Arafath10 commited on
Commit
de093bc
1 Parent(s): 41d268b

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +34 -32
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
- while True:
27
- print("data fetcher running.....")
28
-
29
- # Initialize an empty DataFrame to store the combined data
30
- combined_df = pd.DataFrame()
31
-
32
- # Update the payload for each page
33
- url = "https://dev3.api.curfox.parallaxtec.com/api/ml/order-list?sort=id&paginate=500&page="+str(page)
34
-
35
- payload = {}
36
- headers = {
37
- 'Accept': 'application/json',
38
- 'X-Tenant': 'royalexpress'
39
- }
40
-
41
- response = requests.request("GET", url, headers=headers, data=payload)
42
-
43
- # Sample JSON response
44
- json_response = response.json()
45
- # Extracting 'data' for conversion
46
- data = json_response['data']
47
-
48
- df = pd.json_normalize(data)
49
-
50
- # Concatenate the current page's DataFrame with the combined DataFrame
51
- combined_df = pd.concat([combined_df, df], ignore_index=True)
52
-
53
- data = combined_df[combined_df['status.name'].isin(['RETURN TO CLIENT', 'DELIVERED'])]
54
- print("data collected from page : "+str(page))
55
- page+=1
56
- await asyncio.sleep(60) # Adjust the sleep interval as needed
 
 
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")