-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAqiCaptor.py
32 lines (27 loc) · 1.07 KB
/
AqiCaptor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from Captor import Captor
import requests
from lxml import html
class AqiCaptor(Captor):
url = "http://aqicn.org/city/##/m/"
def __init__(self, logger):
self.logger = logger
def get_data(self, location):
scrapped_url = self.url.replace("##", location)
self.logger.info("scrapped_url=%s"% scrapped_url)
r = requests.get(scrapped_url, headers=self.headers_anonymous)
r.raise_for_status()
tree = html.fromstring(r.text)
data = {
'pm25': tree.xpath('//td[@id="cur_pm25"]/div/text()'),
'pm10': tree.xpath('//td[@id="cur_pm10"]/div/text()'),
'o3': tree.xpath('//td[@id="cur_o3"]/div/text()'),
'no2': tree.xpath('//td[@id="cur_no2"]/div/text()'),
'so2': tree.xpath('//td[@id="cur_so2"]/div/text()'),
'co': tree.xpath('//td[@id="cur_co"]/div/text()'),
'temperature': tree.xpath('//td[@id="cur_t"]/div/text()'),
'dew': tree.xpath('//td[@id="cur_d"]/div/text()'),
'pressure': tree.xpath('//td[@id="cur_p"]/div/text()'),
'humidity': tree.xpath('//td[@id="cur_h"]/div/text()'),
'wind': tree.xpath('//td[@id="cur_w"]/div/text()')
}
return data