[modules/spaceapi] convert from urllib2 to requests
better python2 support Signed-off-by: Tobias Manske <tobias.manske@mailbox.org>
This commit is contained in:
parent
969d2f35cd
commit
095b27436e
1 changed files with 5 additions and 4 deletions
|
@ -3,7 +3,7 @@
|
||||||
"""Displays the state of a spaceapi endpoint
|
"""Displays the state of a spaceapi endpoint
|
||||||
|
|
||||||
Requires the following libraries:
|
Requires the following libraries:
|
||||||
* urllib
|
* requests
|
||||||
* json
|
* json
|
||||||
* time
|
* time
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import bumblebee.input
|
||||||
import bumblebee.output
|
import bumblebee.output
|
||||||
import bumblebee.engine
|
import bumblebee.engine
|
||||||
|
|
||||||
import urllib.request
|
import requests
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -61,8 +61,9 @@ class Module(bumblebee.engine.Module):
|
||||||
if self._lastQuery + self._sleeptime < int(unixtime):
|
if self._lastQuery + self._sleeptime < int(unixtime):
|
||||||
self._lastQuery = int(unixtime)
|
self._lastQuery = int(unixtime)
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(self._url) as u:
|
|
||||||
data = json.loads(u.read().decode())
|
with requests.get(self._url) as u:
|
||||||
|
data = u.json()
|
||||||
self._state = data["state"]["open"]
|
self._state = data["state"]["open"]
|
||||||
self._name = self.parameter("name", default=data["space"])
|
self._name = self.parameter("name", default=data["space"])
|
||||||
self._error = False
|
self._error = False
|
||||||
|
|
Loading…
Reference in a new issue