Mr-Help commited on
Commit
b5f9518
·
verified ·
1 Parent(s): 8eb8201

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -11
main.py CHANGED
@@ -1,5 +1,5 @@
1
  from fastapi import FastAPI, Request
2
- from datetime import datetime
3
 
4
  app = FastAPI()
5
 
@@ -8,13 +8,16 @@ async def receive_webhook(request: Request):
8
  payload = await request.json()
9
  print("📥 Webhook received:")
10
 
 
 
 
11
  # Top-level fields
12
  print(f"Request ID: {payload.get('request_id')}")
13
  print(f"Object: {payload.get('object')}")
14
  print(f"Time (Unix): {payload.get('time')}")
15
  try:
16
- readable_time = datetime.utcfromtimestamp(payload.get('time')).strftime('%Y-%m-%d %H:%M:%S UTC')
17
- print(f"Time (Formatted): {readable_time}")
18
  except Exception:
19
  print("Time (Formatted): Invalid timestamp")
20
  print("----")
@@ -30,13 +33,12 @@ async def receive_webhook(request: Request):
30
  print(f"Ad Group Name: {entry.get('adgroup_name')}")
31
  print(f"Ad ID: {entry.get('ad_id')}")
32
  print(f"Ad Name: {entry.get('ad_name')}")
33
-
34
- # Format create time if present
35
  create_ts = entry.get('create_time')
36
  print(f"Create Time (Unix): {create_ts}")
37
  try:
38
- create_time_fmt = datetime.utcfromtimestamp(create_ts).strftime('%Y-%m-%d %H:%M:%S UTC')
39
- print(f"Create Time (Formatted): {create_time_fmt}")
40
  except Exception:
41
  print("Create Time (Formatted): Invalid timestamp")
42
 
@@ -46,11 +48,9 @@ async def receive_webhook(request: Request):
46
  print(f"Lead Source: {entry.get('lead_source')}")
47
  print("----")
48
 
49
- # Loop through lead fields (changes)
50
  for change in entry.get('changes', []):
51
  print(f"{change.get('field').capitalize()}: {change.get('value')}")
52
  print("----")
53
 
54
- return {"status": "ok"}
55
-
56
- # Run with: uvicorn filename:app --reload
 
1
  from fastapi import FastAPI, Request
2
+ from datetime import datetime, timezone, timedelta
3
 
4
  app = FastAPI()
5
 
 
8
  payload = await request.json()
9
  print("📥 Webhook received:")
10
 
11
+ # Define GMT+3 offset
12
+ gmt_plus_3 = timezone(timedelta(hours=3))
13
+
14
  # Top-level fields
15
  print(f"Request ID: {payload.get('request_id')}")
16
  print(f"Object: {payload.get('object')}")
17
  print(f"Time (Unix): {payload.get('time')}")
18
  try:
19
+ formatted_time = datetime.fromtimestamp(payload.get('time'), gmt_plus_3).strftime('%Y-%m-%d %H:%M:%S GMT+3')
20
+ print(f"Time (Formatted): {formatted_time}")
21
  except Exception:
22
  print("Time (Formatted): Invalid timestamp")
23
  print("----")
 
33
  print(f"Ad Group Name: {entry.get('adgroup_name')}")
34
  print(f"Ad ID: {entry.get('ad_id')}")
35
  print(f"Ad Name: {entry.get('ad_name')}")
36
+
 
37
  create_ts = entry.get('create_time')
38
  print(f"Create Time (Unix): {create_ts}")
39
  try:
40
+ formatted_create_time = datetime.fromtimestamp(create_ts, gmt_plus_3).strftime('%Y-%m-%d %H:%M:%S GMT+3')
41
+ print(f"Create Time (Formatted): {formatted_create_time}")
42
  except Exception:
43
  print("Create Time (Formatted): Invalid timestamp")
44
 
 
48
  print(f"Lead Source: {entry.get('lead_source')}")
49
  print("----")
50
 
51
+ # Lead field values
52
  for change in entry.get('changes', []):
53
  print(f"{change.get('field').capitalize()}: {change.get('value')}")
54
  print("----")
55
 
56
+ return {"status": "ok"}