kopia lustrzana https://github.com/sq9atk/sr0wx
dodanie timeoutów do żądań
rodzic
2c90c9e33e
commit
143dbfca14
|
@ -41,7 +41,7 @@ Parameters:
|
||||||
"""
|
"""
|
||||||
def __init__(self, callsign, latitude, longitude, hour_quarter,
|
def __init__(self, callsign, latitude, longitude, hour_quarter,
|
||||||
above_sea_level, above_ground_level, station_range,
|
above_sea_level, above_ground_level, station_range,
|
||||||
additional_info="", service_url="http://test.ostol.pl"):
|
additional_info="", service_url=""):
|
||||||
self.__callsign = callsign
|
self.__callsign = callsign
|
||||||
self.__latitude = latitude
|
self.__latitude = latitude
|
||||||
self.__longitude = longitude
|
self.__longitude = longitude
|
||||||
|
@ -74,6 +74,7 @@ Parameters:
|
||||||
dump = json.dumps(station_info, separators=(',', ':'))
|
dump = json.dumps(station_info, separators=(',', ':'))
|
||||||
b64data = base64.urlsafe_b64encode(dump)
|
b64data = base64.urlsafe_b64encode(dump)
|
||||||
request = self.__service_url + b64data
|
request = self.__service_url + b64data
|
||||||
|
self.__logger.info("::: Odpytuję adres: " + request)
|
||||||
response = urllib.urlopen(request).read()
|
response = urllib.urlopen(request).read()
|
||||||
|
|
||||||
if response == 'OK':
|
if response == 'OK':
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
import urllib2
|
import urllib2
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
import socket
|
||||||
|
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
# LISTA STACJI Z NUMERAMI
|
# LISTA STACJI Z NUMERAMI
|
||||||
# http://api.gios.gov.pl/pjp-api/rest/station/findAll
|
# http://api.gios.gov.pl/pjp-api/rest/station/findAll
|
||||||
|
@ -26,9 +28,17 @@ class AirPollutionSq9atk(SR0WXModule):
|
||||||
self.__index_url = "aqindex/getIndex/"
|
self.__index_url = "aqindex/getIndex/"
|
||||||
|
|
||||||
def getJson(self, url):
|
def getJson(self, url):
|
||||||
data = urllib2.urlopen(url)
|
self.__logger.info("::: Odpytuję adres: " + url)
|
||||||
jsonArr = json.load(data)
|
|
||||||
return jsonArr
|
try:
|
||||||
|
data = urllib2.urlopen(url, None, 45)
|
||||||
|
return json.load(data)
|
||||||
|
except urllib2.URLError, e:
|
||||||
|
print e
|
||||||
|
except socket.timeout:
|
||||||
|
print "Timed out!"
|
||||||
|
|
||||||
|
return {}
|
||||||
|
|
||||||
def getStationName(self):
|
def getStationName(self):
|
||||||
url = self.__service_url + self.__stations_url
|
url = self.__service_url + self.__stations_url
|
||||||
|
@ -103,7 +113,7 @@ class AirPollutionSq9atk(SR0WXModule):
|
||||||
valuesMessage = self.prepareMessage(sensorsData)
|
valuesMessage = self.prepareMessage(sensorsData)
|
||||||
|
|
||||||
message += valuesMessage
|
message += valuesMessage
|
||||||
|
print "\n"
|
||||||
return {
|
return {
|
||||||
"message": message,
|
"message": message,
|
||||||
# "source": "powietrze_malopolska_pl",
|
# "source": "powietrze_malopolska_pl",
|
||||||
|
|
|
@ -5,6 +5,7 @@ import urllib2
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
import pytz
|
import pytz
|
||||||
|
import socket
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sr0wx_module import SR0WXModule
|
from sr0wx_module import SR0WXModule
|
||||||
|
@ -20,8 +21,15 @@ class CalendarSq9atk(SR0WXModule):
|
||||||
|
|
||||||
|
|
||||||
def downloadFile(self, url):
|
def downloadFile(self, url):
|
||||||
webFile = urllib2.urlopen(url)
|
try:
|
||||||
return webFile.read()
|
self.__logger.info("::: Odpytuję adres: " + url)
|
||||||
|
webFile = urllib2.urlopen(url, None, 30)
|
||||||
|
return webFile.read()
|
||||||
|
except urllib2.URLError, e:
|
||||||
|
print e
|
||||||
|
except socket.timeout:
|
||||||
|
print "Timed out!"
|
||||||
|
return ""
|
||||||
|
|
||||||
def getSunsetSunrise(self):
|
def getSunsetSunrise(self):
|
||||||
self.__logger.info("::: Pobieram dane o wschodzie i zachodzie słońca")
|
self.__logger.info("::: Pobieram dane o wschodzie i zachodzie słońca")
|
||||||
|
|
|
@ -148,12 +148,12 @@ imgwpodestsq9atk = ImgwPodestSq9atk(
|
||||||
## MAPA WSZYSTKICH WODOWSKAZÓW W POLSCE Z NUMERAMI
|
## MAPA WSZYSTKICH WODOWSKAZÓW W POLSCE Z NUMERAMI
|
||||||
## http://wx.ostol.pl/wodowskazy/
|
## http://wx.ostol.pl/wodowskazy/
|
||||||
|
|
||||||
'2.149180210', # Nazwa: Zabrzeg, rzeka: Wisła - zrypany wodowskaz / tylko do testów
|
#'2.149180210', # Nazwa: Zabrzeg, rzeka: Wisła - zrypany wodowskaz / tylko do testów
|
||||||
'2.149200360', # Nazwa: Lipnica Murowana, rzeka: Uszwica - zrypany wodowskaz / tylko do testów
|
#'2.149200360', # Nazwa: Lipnica Murowana, rzeka: Uszwica - zrypany wodowskaz / tylko do testów
|
||||||
'2.149200370', # Nazwa: Okocim, rzeka: Uszwica - zrypany wodowskaz / tylko do testów
|
'2.149200370', # Nazwa: Okocim, rzeka: Uszwica - zrypany wodowskaz / tylko do testów
|
||||||
'2.149190350', # Nazwa: Krzczonów, rzeka: Krzczonówka - zrypany wodowskaz / tylko do testów
|
'2.149190350', # Nazwa: Krzczonów, rzeka: Krzczonówka - zrypany wodowskaz / tylko do testów
|
||||||
'2.150210200', # Nazwa: Grebów, rzeka: Łęg - zrypany wodowskaz / tylko do testów
|
'2.150210200', # Nazwa: Grebów, rzeka: Łęg - zrypany wodowskaz / tylko do testów
|
||||||
'2.149180080', # Nazwa: Drogomyśl, rzeka: Wisła - zrypany wodowskaz / tylko do testów
|
#'2.149180080', # Nazwa: Drogomyśl, rzeka: Wisła - zrypany wodowskaz / tylko do testów
|
||||||
|
|
||||||
'2.149210050', # Nazwa: Krajowice, rzeka: Wisłoka
|
'2.149210050', # Nazwa: Krajowice, rzeka: Wisłoka
|
||||||
'2.149200110', # Nazwa: Trybsz, rzeka: Białka
|
'2.149200110', # Nazwa: Trybsz, rzeka: Białka
|
||||||
|
|
|
@ -35,6 +35,7 @@ class GeoMagneticSq9atk(SR0WXModule):
|
||||||
}
|
}
|
||||||
|
|
||||||
def downloadDataFromUrl(self, url):
|
def downloadDataFromUrl(self, url):
|
||||||
|
self.__logger.info("::: Odpytuję adres: " + url)
|
||||||
opener = urllib2.build_opener()
|
opener = urllib2.build_opener()
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:10.0.1) Gecko/20100101 Firefox/10.0.1',
|
'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:10.0.1) Gecko/20100101 Firefox/10.0.1',
|
||||||
|
|
|
@ -137,7 +137,7 @@ class ImgwPodestSq9atk(SR0WXModule):
|
||||||
a=1
|
a=1
|
||||||
#s.__logger.info("Przetwarzam wodowskaz: " + wodowskaz + " - " + rzeka + ' - ' + w['nazwa_org'])
|
#s.__logger.info("Przetwarzam wodowskaz: " + wodowskaz + " - " + rzeka + ' - ' + w['nazwa_org'])
|
||||||
except:
|
except:
|
||||||
s.__logger.info("::: Brak danych!!! "+ wodowskaz+" - " + rzeka + ' - ' + w['nazwa_org'])
|
s.__logger.info("::: Brak danych!!! "+ wodowskaz )
|
||||||
pass
|
pass
|
||||||
|
|
||||||
message = "";
|
message = "";
|
||||||
|
|
|
@ -21,8 +21,17 @@ class MeteoSq9atk(SR0WXModule):
|
||||||
self.__logger = logging.getLogger(__name__)
|
self.__logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def downloadFile(self, url):
|
def downloadFile(self, url):
|
||||||
webFile = urllib2.urlopen(url)
|
self.__logger.info("::: Odpytuję adres: " + url)
|
||||||
return webFile.read()
|
try:
|
||||||
|
webFile = urllib2.urlopen(url, None, 30)
|
||||||
|
return webFile.read()
|
||||||
|
except URLError, e:
|
||||||
|
print e
|
||||||
|
except socket.timeout:
|
||||||
|
print "Timed out!"
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getHour(self):
|
def getHour(self):
|
||||||
time = ":".join([str(datetime.now().hour), str(datetime.now().minute)])
|
time = ":".join([str(datetime.now().hour), str(datetime.now().minute)])
|
||||||
|
|
|
@ -20,6 +20,7 @@ import urllib2
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
import socket
|
||||||
|
|
||||||
from sr0wx_module import SR0WXModule
|
from sr0wx_module import SR0WXModule
|
||||||
|
|
||||||
|
@ -51,14 +52,28 @@ class MeteoalarmSq9atk(SR0WXModule):
|
||||||
}
|
}
|
||||||
|
|
||||||
def getDataFromUrl(self, url):
|
def getDataFromUrl(self, url):
|
||||||
dane = urllib2.urlopen(url)
|
self.__logger.info("::: Odpytuję adres: " + url)
|
||||||
self.__logger.info("Przetwarzam...\n")
|
dane = ''
|
||||||
zagrozenia = json.load(dane)
|
try:
|
||||||
return zagrozenia
|
dane = urllib2.urlopen(url, None, 30);
|
||||||
|
return json.load(dane)
|
||||||
|
except URLError, e:
|
||||||
|
print e
|
||||||
|
except socket.timeout:
|
||||||
|
print "Timed out!"
|
||||||
|
return {}
|
||||||
|
|
||||||
def downloadFile(self, url):
|
def downloadFile(self, url):
|
||||||
webFile = urllib2.urlopen(url)
|
|
||||||
return webFile.read()
|
try:
|
||||||
|
self.__logger.info("::: Odpytuję adres: " + url)
|
||||||
|
webFile = urllib2.urlopen(url, None, 30)
|
||||||
|
return webFile.read()
|
||||||
|
except urllib2.URLError, e:
|
||||||
|
print e
|
||||||
|
except socket.timeout:
|
||||||
|
print "Timed out!"
|
||||||
|
return ""
|
||||||
|
|
||||||
def getWarnings(self, region, tomorrow=False):
|
def getWarnings(self, region, tomorrow=False):
|
||||||
r = re.compile('pictures/aw(\d[01]?)([0234]).jpg')
|
r = re.compile('pictures/aw(\d[01]?)([0234]).jpg')
|
||||||
|
@ -96,7 +111,7 @@ class MeteoalarmSq9atk(SR0WXModule):
|
||||||
message += " ".join([self.warningsPrefix," ",self.regions[self.__region],"_", "dzis","_", today,"_","jutro","_",tomorrow])
|
message += " ".join([self.warningsPrefix," ",self.regions[self.__region],"_", "dzis","_", today,"_","jutro","_",tomorrow])
|
||||||
|
|
||||||
message += " _ "
|
message += " _ "
|
||||||
|
print "\n"
|
||||||
return {
|
return {
|
||||||
"message": message,
|
"message": message,
|
||||||
"source": "meteoalarm_eu",
|
"source": "meteoalarm_eu",
|
||||||
|
|
|
@ -5,6 +5,7 @@ import urllib2
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json as JSON
|
import json as JSON
|
||||||
|
import socket
|
||||||
|
|
||||||
from sr0wx_module import SR0WXModule
|
from sr0wx_module import SR0WXModule
|
||||||
|
|
||||||
|
@ -84,8 +85,14 @@ class OpenWeatherSq9atk(SR0WXModule):
|
||||||
}
|
}
|
||||||
|
|
||||||
def downloadFile(self, url):
|
def downloadFile(self, url):
|
||||||
webFile = urllib2.urlopen(url)
|
try:
|
||||||
return webFile.read()
|
webFile = urllib2.urlopen(url, None, 30)
|
||||||
|
return webFile.read()
|
||||||
|
except urllib2.URLError, e:
|
||||||
|
print e
|
||||||
|
except socket.timeout:
|
||||||
|
print "Timed out!"
|
||||||
|
return ""
|
||||||
|
|
||||||
def getHour(self):
|
def getHour(self):
|
||||||
time = ":".join([str(datetime.now().hour), str(datetime.now().minute)])
|
time = ":".join([str(datetime.now().hour), str(datetime.now().minute)])
|
||||||
|
|
|
@ -5,6 +5,7 @@ import urllib2
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
import pytz
|
import pytz
|
||||||
|
import socket
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sr0wx_module import SR0WXModule
|
from sr0wx_module import SR0WXModule
|
||||||
|
@ -19,8 +20,15 @@ class RadioactiveSq9atk(SR0WXModule):
|
||||||
self.__logger = logging.getLogger(__name__)
|
self.__logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def downloadFile(self, url):
|
def downloadFile(self, url):
|
||||||
webFile = urllib2.urlopen(url)
|
try:
|
||||||
return webFile.read()
|
self.__logger.info("::: Odpytuję adres: " + url)
|
||||||
|
webFile = urllib2.urlopen(url, None, 30)
|
||||||
|
return webFile.read()
|
||||||
|
except urllib2.URLError, e:
|
||||||
|
print e
|
||||||
|
except socket.timeout:
|
||||||
|
print "Timed out!"
|
||||||
|
return ""
|
||||||
|
|
||||||
def isSensorMatchedById(self, sensorId, string):
|
def isSensorMatchedById(self, sensorId, string):
|
||||||
pos = string.find(","+str(sensorId)+", ")
|
pos = string.find(","+str(sensorId)+", ")
|
||||||
|
|
Ładowanie…
Reference in New Issue