import requests import logging as log class Misskey: ''' Class for interaction with Misskey instance Currently, this class ignores most of the Misskey specific shit like channels =3 ''' def __init__(self, url: str, i: str): self.url = url self.i = i def notes_create(self, text=None, visibility = "public", cw = None, fileIds = list(), replyId = None, renoteId = None): req_url = self.url + "/api/notes/create" if renoteId: body = { "renoteId": renoteId, } else: body = { "text": text, "visibility": visibility, } for item in [(cw, "cw"), (fileIds,"fileIds"), (replyId,"replyId")]: if item[0]: body[item[1]] = item[0] body['i'] = self.i log.info("Trying to post note to {}".format(self.url)) r = requests.post(req_url, json=body) print(body) if r.status_code == 200: log.info("Successfully posted") else: log.error("Posting failed with {} error!".format(r.status_code)) return r.json() def following_create(self, userId: str): req_url = self.url + "/api/following/create" r = requests.post(req_url, json={"i":self.i, "userId": userId}) if r.status_code == 200: res = r.json() log.info("Successfully followed user {}@{}[{}]".format(res['username'],res['host'] ,userId)) else: log.error("Failed to follow user [{}] with {} error!".format(userId, r.status_code)) return r.json() def drive_files_create(self, file, isSensitive=False): req_url = self.url + "/api/drive/files/create" with open(file, "rb") as f: files = {"file": (file, f)} body = { "isSensitive": isSensitive, "i":self.i } payload = {'json_payload': body, 'i': self.i } r = requests.post(req_url, data=payload, files=files) if r.status_code == 200: res = r.json() log.info("Successfully uploaded file {}[{}]".format(res['name'], res['id'])) else: log.error("Failed to upload file {} with {} error!".format(file, r.status_code)) return r.json()