Skip to content

Update adafruit_pyportal.py #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2019
Merged
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
6 changes: 4 additions & 2 deletions adafruit_pyportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class PyPortal:
"""Class representing the Adafruit PyPortal.

:param url: The URL of your data source. Defaults to ``None``.
:param headers: The headers for authentication, typically used by Azure API's.
:param json_path: The list of json traversal to get data out of. Can be list of lists for
multiple data points. Defaults to ``None`` to not use json.
:param regexp_path: The list of regexp strings to get data out (use a single regexp group). Can
Expand Down Expand Up @@ -144,7 +145,7 @@ class PyPortal:

"""
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
def __init__(self, *, url=None, json_path=None, regexp_path=None,
def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
default_bg=0x000000, status_neopixel=None,
text_font=None, text_position=None, text_color=0x808080,
text_wrap=False, text_maxlen=0, text_transform=None,
Expand All @@ -162,6 +163,7 @@ def __init__(self, *, url=None, json_path=None, regexp_path=None,
self.set_backlight(1.0) # turn on backlight

self._url = url
self._headers = headers
if json_path:
if isinstance(json_path[0], (list, tuple)):
self._json_path = json_path
Expand Down Expand Up @@ -666,7 +668,7 @@ def fetch(self):
print("Retrieving data...", end='')
self.neo_status((100, 100, 0)) # yellow = fetching data
gc.collect()
r = requests.get(self._url)
r = requests.get(self._url, headers=self._headers)
gc.collect()
self.neo_status((0, 0, 100)) # green = got data
print("Reply is OK!")
Expand Down