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