Last active
December 15, 2016 12:46
-
-
Save AnnamalaiNagappan/4ee1ffaa61960c280dbb3bce0abdf236 to your computer and use it in GitHub Desktop.
Using python to get udacity courses via their API and store it in csv file
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
''' | |
1. Get latest updates on udacity courses via their API | |
2. Using python and pandas will get all the details about courses in a csv file | |
''' | |
import json | |
import urllib | |
import pandas as pd | |
response = urllib.urlopen('https://udacity.com/public-api/v0/courses') | |
json_response = json.loads(response.read()) | |
course = json_response['courses'] | |
''' | |
Dumping to JSON File | |
''' | |
course = json_response['courses'] | |
with open('data.json', 'w') as outfile: | |
json.dump(course, outfile, indent=4, sort_keys=True, separators=(',', ':')) | |
''' | |
Reading JSON file in pandas to a dataframe | |
which enables us to convert to a csv file | |
''' | |
df = pd.read_json('data.json') | |
df.to_csv("courses.csv", index=False, encoding="utf-8") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment