Periodic sync example? #376
-
I saw this page, but I cannot find example code. Is the following the best way to do periodic sync (continuously displaying current information)? I am wondering if there this library is providing a better way like internally caching and merging the "maindata", so that I don't have to maintain rid and previous values. rid = 0
us = -1
ds = -1
while True:
maindata = qbt_client.sync_maindata(rid=rid)
rid = maindata["rid"]
ss = maindata["server_state"]
us = ss.get("up_info_speed", us)
ds = ss.get("dl_info_speed", ds)
print(f"Upload: {us}, Download: {ds}")
time.sleep(2) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
oh yeah....the docs don't include the simplest way to use sync data. I should add a better example. Give this a go: import time
from collections.abc import Mapping
def update(d, u):
for k, v in u.items():
d[k] = update(d.get(k, {}), v) if isinstance(v, Mapping) else v
return d
maindata = client.sync_maindata()
while True:
print(f"Upload: {maindata.server_state.up_info_speed}, Download: {maindata.server_state.dl_info_speed}")
maindata = update(maindata, client.sync.maindata.delta())
time.sleep(1)
Although, there isn't anything to keep a full up-to-date |
Beta Was this translation helpful? Give feedback.
oh yeah....the docs don't include the simplest way to use sync data. I should add a better example.
Give this a go:
client.sync.maindata.delta()
can keep track of therid
for you between subsequent calls.Although, there isn't anything to keep a full up-to-date
maindata
....that pr…