From 5a82d55d76ec8a2b82d0bf08f02c68777546dc40 Mon Sep 17 00:00:00 2001 From: heehee Date: Sat, 30 Mar 2024 01:50:33 +0000 Subject: [PATCH] Add main.py --- main.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..7c65957 --- /dev/null +++ b/main.py @@ -0,0 +1,51 @@ +from mastodon import Mastodon +import os +#from thingtons import keep_alive +from flask import Flask, request +import requests + +app = Flask(__name__) +mastodon = Mastodon(api_base_url = os.getenv('INSTURL'), access_token = os.getenv('TOKEN')) + +@app.route('/') +def home(): + return "

" + "Website proudly hosted on cyclic.sh!" + "

" + #end + @app.route('/post') + def post(): + type = request.args.get('type') + auth = request.args.get('pass') + quote = [] + data = [] + randomquote = [] + dogurl = [] + imagetoget = [] + image = [] + thekey = os.getenv('PASS') + id = [] + data2 = [] + if auth is None: + return "one parameter missing: auth", 403 + if auth != thekey: + return "auth failed, womp womp", 403 + else: + if type == 'text': + randomquote = requests.get("https://api.quotable.io/quotes/random") + data = randomquote.json() + quote = f"A quote to start your day:\n\"{data[0]['content']}\"\n-{data[0]['author']}\n#quotes #quote" + mastodon.toot(quote) + return 'posted text' + elif type == 'img': + dogurl = requests.get("https://dog.ceo/api/breeds/image/random") + data2 = dogurl.json() + imagetoget = requests.get(data2["message"]) + image = imagetoget.content + print(data2) + id = mastodon.media_post(image, 'image/png').id + mastodon.status_post("new dog picture for you!\nprovided by dog.ceo (thanks!)\n#dogs", media_ids=id) + return 'posted img' + elif type is None: + return "yooo" + #end.. or is it? + if __name__ == '__main__': + app.run(host='0.0.0.0', port=3000) #use waitress-serve or uvicorn for production \ No newline at end of file