Global rewrite, shit cleaning
parent
27c2296db3
commit
298ea853b7
@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import logging as log
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import msk
|
||||||
|
|
||||||
|
def json_read(file):
|
||||||
|
print("Reading config file: {}".format(file))
|
||||||
|
with open(file) as f:
|
||||||
|
config = json.load(f)
|
||||||
|
return config
|
||||||
|
|
||||||
|
config = json_read('config.json')
|
||||||
|
|
||||||
|
if config['verbosity'].upper() == 'DEBUG':
|
||||||
|
log.basicConfig(format="%(levelname)s: %(message)s", level=log.DEBUG)
|
||||||
|
log.info("Verbose output")
|
||||||
|
|
||||||
|
msk = msk.Misskey(i=config['token'], url=config['url'])
|
||||||
|
|
||||||
|
|
||||||
|
fid = msk.drive_files_create("yaoshi-jun-Toosaka-Rin-Fate-(series)-Anime-3306019.jpeg", isSensitive=True)['id']
|
||||||
|
msk.notes_create(text="Wannya see my picture?", cw="Nya?", fileIds=[fid])
|
||||||
|
|
@ -0,0 +1,72 @@
|
|||||||
|
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()
|
Loading…
Reference in New Issue