Skip to content

Commit 753485b

Browse files
committed
Adjust ingest endpoint (internal)
Add TEST_MODE check on import
1 parent 4d11c91 commit 753485b

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ start_env.sh
2323
.mypy_cache/
2424
*secrets*
2525
*kustomization*
26+
src/.venv/
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
from api.API_ingest import shelterluv_api_handler
1+
from api.API_ingest import shelterluv_api_handler, sl_animal_events
22

33
def start(conn):
4-
print("Start Fetching raw data from different API sources")
4+
print("Start fetching raw data from different API sources")
5+
6+
print(" Fetching Shelterluv people")
7+
#Run each source to store the output in dropbox and in the container as a CSV
8+
slp_count = shelterluv_api_handler.store_shelterluv_people_all(conn)
9+
print(" Finished fetching Shelterluv people - %d records" % slp_count)
10+
11+
print(" Fetching Shelterluv events")
512
#Run each source to store the output in dropbox and in the container as a CSV
6-
shelterluv_api_handler.store_shelterluv_people_all(conn)
7-
print("Finish Fetching raw data from different API sources")
13+
sle_count = sl_animal_events.slae_test()
14+
print(" Finished fetching Shelterluv events - %d records" % sle_count)
15+
16+
print("Finished fetching raw data from different API sources")
17+
18+
19+
#TODO: Return object with count for each data source?

src/server/api/API_ingest/shelterluv_api_handler.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from constants import RAW_DATA_PATH
99
from models import ShelterluvPeople
1010

11+
12+
TEST_MODE = os.getenv("TEST_MODE")
13+
1114
try:
1215
from secrets_dict import SHELTERLUV_SECRET_TOKEN
1316
except ImportError:
@@ -78,6 +81,13 @@ def store_shelterluv_people_all(conn):
7881
has_more = response["has_more"]
7982
offset += 100
8083

84+
if offset % 1000 == 0:
85+
print("Reading offset ", str(offset))
86+
if TEST_MODE and offset > 1000:
87+
has_more=False # Break out early
88+
89+
90+
8191
print("Finish getting shelterluv contacts from people table")
8292

8393
print("Start storing latest shelterluvpeople results to container")
@@ -98,3 +108,5 @@ def store_shelterluv_people_all(conn):
98108

99109
print("Uploading shelterluvpeople csv to database")
100110
ShelterluvPeople.insert_from_df(pd.read_csv(file_path, dtype="string"), conn)
111+
112+
return offset

src/server/api/API_ingest/sl_animal_events.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
print("Couldn't get SHELTERLUV_SECRET_TOKEN from file or environment")
3939

4040

41+
TEST_MODE=os.getenv("TEST_MODE") # if not present, has value None
42+
4143
headers = {"Accept": "application/json", "X-API-Key": SHELTERLUV_SECRET_TOKEN}
4244

4345
logger = print # print to console for testing
@@ -143,6 +145,8 @@ def get_events_bulk():
143145
offset += limit
144146
if offset % 1000 == 0:
145147
print("Reading offset ", str(offset))
148+
if TEST_MODE and offset > 1000:
149+
more_records=False # Break out early
146150

147151
else:
148152
return -5 # AFAICT, this means URL was bad
@@ -155,7 +159,7 @@ def slae_test():
155159
print("Total events:", total_count)
156160

157161
b = get_events_bulk()
158-
print("Records:", len(b))
162+
print("Strored records:", len(b))
159163

160164
# f = filter_events(b)
161165
# print(f)

src/server/api/internal_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def user_test2():
2222
return jsonify(("OK from INTERNAL test/test @ " + str(datetime.now())))
2323

2424

25-
@internal_api.route("/api/ingestRawData", methods=["GET"])
25+
@internal_api.route("/api/internal/ingestRawData", methods=["GET"])
2626
def ingest_raw_data():
2727
try:
2828
with engine.begin() as conn:

0 commit comments

Comments
 (0)