-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvalue_extract.py
56 lines (51 loc) · 1.76 KB
/
value_extract.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from urllib import parse
from urllib.parse import unquote
parameter_dict = {
'lineid': '',
'lineno': '',
'direction': '',
'stationname': '',
'nextstationname': '',
'cityid': '',
'targetorder': '',
}
yaml_config_templ = """
- platform: bus_arrivaltime
name: {lineno}_bus_arrival
lineid: '{lineid}'
linename: '{lineno}'
direction: '{direction}'
stationname: '{stationname}'
nextstationname: '{nextstationname}'
lineno: '{lineno}'
targetorder: '{targetorder}'
cityid: '{cityid}'
#timerange: '083000-093000,174500-183000'
"""
link = r'''https://web.chelaile.net.cn/ch5/?src=webapp_qqwallet&utm_source=webapp_qqwallet&utm_medium=entrance&hideFooter=1&showFav=0&homePage=around&_wv=1027&showTopLogo=0&supportSubway=1&cityId=018&cityName=%E5%8D%97%E4%BA%AC&cityVersion=2#!/linedetail/2557257721/1/%E6%98%9F%E7%81%AB%E8%B7%AF%C2%B7%E6%B1%87%E6%96%87%E8%B7%AF/%E6%98%9F%E7%81%AB%E8%B7%AF%E5%9C%B0%E9%93%81%E7%AB%99%E4%B8%9C/6/668'''
link = unquote(link)
# print(link)
parseResult = parse.urlparse(link, scheme='https')
# print(parseResult)
query = parse.parse_qs(parseResult.query)
parameter_dict['cityid'] = query['cityId'][0]
# print(parseResult.fragment)
linedetail = parseResult.fragment.split('/')
linedetail = linedetail[2:]
for x in ['lineid', 'direction', 'stationname', 'nextstationname', 'targetorder', 'lineno']:
parameter_dict[x] = linedetail.pop(0)
from pprint import pprint
# pprint(parameter_dict)
print(yaml_config_templ.format(**parameter_dict))
'''
- platform: bus_arrivaltime
name: 668_bus_arrival
lineid: '2557257721'
linename: '668'
direction: '1'
stationname: '星火路·汇文路'
nextstationname: '星火路地铁站东'
lineno: '668'
targetorder: '6'
cityid: '018'
'''