-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.py
More file actions
executable file
·60 lines (53 loc) · 1.58 KB
/
Copy pathexport.py
File metadata and controls
executable file
·60 lines (53 loc) · 1.58 KB
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
57
58
59
#!/usr/bin/env python2.6
# -*- encoding: utf8 -*-
import sys
import os
import optparse
import urllib2
import json
import codecs
from datetime import datetime
#reload(sys)
#sys.setdefaultencoding('utf-8')
def main(args):
'''\
%prog [options]
'''
lines = []
current_path = os.path.dirname(os.path.abspath(__file__))
response = urllib2.urlopen('https://wapi.gogoro.com/tw/api/vm/list')
data = json.load(response)
for d in data["data"]:
locname = json.loads(d["LocName"])
address = json.loads(d["Address"])
address = address["List"][1]["Value"].replace(",", u",")
if d["State"] == 1:
state = u"已啟用"
elif d["State"] == 99:
state = u"建置中"
else:
state = u"建置中(其他狀態%s)" % d["State"]
lines.append(u"%s,%s,%s,%s,%f,%f" %
(
locname["List"][1]["Value"],
address,
d["AvailableTime"],
state,
d["Latitude"],
d["Longitude"]
)
)
lines = sorted(lines)
with codecs.open("%s/gostation-%s.csv"
% (current_path, datetime.now().strftime("%Y%m%d")),
"w", "utf-8") as fo:
fo.write(u"站名,地址,營業時間,目前狀態,緯度,經度\r\n")
fo.write("\r\n".join(lines))
return 0
if __name__ == '__main__':
parser = optparse.OptionParser(usage=main.__doc__)
options, args = parser.parse_args()
if len(args) != 0:
parser.print_help()
sys.exit(1)
sys.exit(main(args))