Exercise: https://gist.github.com/jorin-vogel/2e43ffa981a97bc17259
Created
November 30, 2015 04:59
-
-
Save 7h3rAm/e3e445f677387310544a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from utils import read_json | |
cc_data = read_json('cc.json') | |
outfile = open('cc.csv', 'w') | |
for people in cc_data: | |
print people | |
if 'creditcard' in people and people['creditcard']: | |
line_str = '{name},{email}\n'.format( | |
name=people['name'], | |
email=people['email']) | |
outfile.write(line_str) | |
print '----- OK -----' | |
outfile.close() |
This file contains hidden or 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 requests | |
import time | |
url = 'https://gist.githubusercontent.com/jorin-vogel/7f19ce95a9a842956358/raw/e319340c2f6691f9cc8d8cc57ed532b5093e3619/data.json' | |
data = requests.get(url).json() | |
with open(time.strftime("%Y%m%d.csv"), 'w') as outfile: | |
outfile.write('name,creditcard\n') | |
outfile.writelines(['{name},{creditcard}\n'.format(**l) for l in data if l['creditcard']]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment