kopia lustrzana https://github.com/sq9atk/sr0wx
moduł zanieczyszczeń powietrza Airly
rodzic
4e8bd15f5e
commit
a39498e7df
|
@ -0,0 +1,112 @@
|
|||
#!/usr/bin/python -tt
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import urllib2
|
||||
import logging
|
||||
from datetime import datetime
|
||||
import json as JSON
|
||||
import socket
|
||||
|
||||
from sr0wx_module import SR0WXModule
|
||||
|
||||
class AirlySq9atk(SR0WXModule):
|
||||
"""Klasa pobierająca dane o zanieszczyszczeniach"""
|
||||
|
||||
def __init__(self, language, api_key, lat, lon, service_url, mode, maxDistanceKM, installationId):
|
||||
self.__language = language
|
||||
self.__api_key = api_key
|
||||
self.__lat = str(lat)
|
||||
self.__lon = str(lon)
|
||||
self.__service_url = service_url
|
||||
self.__mode = mode
|
||||
self.__maxDistanceKM = str(maxDistanceKM)
|
||||
self.__installationId = str(installationId)
|
||||
self.__logger = logging.getLogger(__name__)
|
||||
self.__levels = {
|
||||
'VERY_LOW': 'bardzo_dobry',
|
||||
'LOW': 'dobry',
|
||||
'MEDIUM': 'umiarkowany',
|
||||
'HIGH': 'zly',
|
||||
'VERY_HIGH':'bardzo_zly',
|
||||
}
|
||||
|
||||
|
||||
def get_data(self):
|
||||
self.__logger.info("::: Pobieram dane o zanieczyszczeniach...")
|
||||
|
||||
api_service_url = self.prepareApiServiceUrl()
|
||||
self.__logger.info( api_service_url )
|
||||
|
||||
jsonData = JSON.loads(self.getAirlyData(api_service_url))
|
||||
|
||||
self.__logger.info("::: Przetwarzam dane...\n")
|
||||
|
||||
message = "".join([
|
||||
" _ ",
|
||||
" informacja_o_skaz_eniu_powietrza ",
|
||||
" _ ",
|
||||
" godzina ",
|
||||
self.getHour(),
|
||||
" _ stan_ogolny ",
|
||||
self.__levels[jsonData['current']['indexes'][0]['level']],
|
||||
self.getPollutionLevel(jsonData['current']['values']),
|
||||
" _ ",
|
||||
])
|
||||
return {
|
||||
"message": message,
|
||||
"source": "airly",
|
||||
}
|
||||
|
||||
|
||||
def getPollutionLevel(self, json):
|
||||
message = '';
|
||||
for item in json:
|
||||
if item['name'] == 'PM1':
|
||||
message += ' _ pyl__zawieszony_pm1 '
|
||||
message += self.__language.read_micrograms( int(item['value']) ) + ' '
|
||||
|
||||
if item['name'] == 'PM25':
|
||||
message += ' _ pyl__zawieszony_pm25 '
|
||||
message += self.__language.read_micrograms( int(item['value']) ) + ' '
|
||||
|
||||
if item['name'] == 'PM10':
|
||||
message += ' _ pyl__zawieszony_pm10 '
|
||||
message += self.__language.read_micrograms( int(item['value']) ) + ' '
|
||||
return message;
|
||||
|
||||
|
||||
def prepareApiServiceUrl(self):
|
||||
api_url = 'https://airapi.airly.eu/v2/measurements/'
|
||||
urls = {
|
||||
'installationId': api_url + 'measurements/installation?installationId=' + self.__installationId,
|
||||
'point': api_url + 'measurements/point?lat=' + self.__lat + '&lng=' + self.__lon,
|
||||
'nearest': api_url + 'nearest?lat=' + self.__lat + '&lng=' + self.__lon + '&maxDistanceKM=' + self.__maxDistanceKM,
|
||||
};
|
||||
return urls[self.__mode]
|
||||
|
||||
|
||||
def getAirlyData(self, url):
|
||||
request = urllib2.Request(url, headers={'Accept': 'application/json', 'apikey': self.__api_key})
|
||||
try:
|
||||
webFile = urllib2.urlopen(request, 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)])
|
||||
datetime_object = datetime.strptime(time, '%H:%M')
|
||||
msg = self.__language.read_datetime(datetime_object, '%H %M')
|
||||
return msg
|
||||
|
||||
|
||||
def getVisibility(self, value):
|
||||
msg = ' _ ';
|
||||
msg += ' widocznosc ' + self.__language.read_distance( int(value/1000) )
|
||||
return msg
|
||||
|
||||
|
|
@ -34,14 +34,14 @@ function azAZ09($string)
|
|||
function getMpg($word, $filename)
|
||||
{
|
||||
// $url = 'https://code.responsivevoice.org/getvoice.php?lang=pl-GB&engine=g1&name=&pitch=0.5&rate=0.5&volume=1&key=WGciAW2s&gender=female&text='.urlencode($word);
|
||||
$url = 'https://texttospeech.responsivevoice.org/v1/text:synthesize?lang=pl&engine=g1&name=&pitch=0.5&rate=0.5&volume=1&key=uu8DEkxz&gender=female&text='.urlencode($word);
|
||||
$url = 'https://texttospeech.responsivevoice.org/v1/text:synthesize?lang=pl&engine=g1&name=&pitch=0.5&rate=0.5&volume=1&key=WfWmvaX0&gender=female&text='.urlencode($word);
|
||||
|
||||
|
||||
$audio = file_get_contents_curl($url);
|
||||
|
||||
file_put_contents('mpg/'.$filename.'.mpg', $audio);
|
||||
|
||||
shell_exec ( "ffmpeg -i mpg/$filename.mpg -ar 16000 -ab 48000 -acodec libvorbis ogg/$filename.ogg");
|
||||
shell_exec ( "ffmpeg -y -i mpg/$filename.mpg -ar 32000 -ab 48000 -acodec libvorbis ogg/$filename.ogg");
|
||||
unlink("mpg/$filename.mpg");
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,25 @@
|
|||
|
||||
|
||||
// TABLICE Z SAMPLAMI DO MODUŁÓW
|
||||
$airly = array(
|
||||
array('pył zawieszony Pe eM 1','pyl__zawieszony_pm1'),
|
||||
array('pył zawieszony Pe eM 10','pyl__zawieszony_pm10'),
|
||||
array('pył zawieszony Pe eM 2 i pięć dziesiątych','pyl__zawieszony_pm25'),
|
||||
|
||||
array('bardzo dobry','bardzo_dobry'),
|
||||
array('dobry','dobry'),
|
||||
array('umiarkowany','umiarkowany'),
|
||||
array('zly','zły'),
|
||||
array('bardzo zły','bardzo_zly'),
|
||||
|
||||
array('stan_ogólny ','stan_ogolny'),
|
||||
|
||||
array('airly','airly'),
|
||||
array('godzina','godzina'),
|
||||
);
|
||||
|
||||
|
||||
|
||||
/// PROPAGACJA
|
||||
$slownikPropagacja = array(
|
||||
array('rigreferens','rigreference'),
|
||||
|
|
68
config.py
68
config.py
|
@ -95,37 +95,6 @@ openweathersq9atk = OpenWeatherSq9atk(
|
|||
service_url = 'http://api.openweathermap.org/data/2.5/'
|
||||
)
|
||||
|
||||
# STARY MODUŁ ZACIĄGAJĄCY POGODĘ Z ONETU
|
||||
# NA DOLE W KONFIGURACJI MA BYC JUŻ WYŁĄCZONY
|
||||
# ---------------
|
||||
# meteo_sq9atk
|
||||
# ---------------
|
||||
|
||||
#from meteo_sq9atk import MeteoSq9atk
|
||||
#meteosq9atk = MeteoSq9atk(
|
||||
# language=pl_google,
|
||||
# service_url="https://pogoda.onet.pl/prognoza-pogody/krakow-306020",
|
||||
#)
|
||||
# Warszawa: https://pogoda.onet.pl/prognoza-pogody/warszawa-357732
|
||||
# Kraków: https://pogoda.onet.pl/prognoza-pogody/krakow-306020
|
||||
# Wrocław: https://pogoda.onet.pl/prognoza-pogody/wroclaw-362450
|
||||
# Poznań: https://pogoda.onet.pl/prognoza-pogody/poznan-335979
|
||||
# Sopot: https://pogoda.onet.pl/prognoza-pogody/sopot-346875
|
||||
# Gdańsk: https://pogoda.onet.pl/prognoza-pogody/gdansk-287788
|
||||
# Białystok: https://pogoda.onet.pl/prognoza-pogody/bialystok-270085
|
||||
# Bydgoszcz: https://pogoda.onet.pl/prognoza-pogody/bydgoszcz-276560
|
||||
# Katowice: https://pogoda.onet.pl/prognoza-pogody/katowice-299998
|
||||
# Kielce: https://pogoda.onet.pl/prognoza-pogody/kielce-300882
|
||||
# Koszalin: https://pogoda.onet.pl/prognoza-pogody/koszalin-304806
|
||||
# Lublin: https://pogoda.onet.pl/prognoza-pogody/lublin-311624
|
||||
# Łódź: https://pogoda.onet.pl/prognoza-pogody/lodz-313660
|
||||
# Olsztyn: https://pogoda.onet.pl/prognoza-pogody/olsztyn-325715
|
||||
# Opole: https://pogoda.onet.pl/prognoza-pogody/opole-325985
|
||||
# Rzeszów: https://pogoda.onet.pl/prognoza-pogody/rzeszow-342624
|
||||
# Suwałki: https://pogoda.onet.pl/prognoza-pogody/suwalki-351446
|
||||
# Szczecin: https://pogoda.onet.pl/prognoza-pogody/szczecin-351892
|
||||
# Gdynia: https://pogoda.onet.pl/prognoza-pogody/gdynia-287798
|
||||
# Częstochowa: https://pogoda.onet.pl/prognoza-pogody/czestochowa-280687
|
||||
|
||||
# -----------------
|
||||
# meteoalarm_sq9atk
|
||||
|
@ -323,6 +292,23 @@ airpollutionsq9atk = AirPollutionSq9atk(
|
|||
# 10447 Kraków, os. Wadów
|
||||
)
|
||||
|
||||
# ---------------
|
||||
# airly_sq9atk
|
||||
# ---------------
|
||||
# https://developer.airly.org/ pod tym adresem można uzyskac klucz API
|
||||
# wystarczy sie zarejestrować
|
||||
from airly_sq9atk import AirlySq9atk
|
||||
airlysq9atk = AirlySq9atk(
|
||||
language = pl_google,
|
||||
api_key = '02b3a79363c3497dbb992093cd9d7779',
|
||||
service_url = 'https://airapi.airly.eu/v2/measurements', #location
|
||||
mode = 'nearest', # point|nearest|installationId
|
||||
lat = 50.079242,
|
||||
lon = 18.516138,
|
||||
maxDistanceKM = 5,
|
||||
installationId = 204,
|
||||
)
|
||||
|
||||
# --------------------
|
||||
# geomagnetic_sq9atk
|
||||
# --------------------
|
||||
|
@ -392,14 +378,14 @@ calendarsq9atk = CalendarSq9atk(
|
|||
|
||||
# WŁĄCZONE MODUŁY
|
||||
modules = [
|
||||
activitymap,
|
||||
openweathersq9atk,
|
||||
#meteosq9atk, # pogoda z onet-u, ten moduł jest zastąpiony przez openweathersq9atk
|
||||
meteoalarmsq9atk,
|
||||
imgwpodestsq9atk,
|
||||
airpollutionsq9atk,
|
||||
propagationsq9atk,
|
||||
geomagneticsq9atk,
|
||||
radioactivesq9atk,
|
||||
calendarsq9atk,
|
||||
activitymap, # marker na mapie wx.ostol.pl
|
||||
openweathersq9atk, # prognoza pogody
|
||||
meteoalarmsq9atk, # zagrożenia meteo
|
||||
imgwpodestsq9atk, # wodowskazy
|
||||
#airpollutionsq9atk, # zanieczyszczenia powietrza z GIOŚ
|
||||
airlysq9atk, # zanieczyszczenia powietrza z Airly
|
||||
propagationsq9atk, # propagacja KF
|
||||
geomagneticsq9atk, # zaburzenia geomagnetyczne
|
||||
radioactivesq9atk, # promieniowanie jonizujące
|
||||
calendarsq9atk, # wschód słońca
|
||||
]
|
||||
|
|
126
meteo_sq9atk.py
126
meteo_sq9atk.py
|
@ -1,126 +0,0 @@
|
|||
#!/usr/bin/python -tt
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import urllib2
|
||||
import re
|
||||
import logging
|
||||
import pytz
|
||||
from datetime import datetime
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import unicodedata
|
||||
|
||||
from sr0wx_module import SR0WXModule
|
||||
|
||||
class MeteoSq9atk(SR0WXModule):
|
||||
"""Klasa pobierająca dane kalendarzowe"""
|
||||
|
||||
def __init__(self,language,service_url):
|
||||
self.__service_url = service_url
|
||||
self.__language = language
|
||||
self.__logger = logging.getLogger(__name__)
|
||||
|
||||
def downloadFile(self, url):
|
||||
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)])
|
||||
datetime_object = datetime.strptime(time, '%H:%M')
|
||||
time_words = self.__language.read_datetime(datetime_object, '%H %M')
|
||||
return time_words
|
||||
|
||||
def parseForecastDesc(self, html):
|
||||
match = html.find_all("div", {"class":"forecastDesc"})[0].text
|
||||
return self.__language.rmv_pl_chars( match.strip().replace(" ", "_").replace(",","_") )
|
||||
|
||||
def parseTemperature(self, html):
|
||||
match = html.find_all("li")[0].find_all("span")[1]
|
||||
tempText = re.sub("[^(\-){0,1}(\s){0,1}0-9]", "", match.text)
|
||||
temp = self.__language.read_temperature(int(tempText))
|
||||
return temp
|
||||
|
||||
def parseClouds(self, html):
|
||||
match = html.find_all("li")[2].find_all("span")[1]
|
||||
tempText = re.sub("[^0-9]", "", match.text)
|
||||
temp = self.__language.read_percent(int(tempText))
|
||||
return temp
|
||||
|
||||
def parseWind(self, html):
|
||||
match = html.find_all("li")[3].find_all("span")[1]
|
||||
tempText = re.sub("[^0-9]", "", match.text)
|
||||
temp = self.__language.read_speed(int(tempText),"kmph")
|
||||
return temp
|
||||
|
||||
def parsePressure(self, html):
|
||||
match = html.find_all("li")[5].find_all("span")[1]
|
||||
tempText = re.sub("[^0-9]", "", match.text)
|
||||
temp = self.__language.read_pressure(int(tempText))
|
||||
return temp
|
||||
|
||||
def parseHumidity(self, html):
|
||||
match = html.find_all("li")[6].find_all("span")[1]
|
||||
tempText = re.sub("[^0-9]", "", match.text)
|
||||
temp = self.__language.read_percent(int(tempText))
|
||||
return temp
|
||||
|
||||
|
||||
|
||||
def get_data(self):
|
||||
self.__logger.info("::: Przetwarzam dane...\n")
|
||||
|
||||
rawHtml = self.downloadFile(self.__service_url)
|
||||
soup = BeautifulSoup(rawHtml ,"lxml")
|
||||
|
||||
now = soup.find_all("li", { "id" : "wts_p0" })[0]
|
||||
after = soup.find_all("li", { "id" : "wts_p3" })[0]
|
||||
forecast = soup.find_all("li", { "id" : "wts_p13" })[0]
|
||||
|
||||
|
||||
message = " ".join([ \
|
||||
"stan_pogody_z_godziny", self.getHour(), \
|
||||
|
||||
" _ ", self.parseForecastDesc(now), \
|
||||
"temperatura", self.parseTemperature(now), \
|
||||
"pokrywa_chmur", self.parseClouds(now), \
|
||||
"predkosc_wiatru", self.parseWind(now), \
|
||||
"cisnienie", self.parsePressure(now), \
|
||||
"wilgotnosc", self.parseHumidity(now), \
|
||||
|
||||
" _ ", "prognoza_na_nastepne","cztery", "godziny", \
|
||||
" _ ", self.parseForecastDesc(after), \
|
||||
"temperatura", self.parseTemperature(after), \
|
||||
"pokrywa_chmur", self.parseClouds(after), \
|
||||
"predkosc_wiatru", self.parseWind(after), \
|
||||
"cisnienie", self.parsePressure(after), \
|
||||
"wilgotnosc", self.parseHumidity(after), \
|
||||
|
||||
" _ ", "prognoza_na_nastepne","dwanascie", "godzin", \
|
||||
" _ ", self.parseForecastDesc(forecast), \
|
||||
"temperatura", self.parseTemperature(forecast), \
|
||||
"pokrywa_chmur", self.parseClouds(forecast), \
|
||||
"predkosc_wiatru", self.parseWind(forecast), \
|
||||
"cisnienie", self.parsePressure(forecast), \
|
||||
"wilgotnosc", self.parseHumidity(forecast), \
|
||||
])
|
||||
|
||||
return {
|
||||
"message": message,
|
||||
"source": "",
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Ładowanie…
Reference in New Issue