websockets

niho
nihonium 3 years ago
parent 298ea853b7
commit 8730dcd7f1

@ -3,6 +3,8 @@ import logging as log
import requests import requests
import json import json
import msk import msk
import websockets
import asyncio, aiohttp
def json_read(file): def json_read(file):
print("Reading config file: {}".format(file)) print("Reading config file: {}".format(file))
@ -12,6 +14,12 @@ def json_read(file):
config = json_read('config.json') config = json_read('config.json')
#try:
# config = json_read('config.json')
#except FileNotFoundError:
# print("Config file not found. Maybe we should launch setup.py?")
if config['verbosity'].upper() == 'DEBUG': if config['verbosity'].upper() == 'DEBUG':
log.basicConfig(format="%(levelname)s: %(message)s", level=log.DEBUG) log.basicConfig(format="%(levelname)s: %(message)s", level=log.DEBUG)
log.info("Verbose output") log.info("Verbose output")
@ -19,6 +27,37 @@ if config['verbosity'].upper() == 'DEBUG':
msk = msk.Misskey(i=config['token'], url=config['url']) 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'] #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]) #msk.notes_create(text="Wannya see my picture?", cw="Nya?", fileIds=[fid])
async def main():
async with websockets.connect(msk.ws_url) as ws:
print('Connecting')
p = {
'type': 'connect',
'body': {
'channel': 'homeTimeline',
'id': 'Nya1'
}
}
await ws.send(json.dumps(p))
p = {
'type': 'connect',
'body': {
'channel': 'main',
'id': 'Nya2'
}
}
await ws.send(json.dumps(p))
print('Listening')
while True:
data = await ws.recv()
j = json.loads(data)
print(j)
while True:
try:
asyncio.get_event_loop().run_until_complete(main())
except KeyboardInterrupt:
break

@ -1,7 +1,7 @@
{ {
"nyan.nekoea.red": {
"name": "nyan.nekoea.red", "name": "nyan.nekoea.red",
"url" : "https://nyan.nekoea.red", "url" : "nyan.nekoea.red",
"token": "nyanyanyanyanyanyanya", "token": "*****",
}, "verbosity": "debug"
} }

@ -8,8 +8,9 @@ class Misskey:
''' '''
def __init__(self, url: str, i: str): def __init__(self, url: str, i: str):
self.url = url self.url = f"https://{url}"
self.i = i self.i = i
self.ws_url=f"wss://{url}/streaming&i={i}"
def notes_create(self, text=None, visibility = "public", cw = None, fileIds = list(), replyId = None, renoteId = None): def notes_create(self, text=None, visibility = "public", cw = None, fileIds = list(), replyId = None, renoteId = None):
req_url = self.url + "/api/notes/create" req_url = self.url + "/api/notes/create"

Loading…
Cancel
Save