dodanie timeoutów do żądań

pull/1/head
Paweł Ostolski 2020-03-22 13:01:49 +01:00
rodzic 2c90c9e33e
commit 143dbfca14
10 zmienionych plików z 83 dodań i 24 usunięć

Wyświetl plik

@ -41,7 +41,7 @@ Parameters:
"""
def __init__(self, callsign, latitude, longitude, hour_quarter,
above_sea_level, above_ground_level, station_range,
additional_info="", service_url="http://test.ostol.pl"):
additional_info="", service_url=""):
self.__callsign = callsign
self.__latitude = latitude
self.__longitude = longitude
@ -74,6 +74,7 @@ Parameters:
dump = json.dumps(station_info, separators=(',', ':'))
b64data = base64.urlsafe_b64encode(dump)
request = self.__service_url + b64data
self.__logger.info("::: Odpytuję adres: " + request)
response = urllib.urlopen(request).read()
if response == 'OK':

Wyświetl plik

@ -4,7 +4,9 @@
import urllib2
import logging
import json
import socket
from pprint import pprint
# LISTA STACJI Z NUMERAMI
# http://api.gios.gov.pl/pjp-api/rest/station/findAll
@ -26,9 +28,17 @@ class AirPollutionSq9atk(SR0WXModule):
self.__index_url = "aqindex/getIndex/"
def getJson(self, url):
data = urllib2.urlopen(url)
jsonArr = json.load(data)
return jsonArr
self.__logger.info("::: Odpytuję adres: " + url)
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):
url = self.__service_url + self.__stations_url
@ -103,7 +113,7 @@ class AirPollutionSq9atk(SR0WXModule):
valuesMessage = self.prepareMessage(sensorsData)
message += valuesMessage
print "\n"
return {
"message": message,
# "source": "powietrze_malopolska_pl",

Wyświetl plik

@ -5,6 +5,7 @@ import urllib2
import re
import logging
import pytz
import socket
from datetime import datetime
from sr0wx_module import SR0WXModule
@ -20,8 +21,15 @@ class CalendarSq9atk(SR0WXModule):
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 getSunsetSunrise(self):
self.__logger.info("::: Pobieram dane o wschodzie i zachodzie słońca")

Wyświetl plik

@ -148,12 +148,12 @@ imgwpodestsq9atk = ImgwPodestSq9atk(
## MAPA WSZYSTKICH WODOWSKAZÓW W POLSCE Z NUMERAMI
## http://wx.ostol.pl/wodowskazy/
'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.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.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.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.149200110', # Nazwa: Trybsz, rzeka: Białka

Wyświetl plik

@ -35,6 +35,7 @@ class GeoMagneticSq9atk(SR0WXModule):
}
def downloadDataFromUrl(self, url):
self.__logger.info("::: Odpytuję adres: " + url)
opener = urllib2.build_opener()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:10.0.1) Gecko/20100101 Firefox/10.0.1',

Wyświetl plik

@ -137,7 +137,7 @@ class ImgwPodestSq9atk(SR0WXModule):
a=1
#s.__logger.info("Przetwarzam wodowskaz: " + wodowskaz + " - " + rzeka + ' - ' + w['nazwa_org'])
except:
s.__logger.info("::: Brak danych!!! "+ wodowskaz+" - " + rzeka + ' - ' + w['nazwa_org'])
s.__logger.info("::: Brak danych!!! "+ wodowskaz )
pass
message = "";

Wyświetl plik

@ -21,8 +21,17 @@ class MeteoSq9atk(SR0WXModule):
self.__logger = logging.getLogger(__name__)
def downloadFile(self, url):
webFile = urllib2.urlopen(url)
return webFile.read()
self.__logger.info("::: Odpytuję adres: " + url)
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):
time = ":".join([str(datetime.now().hour), str(datetime.now().minute)])

Wyświetl plik

@ -20,6 +20,7 @@ import urllib2
import re
import logging
import json
import socket
from sr0wx_module import SR0WXModule
@ -51,14 +52,28 @@ class MeteoalarmSq9atk(SR0WXModule):
}
def getDataFromUrl(self, url):
dane = urllib2.urlopen(url)
self.__logger.info("Przetwarzam...\n")
zagrozenia = json.load(dane)
return zagrozenia
self.__logger.info("::: Odpytuję adres: " + url)
dane = ''
try:
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):
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):
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 += " _ "
print "\n"
return {
"message": message,
"source": "meteoalarm_eu",

Wyświetl plik

@ -5,6 +5,7 @@ import urllib2
import logging
from datetime import datetime
import json as JSON
import socket
from sr0wx_module import SR0WXModule
@ -84,8 +85,14 @@ class OpenWeatherSq9atk(SR0WXModule):
}
def downloadFile(self, url):
webFile = urllib2.urlopen(url)
return webFile.read()
try:
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):
time = ":".join([str(datetime.now().hour), str(datetime.now().minute)])

Wyświetl plik

@ -5,6 +5,7 @@ import urllib2
import re
import logging
import pytz
import socket
from datetime import datetime
from sr0wx_module import SR0WXModule
@ -19,8 +20,15 @@ class RadioactiveSq9atk(SR0WXModule):
self.__logger = logging.getLogger(__name__)
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 isSensorMatchedById(self, sensorId, string):
pos = string.find(","+str(sensorId)+", ")