Skip to content

Instantly share code, notes, and snippets.

@0187773933
Created August 1, 2023 20:30
Show Gist options
  • Save 0187773933/6691eb823a283c41069f2e8d266f73ab to your computer and use it in GitHub Desktop.
Save 0187773933/6691eb823a283c41069f2e8d266f73ab to your computer and use it in GitHub Desktop.
PhD Stipends Dot Com Data Downloader
#!/usr/bin/env python3
import requests
import json
def write_json( file_path , python_object ):
with open( file_path , 'w', encoding='utf-8' ) as f:
json.dump( python_object , f , ensure_ascii=False , indent=4 )
def read_json( file_path ):
with open( file_path ) as f:
return json.load( f )
def get_json( url ):
try:
headers = { 'accept': 'application/json, text/plain, */*', }
response = requests.get( url , headers=headers )
response.raise_for_status()
data = response.json()
if "data" not in data:
return False
if len( data["data"] ) < 1:
return False
return data["data"]
except Exception as e:
return False
if __name__ == "__main__":
done = False
i = 0
reports = []
while done == False:
url = f"http://www.phdstipends.com/data/{i}"
latest = get_json( url )
if latest == False:
done = True
break
reports += latest
print( "Downloaded :" , url , len( reports ) )
write_json( "reports.json" , reports )
i += 1
write_json( "reports.json" , reports )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment