diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d344ba6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.json diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..a47ce1e --- /dev/null +++ b/config.json.example @@ -0,0 +1,7 @@ +{ + "nyan.nekoea.red": { + "name": "nyan.nekoea.red", + "url" : "https://nyan.nekoea.red", + "token": "nyanyanyanyanyanyanya", + }, +} diff --git a/main.py b/main.py index d5b9731..46e9868 100644 --- a/main.py +++ b/main.py @@ -1,21 +1,55 @@ #!/usr/bin/python3 import requests -import re import json - -def img_upload(): - pass - -def create_post(): - pass +import time def json_read(file): - pass + with open(file) as f: + config = json.load(f) + return config -if __name__ == '__main__': - pass +def get_notifications(url, i): + print("Getting notifications from", url) + req_url = url + "/api/i/notifications" + print(req_url) + body = { + "i": i, + #"includeTypes": [ + # "reply", + # "mention" + # ], + "limit": 3, + "unreadOnly": True, + } + r = requests.post(req_url, json=body) - config = json_read("config.json") + if r.status_code == 200: + print(r.json()) + else: + print("Fuck") + +def create_post(content, url, i, visibility="public", channel=""): + print("Post to", url, ":", content) + req_url = url + "/api/notes/create" + body = { + "noExtractMentions": True, + "noExtractHashtags": True, + "noExtractEmojis": True, + "visibility": visibility, + "text": content, + "localOnly": channel != "", + "i": i + } + if channel != "": + body["channelId"] = channel + r = requests.post(req_url, json=body) + if r.status_code == 200: + return 0 + else: + print("Failed to post:", result.json()['error']['message']) + return 1 +config = json_read('config.json') +get_notifications(config['url'], config['token'])