Just getting all of the libraries happy
This commit is contained in:
commit
ee13fc3dad
3 changed files with 43 additions and 0 deletions
18
README.md
Normal file
18
README.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# gopher-wp-bridge
|
||||
|
||||
Python gopher server using [https://github.com/dotcomboom/Pituophis/](https://github.com/dotcomboom/Pituophis/) and Wordpress's API to expose your wordpress site to the phlogosphere.
|
||||
|
||||
## How
|
||||
|
||||
Pass your desired wordpress site's URL and port with environment variables like so:
|
||||
|
||||
`URL='http://wordpress.example.com' PORT='7070' python server.py`
|
||||
|
||||
## Why
|
||||
|
||||
Because I'm not just a luddite, I'm an incredibly lazy luddite.
|
||||
|
||||
## Project status
|
||||
|
||||
Experimental. Lacks basic capabilities; right now it's just a menu with your last ten posts.
|
||||
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
pituophis
|
||||
requests
|
||||
|
22
server.py
Normal file
22
server.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from os import getenv
|
||||
from urllib.parse import urljoin
|
||||
from html import unescape
|
||||
|
||||
import pituophis
|
||||
from pituophis import Item
|
||||
from requests import get
|
||||
|
||||
wordpress_url = getenv("URL")
|
||||
|
||||
def handle(request):
|
||||
posts = get(urljoin(wordpress_url, "wp-json/wp/v2/posts")).json()
|
||||
|
||||
menu = [
|
||||
Item(itype=1, path="/" + post['slug'], text=unescape(post['title']['rendered']), host=request.host, port=request.port)
|
||||
for post in posts
|
||||
]
|
||||
print(menu)
|
||||
return menu
|
||||
|
||||
if __name__ == '__main__':
|
||||
pituophis.serve("127.0.0.1", int(getenv("PORT")), handler=handle)
|
Loading…
Add table
Reference in a new issue