output results outside function instead of printing
sdrulik opened this issue · 3 comments
Im leveraging pyxows to pull call history and call stats for each of our units but i'd like to ouput the data into a variable that I can manipulate for furthur implementation in my environment. I cant seem to get it to work and im a little stumped on what I am missing. As soon as I try to output in past the def start function using a global variable, I get errors with future references and it only gives me one video unit output instead of 2. What am I missing?
import xows
import asyncio
async def start(ip, name):
async with xows.XoWSClient(ip, username='admin', password='XXX') as client:
z = (name, await client.xCommand(['CallHistory', 'Get'],DetailLevel='Full', Limit=2))
print(z)
await client.wait_until_closed()
async def task():
codecs = [('X.X.X.X', 'Video1'),
('X.X.X.X', 'Video2')]
connections = [start(*codec) for codec in codecs]
await asyncio.wait(connections)
asyncio.run(task())
I tried not modifying your code too much, just simplified and fixed the obvious issues.
import xows
import asyncio
async def start(ip, name):
async with xows.XoWSClient(ip, username='admin', password='XXX') as client:
print(name, await client.xCommand(['CallHistory', 'Get'],DetailLevel='Full', Limit=2))
async def task():
codecs = [start('X.X.X.X', 'Video1'),
start('X.X.X.X', 'Video2')]
for command in codecs:
await command
asyncio.run(task())
How would i pull the results from the def(start) outside of the local scope of the function so I can manipulate it globally? I dont technically want to "print" the data, but store it in a Dict where Video1 will be element 1 in the json format (with all Call history) and video2 will be element 2?
Sorry for the belated reply. At the point where you're printing the results now, you could e.g. add them to a dict, return them to the outer function, or use them directly if you wish. Same as in any Python program.