Skip to content

Instantly share code, notes, and snippets.

@thisismattmiller
Created April 23, 2021 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisismattmiller/52a3f08c5ea33563eff43659c60b4ddf to your computer and use it in GitHub Desktop.
Save thisismattmiller/52a3f08c5ea33563eff43659c60b4ddf to your computer and use it in GitHub Desktop.
Python files for https://youtu.be/43unEJBV7VE
import requests
import json
with open("key.json") as keyjson:
key = json.load(keyjson)
def archive_search(keyword,limit=20,offset=0,total_only=0):
url = "https://www.brooklynmuseum.org/api/v2/archive/image/"
headers = {
'api_key': key['key']
}
params = {
'keyword' : keyword,
'limit' : limit,
'offset' : offset,
'total_count_only' : total_only
}
results = requests.get(url, headers=headers, params=params)
data = json.loads(results.text)
if total_only == 1:
return data['data']
else:
return data
keyword = 'bridge'
total_count = archive_search(keyword,0,0,1)
offset=0
print('there are',total_count, 'total')
all_results = []
while offset <= total_count:
data = archive_search(keyword,20,offset)
all_results = all_results + data['data']
offset = offset + 20
with open('bridge_data.json','w') as outfile:
json.dump(all_results, outfile, indent=2)
def str_normalize(string_to_do):
new_string = string_to_do
new_string = new_string.strip()
new_string = new_string.lower()
new_string = new_string.split('-')[0]
return new_string
print("TEST")
if __name__ == "__main__":
print('IM HERE!')
# str_list = ['Hello', "Goodbye ", "asdfasdfasdf-dontwant", "123456"," Hello"]
# for s in str_list:
# s = str_normalize(s)
# print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment