Arafath10 commited on
Commit
e4f3adb
·
verified ·
1 Parent(s): 676e2a2

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +29 -31
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
- 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")
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():