tL-ddmu_gt / app.py
sigyllly's picture
Upload 2 files
bb7a5d3 verified
raw
history blame
7.84 kB
from flask import Flask, request, jsonify
import requests
from flask_cors import CORS
from functools import lru_cache
import concurrent.futures
app = Flask(__name__)
CORS(app)
# Function to get top header detail
@lru_cache(maxsize=128)
def get_top_header_detail(id):
url = f"https://www.urbanpro.com/dashboardApi/topHeaderDetail?id={id}"
headers = {
"Host": "www.urbanpro.com",
"Connection": "keep-alive",
"requestType": "xhr",
"pragma": "no-cache",
"sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
"DNT": "1",
"sec-ch-ua-mobile": "?0",
"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",
"Content-Type": "application/json",
"cache-control": "no-cache",
"sec-ch-ua-platform": "\"Windows\"",
"Accept": "*/*",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9,hi;q=0.8",
"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.eyJwcmluY2lwYWwiOiJINHNJQUFBQUFBQUFBSlZT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E3MjY4MDc5MTB9.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
}
response = requests.get(url, headers=headers)
return response.json()
# Function to get virtual number
@lru_cache(maxsize=128)
def get_virtual_number(id, seeker_member_id):
url = f"https://www.urbanpro.com/virtualNumberAllocation/getVirtualNumberToCall?callMember={seeker_member_id}&enquiryId={id}"
headers = {
"Host": "www.urbanpro.com",
"Connection": "keep-alive",
"requestType": "xhr",
"pragma": "no-cache",
"sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
"DNT": "1",
"sec-ch-ua-mobile": "?0",
"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",
"Content-Type": "application/json",
"cache-control": "no-cache",
"sec-ch-ua-platform": "\"Windows\"",
"Accept": "*/*",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9,hi;q=0.8",
"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;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ys5ZXJMenBVZlJ2NCt6R3dpbGhGVDJGd0JXczJTZ01nWGU3c0xsYmNcL3RcL1AxYzhkZlA3MzdBeXNjSWhST0F3QUEiLCJzdWIiOiJ0aWJha2V5NDY0QGpvbmVzcGFsLmNvbSIsInJvbGVzIjpbIlJPTEVfTUVNQkVSIl0sImV4cCI6MjA0NDIyMjQzMywiaWF0IjoxNzMzMTgyNDMzfQ.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",
}
response = requests.get(url, headers=headers)
return response.json()
@app.route("/generate_response", methods=["POST"])
def generate_response():
try:
data = request.get_json()
id = data.get("id")
# First API call to get top header detail
top_header_data = get_top_header_detail(id)
seeker_member_id = top_header_data["data"]["seekerMemberId"]
# Second API call to get virtual number
virtual_number_data = get_virtual_number(id, seeker_member_id)
actual_number = virtual_number_data.get("actualNumber")
virtual_number = virtual_number_data.get("virtualNumber")
# If actual number is None, return the virtual number
if actual_number is None:
return jsonify({
"number": virtual_number,
"isVirtual": True # Indicate it's a virtual number
})
else:
return jsonify({
"number": actual_number,
"isVirtual": False # Indicate it's an actual number
})
except Exception as e:
print('Error processing request. Request data:', request.get_json())
print('Error details:', str(e))
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860, debug=True)