kopia lustrzana https://github.com/sq9atk/sr0wx
Cleanups for Py3 compatibility
rodzic
cd82f95db4
commit
360a5eac5b
|
@ -19,6 +19,7 @@
|
||||||
import base64
|
import base64
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
import socket
|
||||||
|
|
||||||
import urllib.request, urllib.error, urllib.parse
|
import urllib.request, urllib.error, urllib.parse
|
||||||
|
|
||||||
|
@ -73,9 +74,9 @@ Parameters:
|
||||||
}
|
}
|
||||||
|
|
||||||
dump = json.dumps(station_info, separators=(',', ':'))
|
dump = json.dumps(station_info, separators=(',', ':'))
|
||||||
b64data = base64.urlsafe_b64encode(dump)
|
b64data = base64.urlsafe_b64encode(dump.encode('utf-8'))
|
||||||
|
|
||||||
url = self.__service_url + b64data
|
url = self.__service_url + b64data.decode('ascii')
|
||||||
|
|
||||||
self.__logger.info("::: Odpytuję adres: " + url)
|
self.__logger.info("::: Odpytuję adres: " + url)
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ Parameters:
|
||||||
webFile = urllib.request.urlopen(request, None, 5)
|
webFile = urllib.request.urlopen(request, None, 5)
|
||||||
response = webFile.read()
|
response = webFile.read()
|
||||||
|
|
||||||
if response == 'OK':
|
if response == b'OK':
|
||||||
self.__logger.info("::: Dane wysłano, status OK\n")
|
self.__logger.info("::: Dane wysłano, status OK\n")
|
||||||
else:
|
else:
|
||||||
log = "Non-OK response from %s, (%s)"
|
log = "Non-OK response from %s, (%s)"
|
||||||
|
|
|
@ -51,7 +51,7 @@ class AirPollutionSq9atk(SR0WXModule):
|
||||||
def getSensorValue(self, sensorId):
|
def getSensorValue(self, sensorId):
|
||||||
url = self.__service_url + self.__sensor_url + str(sensorId)
|
url = self.__service_url + self.__sensor_url + str(sensorId)
|
||||||
data = self.getJson(url)
|
data = self.getJson(url)
|
||||||
if data['values'][0]['value'] > 0: # czasem tu schodzi null
|
if data['values'][0]['value']: # czasem tu schodzi null
|
||||||
value = data['values'][0]['value']
|
value = data['values'][0]['value']
|
||||||
else:
|
else:
|
||||||
value = data['values'][1]['value']
|
value = data['values'][1]['value']
|
||||||
|
|
|
@ -29,11 +29,10 @@ class CalendarSq9atk(SR0WXModule):
|
||||||
print(e)
|
print(e)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
print("Timed out!")
|
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")
|
||||||
r = re.compile(r'<h1>(.*)(\d\d:\d\d)(.*)(\d\d:\d\d)</h1>')
|
r = re.compile(rb'<h1>(.*)(\d\d:\d\d)(.*)(\d\d:\d\d)</h1>')
|
||||||
url = self.__service_url+str(self.__city_id)
|
url = self.__service_url+str(self.__city_id)
|
||||||
html = self.downloadFile(url)
|
html = self.downloadFile(url)
|
||||||
matches = r.findall(html)
|
matches = r.findall(html)
|
||||||
|
@ -43,7 +42,7 @@ class CalendarSq9atk(SR0WXModule):
|
||||||
}
|
}
|
||||||
|
|
||||||
def hourToNumbers(self, time="00:00"):
|
def hourToNumbers(self, time="00:00"):
|
||||||
datetime_object = datetime.strptime(time, '%H:%M')
|
datetime_object = datetime.strptime(time.decode('ascii'), '%H:%M')
|
||||||
time_words = self.__language.read_datetime(datetime_object, '%H %M')
|
time_words = self.__language.read_datetime(datetime_object, '%H %M')
|
||||||
return time_words
|
return time_words
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#!/usr/bin/python -tt
|
#!/usr/bin/python -tt
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import logging, re, subprocess
|
import logging, re
|
||||||
import urllib.request, urllib.error, urllib.parse
|
import urllib.request, urllib.error, urllib.parse
|
||||||
import time
|
import time
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
from sr0wx_module import SR0WXModule
|
from sr0wx_module import SR0WXModule
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ class GeoMagneticSq9atk(SR0WXModule):
|
||||||
html = self.downloadDataFromUrl(self.__service_url)
|
html = self.downloadDataFromUrl(self.__service_url)
|
||||||
|
|
||||||
#r = re.compile(r'<div class="widget__value w_gm__value(.*?)">(\d)</div>')
|
#r = re.compile(r'<div class="widget__value w_gm__value(.*?)">(\d)</div>')
|
||||||
r = re.compile(r'<div class="value item-(\d)(.*?)"><svg>(.*?)</svg>(\d)</div>')
|
r = re.compile(rb'<div class="value item-(\d)(.*?)"><svg>(.*?)</svg>(\d)</div>')
|
||||||
|
|
||||||
return r.findall(html)
|
return r.findall(html)
|
||||||
|
|
||||||
|
@ -67,7 +66,7 @@ class GeoMagneticSq9atk(SR0WXModule):
|
||||||
if dayNum > 1 or hour > current_hour-1: # omijamy godziny z przeszłości
|
if dayNum > 1 or hour > current_hour-1: # omijamy godziny z przeszłości
|
||||||
if dayNum < 4 and i < 24:
|
if dayNum < 4 and i < 24:
|
||||||
value = data[i+1][3]
|
value = data[i+1][3]
|
||||||
output[dayNum][hour] = value
|
output[dayNum][hour] = int(value)
|
||||||
|
|
||||||
hour += 3
|
hour += 3
|
||||||
if hour > 21:
|
if hour > 21:
|
||||||
|
@ -95,13 +94,12 @@ class GeoMagneticSq9atk(SR0WXModule):
|
||||||
values = self.getDataParsedHtmlData()
|
values = self.getDataParsedHtmlData()
|
||||||
daysValues = self.groupValuesByDays(values)
|
daysValues = self.groupValuesByDays(values)
|
||||||
|
|
||||||
message = ' _ sytuacja_geomagnetyczna_w_regionie ';
|
message = ' _ sytuacja_geomagnetyczna_w_regionie '
|
||||||
|
|
||||||
self.__logger.info("::: Przetwarzam dane...\n")
|
self.__logger.info("::: Przetwarzam dane...\n")
|
||||||
for d, day in daysValues.items():
|
for d, day in daysValues.items():
|
||||||
|
|
||||||
if len(day) > 0:
|
if len(day) > 0:
|
||||||
a=1
|
|
||||||
message += " _ "+self.__days[d-1] + " "
|
message += " _ "+self.__days[d-1] + " "
|
||||||
condition = self.getStrongestConditionOfDay(day)
|
condition = self.getStrongestConditionOfDay(day)
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import urllib.request, urllib.error, urllib.parse
|
import urllib.request, urllib.error, urllib.parse
|
||||||
import re
|
|
||||||
import logging
|
import logging
|
||||||
import pytz
|
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from sr0wx_module import SR0WXModule
|
from sr0wx_module import SR0WXModule
|
||||||
|
|
||||||
class RadioactiveSq9atk(SR0WXModule):
|
class RadioactiveSq9atk(SR0WXModule):
|
||||||
|
@ -62,9 +59,10 @@ class RadioactiveSq9atk(SR0WXModule):
|
||||||
return {"current":current, "average": average}
|
return {"current":current, "average": average}
|
||||||
|
|
||||||
def getSensorData(self, html):
|
def getSensorData(self, html):
|
||||||
dataArr = html.split("L.marker([")
|
dataArr = html.split(b"L.marker([")
|
||||||
ret = {}
|
ret = {}
|
||||||
for row in dataArr:
|
for row in dataArr:
|
||||||
|
row = row.decode('utf-8')
|
||||||
if self.isSensorRow(row):
|
if self.isSensorRow(row):
|
||||||
if self.isSensorMatchedById(self.__sensor_id, row):
|
if self.isSensorMatchedById(self.__sensor_id, row):
|
||||||
ret = self.extractSensorData(row)
|
ret = self.extractSensorData(row)
|
||||||
|
|
|
@ -45,7 +45,7 @@ class VhfTropoSq9atk(SR0WXModule):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def findMapUrlInHtml(self, html, target_id):
|
def findMapUrlInHtml(self, html, target_id):
|
||||||
pattern = r'<img\s+(?:[^>]*\s+)?id="' + re.escape(target_id) + r'"(?:[^>]*)\s+src="([^"]+)"'
|
pattern = rb'<img\s+(?:[^>]*\s+)?id="' + re.escape(target_id).encode('ascii') + rb'"(?:[^>]*)\s+src="([^"]+)"'
|
||||||
match = re.search(pattern, html, re.IGNORECASE)
|
match = re.search(pattern, html, re.IGNORECASE)
|
||||||
if match:
|
if match:
|
||||||
mapUrl = match.group(1)
|
mapUrl = match.group(1)
|
||||||
|
@ -55,7 +55,7 @@ class VhfTropoSq9atk(SR0WXModule):
|
||||||
|
|
||||||
def downloadMapFile(self, mapUrl, targetFileName):
|
def downloadMapFile(self, mapUrl, targetFileName):
|
||||||
try:
|
try:
|
||||||
self.__logger.info("::: Odpytuję adres: " + mapUrl)
|
self.__logger.info("::: Odpytuję adres: " + mapUrl.decode('utf-8'))
|
||||||
response = requests.get(mapUrl, timeout=30)
|
response = requests.get(mapUrl, timeout=30)
|
||||||
|
|
||||||
with open(targetFileName, "wb") as mapFile:
|
with open(targetFileName, "wb") as mapFile:
|
||||||
|
|
Ładowanie…
Reference in New Issue