Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
add simple usage counter
Browse files Browse the repository at this point in the history
  • Loading branch information
dynasticorpheus committed Oct 2, 2015
1 parent fed1ab5 commit 9e1d2ec
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions gigasetelements/gigasetelements.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
URL_HEALTH = 'https://api.gigaset-elements.de/api/v2/me/health'
URL_DEVICE = 'https://api.gigaset-elements.de/api/v1/me/devices'
URL_CHANNEL = 'https://api.gigaset-elements.de/api/v1/me/notifications/users/channels'
URL_USAGE = 'https://goo.gl/S66QUI'


class bcolors:
Expand Down Expand Up @@ -167,11 +168,15 @@ def is_json(myjson):
return True


def restget(url):
"""REST interaction using GET."""
def restget(url, head=0, seconds=90):
"""REST interaction using GET or HEAD."""
data = ''
try:
r = s.get(url, timeout=90, stream=False)
if head == 1:
header = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'}
r = s.head(url, timeout=seconds, headers=header, allow_redirects=True)
else:
r = s.get(url, timeout=seconds, stream=False)
except requests.exceptions.RequestException as e:
log(str(e.message), 3, 1)
if r.status_code != requests.codes.ok:
Expand Down Expand Up @@ -212,6 +217,7 @@ def connect():
restget(URL_AUTH)
s.headers['Connection'] = 'keep-alive'
log('Authenticated')
restget(URL_USAGE, 1, 3)
basestation_data = restget(URL_BASE)
log('Basestation ' + basestation_data[0]['id'])
camera_data = restget(URL_CAMERA)
Expand Down

0 comments on commit 9e1d2ec

Please sign in to comment.