Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pyebox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,13 @@ def main():
loop.run_until_complete(task)
except PyEboxError as exp:
print(exp)
client.close_session()
return
if not client.get_data():
client.close_session()
return
if args.json:
print(json.dumps(client.get_data()))
else:
_format_output(args.username, client.get_data())
client.close_session()


if __name__ == '__main__':
Expand Down
11 changes: 6 additions & 5 deletions pyebox/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Pyebox
"""
import asyncio
import json
Comment on lines -4 to -5

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opportunistic removal of unused packages

import logging
import re
import async_timeout
Expand Down Expand Up @@ -38,7 +36,8 @@ class PyEboxError(Exception):

class EboxClient(object):

def __init__(self, username, password, timeout=REQUESTS_TIMEOUT, session=None):
def __init__(self, username, password, timeout=REQUESTS_TIMEOUT,
session=None):
Comment on lines +39 to +40

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opportunistic PEP-8 line-wrap

"""Initialize the client object."""
self.username = username
self.password = password
Expand Down Expand Up @@ -184,14 +183,16 @@ async def fetch_data(self):
# Merge data
self._data.update(home_data)
self._data.update(usage_data)
# Close http session
await self.close_session()

def get_data(self):
"""Return collected data"""
return self._data

def close_session(self):
async def close_session(self):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change

"""Close current session."""
if not self._session.closed:
if self._session._connector_owner:
self._session._connector.close()
await self._session._connector.close()
self._session._connector = None