You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB
Python

#!/usr/bin/python3
import logging as log
import requests
import json
import msk
import websockets
import asyncio, aiohttp
def json_read(file):
print("Reading config file: {}".format(file))
with open(file) as f:
config = json.load(f)
return config
# Temp
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':
log.basicConfig(format="%(levelname)s: %(message)s", level=log.DEBUG)
log.info("Verbose output")
msk = msk.Misskey(i=config['token'], url=config['url'])
async def main():
log.info("Connecting to {}".format(msk.url))
async with websockets.connect(msk.ws_url) as ws:
log.info('Sucessfully connected to {}'.format(msk.url))
log.info('Attemping to watch timeline')
p = {
'type': 'connect',
'body': {
'channel': 'main'
}
}
await ws.send(json.dumps(p))
log.info('Listening to timeline')
while True:
data = await ws.recv()
j = json.loads(data)
if j['type'] == 'channel':
if j['body']['type'] == 'followed':
print("Follow!")
msk.following_create(j['body']['body']['id'])
if j['body']['type'] == 'mention':
if not j['body']['body']['replyId']:
msk.notes_create(renoteId=j['body']['body']['id'])
print(j)
while True:
try:
loop = asyncio.new_event_loop()
#asyncio.set_event_loop(loop)
loop.run_until_complete(main())
except KeyboardInterrupt:
break