#!/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 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']) #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]) 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