|
|
|
@ -45,7 +45,7 @@ def get_notifications(url, i):
|
|
|
|
|
|
|
|
|
|
# Функция, создающая пост
|
|
|
|
|
# 2do: посты с картинками, ...
|
|
|
|
|
def create_post(content, url, i, visibility="public", channel=""):
|
|
|
|
|
def create_post(content, url, i, visibility="public", channel="", fileIds=[]):
|
|
|
|
|
print("Post to", url, ":", content)
|
|
|
|
|
# Аналогично, адрес нужной функции API
|
|
|
|
|
req_url = url + "/api/notes/create"
|
|
|
|
@ -56,6 +56,7 @@ def create_post(content, url, i, visibility="public", channel=""):
|
|
|
|
|
"noExtractEmojis": True,
|
|
|
|
|
"visibility": visibility,
|
|
|
|
|
"text": content,
|
|
|
|
|
"fileIds": fileIds,
|
|
|
|
|
# Если поставлен канал, то пост только локальный для инстанса
|
|
|
|
|
"localOnly": channel != "",
|
|
|
|
|
"i": i
|
|
|
|
@ -68,9 +69,36 @@ def create_post(content, url, i, visibility="public", channel=""):
|
|
|
|
|
if r.status_code == 200:
|
|
|
|
|
return 0
|
|
|
|
|
else:
|
|
|
|
|
print("Failed to post:", result.json()['error']['message'])
|
|
|
|
|
print("Failed to post:", r.text)
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
# Пока что можешь не пытаться разобраться, я сам отчасти хз, как это работает, лол
|
|
|
|
|
def file_upload(file, url, i, isSensitive=False):
|
|
|
|
|
print("Uploading file to", url)
|
|
|
|
|
req_url = url + "/api/drive/files/create"
|
|
|
|
|
with open(file, "rb") as f:
|
|
|
|
|
fileo = f.read()
|
|
|
|
|
body = {
|
|
|
|
|
"isSensitive": False,
|
|
|
|
|
"force": True,
|
|
|
|
|
"i":i
|
|
|
|
|
}
|
|
|
|
|
body = json.dumps(body)
|
|
|
|
|
|
|
|
|
|
payload = {'json_payload': body, 'i': i }
|
|
|
|
|
|
|
|
|
|
files = {"file": (file, fileo)}
|
|
|
|
|
r = requests.post(req_url, data=payload, files=files)
|
|
|
|
|
if r.status_code == 200:
|
|
|
|
|
return r.json()
|
|
|
|
|
else:
|
|
|
|
|
print("Upload failed with code", r.status_code)
|
|
|
|
|
print(r.text)
|
|
|
|
|
|
|
|
|
|
def get_file_list(url, i):
|
|
|
|
|
req_url = url + "/api/drive/files"
|
|
|
|
|
r = requests.post(req_url, json={"i":i})
|
|
|
|
|
print(r.json())
|
|
|
|
|
### Сюда надо захуярить еще 100500 функций###
|
|
|
|
|
|
|
|
|
|
# Собсна, содержательная часть программы начинается тут
|
|
|
|
@ -78,5 +106,10 @@ def create_post(content, url, i, visibility="public", channel=""):
|
|
|
|
|
# Читаем конфиг, получаем словарь
|
|
|
|
|
config = json_read('config.json')
|
|
|
|
|
|
|
|
|
|
notif_list = get_notifications(config['url'], config['token'])
|
|
|
|
|
#notif_list = get_notifications(config['url'], config['token'])
|
|
|
|
|
#print(notif_list)
|
|
|
|
|
#file_upload('test.jpg', config['url'], config['token'])
|
|
|
|
|
im_info = file_upload('test.jpg', config['url'], config['token'])
|
|
|
|
|
|
|
|
|
|
create_post("Nya~", config['url'], config['token'], fileIds=[im_info['id']])
|
|
|
|
|
#print(notif_list)
|
|
|
|
|