mirror of
https://github.com/KevinMidboe/delugeClient.git
synced 2025-10-29 12:00:13 +00:00
Added json response to ls command and removed print functions.
This commit is contained in:
@@ -31,6 +31,7 @@ import os
|
||||
import sys
|
||||
import re
|
||||
import signal
|
||||
import json
|
||||
import socket
|
||||
import logging
|
||||
import logging.config
|
||||
@@ -240,7 +241,7 @@ def signal_handler(signal, frame):
|
||||
logger.info('\nGood bye!')
|
||||
sys.exit(0)
|
||||
|
||||
def main(arg):
|
||||
def main(arg=None):
|
||||
"""
|
||||
Main function, parse the input
|
||||
"""
|
||||
@@ -284,7 +285,8 @@ def main(arg):
|
||||
elif arguments['progress']:
|
||||
logger.info('Progress cmd selected.')
|
||||
response = deluge.progress()
|
||||
[ pprint(t.toJSON()) for t in response ]
|
||||
print(response)
|
||||
# [ pprint(t.toJSON()) for t in response ]
|
||||
return response
|
||||
|
||||
elif arguments['get']:
|
||||
@@ -296,8 +298,9 @@ def main(arg):
|
||||
elif arguments['ls']:
|
||||
logger.info('List cmd selected')
|
||||
response = deluge.get_all(_filter=_filter)
|
||||
[ pprint(t.toJSON()) for t in response ]
|
||||
return response
|
||||
response = [t.toJSON() for t in response]
|
||||
# pprint(response)
|
||||
return json.dumps(response)
|
||||
|
||||
elif arguments['toggle']:
|
||||
logger.info('Toggling id: {}'.format(_id))
|
||||
|
||||
@@ -2,6 +2,7 @@ import asyncio
|
||||
import datetime
|
||||
import random
|
||||
import websockets
|
||||
import json
|
||||
|
||||
import deluge_cli
|
||||
|
||||
@@ -22,20 +23,20 @@ async def time(websocket, path):
|
||||
|
||||
|
||||
async def deluge(websocket, path):
|
||||
last_msg = None
|
||||
downloading = deluge_cli.main(['ls', '--downloading'])
|
||||
last_msg = []
|
||||
while True:
|
||||
if downloading != last_msg:
|
||||
await websocket.send(str(downloading))
|
||||
downloading = deluge_cli.main(['progress'])
|
||||
|
||||
if downloading is not last_msg:
|
||||
await websocket.send(json.dumps(downloading))
|
||||
print('sending response')
|
||||
last_msg = downloading
|
||||
|
||||
await asyncio.sleep(1)
|
||||
|
||||
serve_hello = websockets.serve(hello, '0.0.0.0', 8765)
|
||||
# serve_time = websockets.serve(time, '0.0.0.0', 5678)
|
||||
serve_deluge = websockets.serve(deluge, '0.0.0.0', 5678)
|
||||
|
||||
asyncio.get_event_loop().run_until_complete(serve_hello)
|
||||
asyncio.get_event_loop().run_until_complete(serve_deluge)
|
||||
asyncio.get_event_loop().run_forever()
|
||||
asyncio.get_event_loop().run_forever()
|
||||
|
||||
Reference in New Issue
Block a user