[modules/spaceapi] convert from urllib2 to requests

better python2 support

Signed-off-by: Tobias Manske <tobias.manske@mailbox.org>
This commit is contained in:
Tobias Manske 2018-10-05 17:54:43 +02:00
parent 969d2f35cd
commit 095b27436e
No known key found for this signature in database
GPG key ID: 978D99F12D4E041F

View file

@ -3,7 +3,7 @@
"""Displays the state of a spaceapi endpoint
Requires the following libraries:
* urllib
* requests
* json
* time
@ -18,7 +18,7 @@ import bumblebee.input
import bumblebee.output
import bumblebee.engine
import urllib.request
import requests
import json
import time
@ -61,8 +61,9 @@ class Module(bumblebee.engine.Module):
if self._lastQuery + self._sleeptime < int(unixtime):
self._lastQuery = int(unixtime)
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._name = self.parameter("name", default=data["space"])
self._error = False