Created
June 7, 2016 07:07
-
-
Save ommadawn46/9925a4e4814a1804544a8067b50dd3c4 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
import json | |
def convertToStr(data): | |
if type(data) is unicode: | |
data = data.encode('utf-8') | |
elif not type(data) is str: | |
data = str(data) | |
return data | |
def writerow(f, cols): | |
for col in cols[:-1]: | |
f.write('"%s"\t' % convertToStr(col)) | |
f.write('"%s"\n' % convertToStr(cols[-1])) | |
fav_manga_data = [] | |
with open('favorite_manga_001.json', 'rb') as f: | |
fav_manga_data += json.load(f) | |
with open('favorite_manga_002.json', 'rb') as f: | |
fav_manga_data += json.load(f) | |
fav_manga_data.sort(cmp=lambda x, y: cmp(x['user']['id'], y['user']['id'])) | |
with open('result.tsv', 'wb') as f: | |
f.write('%s\t%s\t%s\t%s\t%s\t%s\n' % | |
('user_id', 'user_login', 'manga_id', 'manga_title','manga_author', 'mangapedia_title_url')) | |
for data in fav_manga_data: | |
for manga in sorted(data['user']['favorite_manga'], | |
cmp=lambda x, y: cmp(x['id'], y['id'])): | |
writerow(f, [data['user']['id'], | |
data['user']['login'], | |
manga['id'], | |
manga['title'], | |
manga['author'], | |
manga['mangapedia_url']]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment