Skip to content

Commit ac2bfe2

Browse files
committed
add script to fetch shelterluv data
1 parent 9fa2832 commit ac2bfe2

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

src/server/pipeline/api_data_fetch.py

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import requests
2+
import json
3+
import config
4+
5+
#################################
6+
# This script is used to fetch data from shelterluv API.
7+
# Please be mindful of your usage.
8+
# example: /people will fetch the data of all people. and send approximately 300 requests.
9+
# https://help.shelterluv.com/hc/en-us/articles/115000580127-Shelterluv-API-Overview
10+
#################################
11+
12+
######## Insights ###############
13+
# Max result items is 100 - even though it's not specifically specified in the above reference
14+
# /people has all the data. it seems that /person/:id isn't used
15+
#################################
16+
17+
shelterluv_token = "replace_with_secret_token" #dropbox
18+
19+
20+
''' Iterate over all shelterlove people and store in json file in the raw data folder
21+
We fetch 100 items in each request, since that is the limit based on our research '''
22+
def save_shelterluv_people_all():
23+
offset = 0
24+
LIMIT = 100
25+
has_more = True
26+
shelterluv_people = []
27+
28+
while has_more:
29+
r = requests.get("http://shelterluv.com/api/v1/people?limit={}&offset={}".format(LIMIT, offset),
30+
headers={"x-api-key": shelterluv_token})
31+
response = r.json()
32+
shelterluv_people += response["people"]
33+
has_more = response["has_more"]
34+
offset += 100
35+
36+
with open(config.RAW_DATA_PATH + "shelterLuv_people.json", "w") as outfile:
37+
json.dump(shelterluv_people, outfile, indent=4)

0 commit comments

Comments
 (0)