From ee13fc3dada6add959844b2de89fb704674508dd Mon Sep 17 00:00:00 2001 From: EamonnMR Date: Fri, 30 Dec 2022 01:37:24 -0500 Subject: [PATCH] Just getting all of the libraries happy --- README.md | 18 ++++++++++++++++++ requirements.txt | 3 +++ server.py | 22 ++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 README.md create mode 100644 requirements.txt create mode 100644 server.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..fcb811f --- /dev/null +++ b/README.md @@ -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. + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1502b89 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pituophis +requests + diff --git a/server.py b/server.py new file mode 100644 index 0000000..49a4f62 --- /dev/null +++ b/server.py @@ -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)