sigyllly commited on
Commit
bb7a5d3
1 Parent(s): 24f0572

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +97 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import requests
3
+ from flask_cors import CORS
4
+ from functools import lru_cache
5
+ import concurrent.futures
6
+
7
+ app = Flask(__name__)
8
+ CORS(app)
9
+
10
+ # Function to get top header detail
11
+ @lru_cache(maxsize=128)
12
+ def get_top_header_detail(id):
13
+ url = f"https://www.urbanpro.com/dashboardApi/topHeaderDetail?id={id}"
14
+ headers = {
15
+ "Host": "www.urbanpro.com",
16
+ "Connection": "keep-alive",
17
+ "requestType": "xhr",
18
+ "pragma": "no-cache",
19
+ "sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
20
+ "DNT": "1",
21
+ "sec-ch-ua-mobile": "?0",
22
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
23
+ "Content-Type": "application/json",
24
+ "cache-control": "no-cache",
25
+ "sec-ch-ua-platform": "\"Windows\"",
26
+ "Accept": "*/*",
27
+ "Sec-Fetch-Site": "same-origin",
28
+ "Sec-Fetch-Mode": "cors",
29
+ "Sec-Fetch-Dest": "empty",
30
+ "Accept-Encoding": "gzip, deflate, br",
31
+ "Accept-Language": "en-US,en;q=0.9,hi;q=0.8",
32
+ "Cookie": "ApplicationGatewayAffinityCORS=59e9aaa731d02c5e07d5f1c3645d8b55; ApplicationGatewayAffinity=59e9aaa731d02c5e07d5f1c3645d8b55; JSESSIONID=2E1FB430F8F6B840D2536AEE40B2A90A; vis=8497ede2-9619-4a8d-8ea2-b31cf32179f2; referrer=seo%7Cwww.google.com%7C%7C%2Flogin%7C%7C; _gcl_au=1.1.758965275.1726809695; _cc=accept; _fbp=fb.1.1726809700440.451265153444350329; grails_remember_me=a3VzdW1rdW1hcmlwYW5kZXkxMkBnbWFpbC5jb206MTc1NzkxMTkxMDA5NzoyNmFkNzE1NzdkZjZjNjQ2NWVmNGMxZGMzOGNmYTY3NQ; city=Delhi; X-Auth-Token=eyJhbGciOiJIUzI1NiJ9.eyJwcmluY2lwYWwiOiJINHNJQUFBQUFBQUFBSlZTdTI0VFFSUzlObzZDWkFrU0pKQW9URU9RS05EYVhqOEF1UUZIQmdsdEVoVGpKa2lnOGU3c012SHN6REtQeEc2UUt5aFNCQUdSRVB4Q1N2NENHajRBUVVHYmhvYVd1NXZIR3BxSXFVWjN6cDV6N2ptN2Z3QnpXa0VqVW9SeDdTVGNSa3c0T2xGTVJKcjZWakV6Y2F5bUtxQW1ROXpQZ0FPY3dPRXBGS0hnUVpFRkJpNTRtMlNMVkRrUlVYVnR1RWw5MHhrcmNLV0tqaGhEUldLNkxkWElPZUgycGFKXC9DZVRVaFE5Rm1OK0FSZUw3MGdxektrVnZuREJGZ3cxWXlHZWU5RWZwNktLUEwxUVlScmllaGM1VFFZYWNCaDZVaVRYUEpLb3lxZzJjUHpSckRlUFZQalVkRDg0bVJHdDA5ODhtZlpOYVQ5OVRtd0kzZUE0dm9EUk9Dbmd3dTJzcDFFbDVuR1hKT1c3TnBOQkxBeEhMZ0lVc0ZVZithZVhOMTkyUDAwRVJBRE81Y2ZvMytmeHlGNmFmblwveStrZ1ZkOEExY21yR2V3enJqQk4wczVzeVBGRTJWdjcxXC8rSGJ2NE5Yak02aWNJdTc5Zng5TGQ0K1NteXpMT0NHS0dEblRFZEp1bDlJN2tuZFBKejl1WWVMMFdaeHdpbitVTURRNGtjaUpjZDJTa3Z3NGJ3UGw5VFd2OTNTbHQ5THRyWThOWEFcL2J0MnVrUWQxbU9HelYzWnROV21zMDYyR3QzYXFIdzdicis0MWJidGlrYmRkQVpXUzFqVWMySm9vbFJBUjBVbmZ2UkRGdWlLWmlOSDR1eXkwdDNQRWsxcjN6OFwvV1gzYXZmMGNRRG1Oc2kzRktzYlNFSHJkcDRTTlhMXC9iMUsrZDJQblN5RXpQZW4xcThcL0g3Ylp1bFFEQUFBPSIsInN1YiI6Imt1c3Vta3VtYXJpcGFuZGV5MTJAZ21haWwuY29tIiwicm9sZXMiOlsiUk9MRV9NRU1CRVIiXSwiZXhwIjoyMDM3ODQ3OTEwLCJpYXQiOjE3MjY4MDc5MTB9.m1vT-0Jk0aFjFRCsDCuZSZpET8AvUwexOJPRBI39_mw; _gid=GA1.2.1322345867.1726809736; _ga=GA1.1.63626453.1726809700; ph_phc_xgxrdGtjJy28xcQu3knyB36WFF98FkBr6EWhkE0qmWF_posthog=%7B%22distinct_id%22%3A%2201920de0-f3be-7e04-ac7f-6064c2836de8%22%2C%22%24sesid%22%3A%5B1726810128730%2C%2201920de0-f3bc-7ba7-bb85-5d9bf3d9afb4%22%2C1726809699260%5D%7D; _ga_PZ985ML4Z1=GS1.1.1726809699.1.1.1726810129.23.0.0", # Replace with actual cookies
33
+ }
34
+ response = requests.get(url, headers=headers)
35
+ return response.json()
36
+
37
+ # Function to get virtual number
38
+ @lru_cache(maxsize=128)
39
+ def get_virtual_number(id, seeker_member_id):
40
+ url = f"https://www.urbanpro.com/virtualNumberAllocation/getVirtualNumberToCall?callMember={seeker_member_id}&enquiryId={id}"
41
+ headers = {
42
+ "Host": "www.urbanpro.com",
43
+ "Connection": "keep-alive",
44
+ "requestType": "xhr",
45
+ "pragma": "no-cache",
46
+ "sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
47
+ "DNT": "1",
48
+ "sec-ch-ua-mobile": "?0",
49
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
50
+ "Content-Type": "application/json",
51
+ "cache-control": "no-cache",
52
+ "sec-ch-ua-platform": "\"Windows\"",
53
+ "Accept": "*/*",
54
+ "Sec-Fetch-Site": "same-origin",
55
+ "Sec-Fetch-Mode": "cors",
56
+ "Sec-Fetch-Dest": "empty",
57
+ "Accept-Encoding": "gzip, deflate, br",
58
+ "Accept-Language": "en-US,en;q=0.9,hi;q=0.8",
59
+ "Cookie": "JSESSIONID=F091540D532461FE2F4550A299162EB1; vis=90d99535-7a89-4de2-b0aa-41c3d9ac796f; referrer=direct%7Cthinkvidya%7C%2Fregister%2FproviderDashboard%7C%7C%7C; GCILB="23f8b9413d8c6a92"; _gcl_au=1.1.274210954.1733182145; _cc=accept; _ga=GA1.1.903490252.1733182151; _fbp=fb.1.1733182152277.67239322565084397; abt=132; grails_remember_me=dGliYWtleTQ2NEBqb25lc3BhbC5jb206MTc2NDI4NjQzMzM1MDowNzJlNjJlNzM3OWNkN2VlYjg2MjkyMzZmNmE5ZWM1YQ; X-Auth-Token=eyJhbGciOiJIUzI1NiJ9.eyJwcmluY2lwYWwiOiJINHNJQUFBQUFBQUFBSlZTUDJcL1RRQno5T2FRcVVpUm9rUUF4bElVaU1TREhOQ0VoeWdLcEFoSnlXOVNRcFVpZzhcL2xzTGpuZm1idHpteXdvRXd3ZGlvQWlCRitobjRDdkFFTGlBeUFZV0R1emN1ZitjV0NwdU9uMHUrZjMzdTg5NyszRGpKSlFpeVdpVExrcHkyTEtYWlZLeW1ORmNDYXBIcnVaSWpJa09rZmN5NEY5TTRHRDQ1VEE4YUZFUXczblwvQUhhUkZXR2VGeGRDd1lFNlwvWkl3cEtROFNGakpGRkN0b1FjdXNmY1dFanlsMEJCN1h3b3dld0d6Q09NUmNiMXF1RGRVVW9sQ1RkZ3JwajVBZ1wvdDZEdzJMNFJyaXBpYWhzNFNqZ0pHUWg4cUtOTlBoVkdsUkdrNGUyQTIwNVJWZTBTM2ZUaWRJcVdNdTM4MjZXbHIzYjVibTl4czhBeWVRM21VT3VhWTdLNWFxR3Q1M0dYQm1ObWFDcTRXK3p3UklZMm9GVGY4azRYWDMzWStUdm9sQUpQSjlaT1wvS2VhWE9qRDVcL1BqMzVUeG9CMnU0TUdXOWdMVkhxWEV6WHpBXC9sTVFxZjNcL1wvNE0zdVwvc3RIcDR5eVJkejlcL3o0Vzd4d21OMTRXU1lvazBtS3FJME83VmJaM1E5NDVtZnlvaGJIYm8wbktpUG1qdUNiaHNVUkJiTll0UzhHTzh0WlFXVlwvenUwOVd1aXVkN3ZwSXc3WElhOVJ2WU5MQ1ViUGxOV3YxSlM5bzFGcTNjT0RWd3B1UkY0UmhvOW4wYXBHR2k1b0dhRWpHOVViOTlrQndvbExFakozRVdENlRKMmFyZG4xaGl0Nys5ZXJMenBVZlJ2NCt6R3dpbGhGVDJGd0JXczJTZ01nWGU3c0xsYmNcL3RcL1AxYzhkZlA3MzdBeXNjSWhST0F3QUEiLCJzdWIiOiJ0aWJha2V5NDY0QGpvbmVzcGFsLmNvbSIsInJvbGVzIjpbIlJPTEVfTUVNQkVSIl0sImV4cCI6MjA0NDIyMjQzMywiaWF0IjoxNzMzMTgyNDMzfQ.xlM9xUNLxuhdZSyfROB37T8w65cslmL2Dle_Flmco3Y; city=Bangalore; ph_phc_xgxrdGtjJy28xcQu3knyB36WFF98FkBr6EWhkE0qmWF_posthog=%7B%22distinct_id%22%3A%22019389b4-e1c7-721d-b640-28ea46155f1c%22%2C%22%24sesid%22%3A%5B1733182517190%2C%22019389b4-e1c2-7af4-8e60-f2f6a8af5538%22%2C1733182153154%5D%2C%22%24initial_person_info%22%3A%7B%22r%22%3A%22%24direct%22%2C%22u%22%3A%22https%3A%2F%2Fwww.urbanpro.com%2Flogin%22%7D%7D; _ga_PZ985ML4Z1=GS1.1.1733182151.1.1.1733182517.18.0.0",
60
+ }
61
+ response = requests.get(url, headers=headers)
62
+ return response.json()
63
+
64
+ @app.route("/generate_response", methods=["POST"])
65
+ def generate_response():
66
+ try:
67
+ data = request.get_json()
68
+ id = data.get("id")
69
+
70
+ # First API call to get top header detail
71
+ top_header_data = get_top_header_detail(id)
72
+ seeker_member_id = top_header_data["data"]["seekerMemberId"]
73
+
74
+ # Second API call to get virtual number
75
+ virtual_number_data = get_virtual_number(id, seeker_member_id)
76
+ actual_number = virtual_number_data.get("actualNumber")
77
+ virtual_number = virtual_number_data.get("virtualNumber")
78
+
79
+ # If actual number is None, return the virtual number
80
+ if actual_number is None:
81
+ return jsonify({
82
+ "number": virtual_number,
83
+ "isVirtual": True # Indicate it's a virtual number
84
+ })
85
+ else:
86
+ return jsonify({
87
+ "number": actual_number,
88
+ "isVirtual": False # Indicate it's an actual number
89
+ })
90
+
91
+ except Exception as e:
92
+ print('Error processing request. Request data:', request.get_json())
93
+ print('Error details:', str(e))
94
+ return jsonify({"error": str(e)}), 500
95
+
96
+ if __name__ == '__main__':
97
+ app.run(host='0.0.0.0', port=7860, debug=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Flask
2
+ Gunicorn
3
+ Flask-Cors
4
+ requests
5
+ Flask-Caching