Created
August 27, 2017 10:12
-
-
Save anonymous/f7978dedd68ba206c563d9c1505eba49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=UTF-8 | |
#!/usr/bin/env python | |
import io | |
import urllib | |
import json | |
import gzip | |
import time | |
url = 'http://data.taipei/youbike' | |
url = urllib.urlretrieve(url, "data.gz") | |
jdata = gzip.open('data.gz', 'r').read() | |
data = json.loads(jdata) | |
t = time.localtime() | |
timestamp = time.strftime('%Y%m%d-%H%M%S', t) | |
file = io.open(timestamp, 'w', encoding = 'UTF-8') | |
for site in data["retVal"]: | |
s = data["retVal"][site]["sna"],",總停車格:",data["retVal"][site]["tot"],",可借數量:",data["retVal"][site]["sbi"]," 可停數量:",data["retVal"][site]["bemp"] | |
s = s[0] + unicode(s[1], "utf-8") + s[2] + unicode(s[3], "utf-8") + s[4] + unicode(s[5], "utf-8") + s[6] + '\n' | |
#print s | |
#raw_input() | |
file.write(s) | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment