File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -19,3 +19,4 @@ start_env.sh
19
19
/src /server /venv /
20
20
/src /local_files /
21
21
/src /server /secrets.py
22
+ /src /server /local_files /
Original file line number Diff line number Diff line change 1
1
import requests
2
- import json
3
- import config
2
+ import csv
3
+ from config import RAW_DATA_PATH
4
4
from secrets import SHELTERLUV_SECRET_TOKEN
5
5
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
+
6
25
#################################
7
26
# This script is used to fetch data from shelterluv API.
8
27
# Please be mindful of your usage.
@@ -31,8 +50,7 @@ def store_shelterluv_people_all():
31
50
has_more = response ["has_more" ]
32
51
offset += 100
33
52
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 )
36
54
37
55
38
56
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments