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