Created
May 21, 2019 20:31
-
-
Save mbstacy/8e80fbc4da00e991ad9091fd47391b82 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 requests, json, os | |
from sys import argv | |
catalog_url = "https://libapps.colorado.edu/api/catalog/data/catalog/cuscholar.json" | |
headers={"Content-Type":"application/json","Authorization":"Token {0}".format(os.getenv('LIBAPPS_APITOKEN'))} | |
def get_cuscholar_data(): | |
#query='query={"filter":{},"projection":{"data_files.s3.key":1,"title":1,"_id":0}}' | |
#url = "{0}?page_size=100&{1}".format(catalog_url,query) | |
url = "{0}?page_size=100".format(catalog_url) | |
req=requests.get(url) | |
data= req.json()["results"] | |
for item in data[:25]: | |
#print (json.dumps(".".join(item['data_files']['s3']['key'].split('/')[-1].split('.')[:-1]),indent=4)) | |
#item['myspecial_test']="new new !!!!" | |
#item.pop('_id') | |
#post_update(item) | |
print(json.dumps(item,indent=4)) | |
def post_update(record): | |
url = "https://libapps.colorado.edu/api/catalog/data/catalog/cuscholartest.json" | |
req=requests.post(url,data=json.dumps(record),headers=headers) | |
print (req.text) | |
if __name__ == "__main__": | |
get_cuscholar_data() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment