Основной функционал готов

niho
nihonium 2 years ago
parent dc517c4555
commit 27c2296db3

@ -5,6 +5,7 @@ import json
import time
import argparse
import logging as log
import pprint
p = argparse.ArgumentParser()
p.add_argument('--verbose', '-v', action='count', default=0)
@ -24,15 +25,17 @@ else:
# Возвращает словарь
def json_read(file):
# Создается локальное окружение (или как эта хуйня зовется), где присутствует дескриптор для нашего файла
#log.info("Reading config file:", file)
log.info("Reading config file: %s", file)
with open(file) as f:
config = json.load(f)
return config
config = json_read('config.json')
# Функция для получения уведомлений пользователя из Misskey
# Возвращает список словарей
def get_notifications(url, i, includeTypes=["follow", "mention", "reply", "renote", "quote", "reaction", "pollVote", "receiveFollowRequest", "followRequestAccepted", "groupInvited","app"], markAsRead=True):
log.info("Getting notifications from", url)
def get_notifications(url, i, includeTypes=["follow", "mention", "reply", "renote", "quote", "reaction", "pollVote", "receiveFollowRequest", "followRequestAccepted", "groupInvited","app"], markAsRead=True, unreadOnly=True, following=True, limit=5):
log.info("Getting notifications from %s", url)
# Формируем URL для доступа к конкретной функции API
req_url = url + "/api/i/notifications"
body = {
@ -43,21 +46,23 @@ def get_notifications(url, i, includeTypes=["follow", "mention", "reply", "renot
"limit": 3,
"unreadOnly": False,
"markAsRead": markAsRead,
"unreadOnly": unreadOnly,
"following": following,
"limit": limit,
}
# Отправляем запрос, в тело запроса суем словарь-JSON, которые объявили выше
r = requests.post(req_url, json=body)
# Если все прошло збс, код HTTP 200, то отдаем получанный список уведомлений
if r.status_code == 200:
# Можешь раскомментить, глянуть, что это за черт
#print(r.json())
return r.json()
# Иначе, если не збс, то ругаемся
else:
print("Fuck")
log.error("Fuck you, leatherman")
# Функция, создающая пост
# 2do: посты с картинками, ...
def create_post(url, i, content="", visibility="public", channel="", fileIds=[], renote=False, renoteId=None):
print("Post to", url, ":", content)
def create_note(url=config['url'], i=config['token'], content="", visibility="public", channel="", fileIds=[], renote=False, renoteId=None):
log.info("Creating note to %s", url)
# Аналогично, адрес нужной функции API
req_url = url + "/api/notes/create"
if renote:
@ -76,7 +81,7 @@ def create_post(url, i, content="", visibility="public", channel="", fileIds=[],
#"fileIds": fileIds,
# Если поставлен канал, то пост только локальный для инстанса
"localOnly": channel != "",
"i": i
"i": i,
}
if channel != "":
body["channelId"] = channel
@ -86,8 +91,9 @@ def create_post(url, i, content="", visibility="public", channel="", fileIds=[],
if r.status_code == 200:
return 0
else:
print("Failed to post:", r.text)
log.error("Failed to post: %s", r.text)
return 1
# Пока что можешь не пытаться разобраться, я сам отчасти хз, как это работает, лол
def file_upload(file, url, i, isSensitive=False):
print("Uploading file to", url)
@ -117,11 +123,38 @@ def get_file_list(url, i):
print(r.json())
### Сюда надо захуярить еще 100500 функций###
def follow_user(userId, url=config['url'], i=config['token']):
req_url = url + "/api/following/create"
r = requests.post(req_url, json={"i":i, "userId": userId})
#print(r.json())
if r.status_code == 200:
return r.json()
else:
print("Upload failed with code", r.status_code)
print(r.text)
# Собсна, содержательная часть программы начинается тут
# Читаем конфиг, получаем словарь
config = json_read('config.json')
create_post(config['url'], config['token'], renote=True, renoteId="8vxi115z0g")
#create_note(config['url'], config['token'], renote=True, renoteId="8vxo3hpsdm")
while True:
notif_list = get_notifications(config['url'], config['token'], includeTypes=["mention"], markAsRead=False, unreadOnly=True, limit=2, following=True)
follow_notif_list = get_notifications(config['url'], config['token'], includeTypes=["follow"], markAsRead=False, unreadOnly=True, limit=2, following=False)
#pprint.pprint(notif_list)
pprint.pprint(follow_notif_list)
notes_to_repost=list()
users_to_follow=list()
for i in range(len(notif_list)):
#pprint.pprint(notif_list[i]['note']['id'])
notes_to_repost.append(notif_list[i]['note']['id'])
for i in range(len(follow_notif_list)):
#pprint.pprint(notif_list[i]['note']['id'])
users_to_follow.append(follow_notif_list[i]['user']['id'])
print(users_to_follow)
#for i in range(len(notes_to_repost)):
# create_note(renote=True, renoteId=notes_to_repost.pop())
for i in range(len(users_to_follow)):
follow_user(users_to_follow.pop())
time.sleep(2)

Loading…
Cancel
Save