Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -18,50 +18,48 @@ app.add_middleware(
|
|
18 |
global page
|
19 |
page = 1
|
20 |
# Declare the continuous function as an async function.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
async def your_continuous_function():
|
22 |
-
import pandas as pd
|
23 |
-
import requests
|
24 |
-
import json,httpx
|
25 |
global page
|
26 |
-
|
27 |
-
|
28 |
-
while True:
|
29 |
-
print("data fetcher running.....")
|
30 |
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
|
39 |
'Accept': 'application/json',
|
40 |
'X-Tenant': 'royalexpress'
|
41 |
}
|
42 |
|
43 |
-
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
51 |
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
await asyncio.sleep(60) # Adjust the sleep interval as needed
|
59 |
-
|
60 |
-
# Create a startup event.
|
61 |
-
@app.on_event("startup")
|
62 |
-
async def startup_event():
|
63 |
-
# Start the continuous function as a background task.
|
64 |
-
asyncio.create_task(your_continuous_function())
|
65 |
|
66 |
@app.get("/test_api")
|
67 |
async def test_api():
|
|
|
18 |
global page
|
19 |
page = 1
|
20 |
# Declare the continuous function as an async function.
|
21 |
+
#async def your_continuous_function():
|
22 |
+
|
23 |
+
#await asyncio.sleep(60) # Adjust the sleep interval as needed
|
24 |
+
|
25 |
+
# Create a startup event.
|
26 |
+
#@app.on_event("startup")
|
27 |
+
#async def startup_event():
|
28 |
+
# Start the continuous function as a background task.
|
29 |
+
#asyncio.create_task(your_continuous_function())
|
30 |
+
|
31 |
+
@app.get("/trigger_the_data_fecher_every_60s")
|
32 |
async def your_continuous_function():
|
|
|
|
|
|
|
33 |
global page
|
34 |
+
print("data fetcher running.....")
|
|
|
|
|
|
|
35 |
|
36 |
+
# Initialize an empty DataFrame to store the combined data
|
37 |
+
combined_df = pd.DataFrame()
|
38 |
|
39 |
+
# Update the payload for each page
|
40 |
+
url = "https://dev3.api.curfox.parallaxtec.com/api/ml/order-list?sort=id&paginate=500&page="+str(page)
|
41 |
|
42 |
+
payload = {}
|
43 |
+
headers = {
|
44 |
'Accept': 'application/json',
|
45 |
'X-Tenant': 'royalexpress'
|
46 |
}
|
47 |
|
48 |
+
response = requests.request("GET", url, headers=headers, data=payload)
|
49 |
|
50 |
+
# Sample JSON response
|
51 |
+
json_response = response.json()
|
52 |
+
# Extracting 'data' for conversion
|
53 |
+
data = json_response['data']
|
54 |
|
55 |
+
df = pd.json_normalize(data)
|
56 |
|
57 |
+
# Concatenate the current page's DataFrame with the combined DataFrame
|
58 |
+
combined_df = pd.concat([combined_df, df], ignore_index=True)
|
59 |
|
60 |
+
data = combined_df[combined_df['status.name'].isin(['RETURN TO CLIENT', 'DELIVERED'])]
|
61 |
+
print("data collected from page : "+str(page))
|
62 |
+
page+=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
@app.get("/test_api")
|
65 |
async def test_api():
|