Skip to content

Commit 0a750a2

Browse files
committed
update shelterluv data scraper to store as CSV
1 parent f9f6aed commit 0a750a2

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ start_env.sh
1919
/src/server/venv/
2020
/src/local_files/
2121
/src/server/secrets.py
22+
/src/server/local_files/

src/server/pipeline/shelterluv_api_handler.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
import requests
2-
import json
3-
import config
2+
import csv
3+
from config import RAW_DATA_PATH
44
from secrets import SHELTERLUV_SECRET_TOKEN
55

6+
7+
def write_csv(json_data):
8+
result = open(RAW_DATA_PATH + "shelterluv_people.csv", "w")
9+
10+
csv_writer = csv.writer(result)
11+
count = 0
12+
13+
for item in json_data:
14+
if count == 0:
15+
# Writing headers of CSV file
16+
header = item.keys()
17+
csv_writer.writerow(header)
18+
count += 1
19+
20+
# Writing data of CSV file
21+
csv_writer.writerow(item.values())
22+
23+
result.close()
24+
625
#################################
726
# This script is used to fetch data from shelterluv API.
827
# Please be mindful of your usage.
@@ -31,8 +50,7 @@ def store_shelterluv_people_all():
3150
has_more = response["has_more"]
3251
offset += 100
3352

34-
with open(config.RAW_DATA_PATH + "shelterLuv_people.json", "w") as outfile:
35-
json.dump(shelterluv_people, outfile, indent=4)
53+
write_csv(shelterluv_people)
3654

3755

3856
if __name__ == "__main__":

0 commit comments

Comments
 (0)