sigyllly commited on
Commit
c304bb4
·
verified ·
1 Parent(s): 5a67169

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -29
app.py CHANGED
@@ -1,34 +1,43 @@
1
  from flask import Flask, jsonify
2
  import requests
3
  from flask_cors import CORS
 
4
 
5
  app = Flask(__name__)
6
  CORS(app)
7
 
 
 
 
 
 
 
 
 
8
  @app.route('/generate_response', methods=['GET'])
 
9
  def generate_response():
10
  url = "https://www.urbanpro.com/dashboardApi/myDashboard"
11
-
12
  headers = {
13
- "Host": "www.urbanpro.com",
14
- "Connection": "keep-alive",
15
- "requestType": "xhr",
16
- "pragma": "no-cache",
17
- "sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
18
- "DNT": "1",
19
- "sec-ch-ua-mobile": "?0",
20
- "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",
21
- "Content-Type": "application/json",
22
- "cache-control": "no-cache",
23
- "sec-ch-ua-platform": "\"Windows\"",
24
- "Accept": "*/*",
25
- "Sec-Fetch-Site": "same-origin",
26
- "Sec-Fetch-Mode": "cors",
27
- "Sec-Fetch-Dest": "empty",
28
- "Accept-Encoding": "gzip, deflate, br",
29
- "Accept-Language": "en-US,en;q=0.9,hi;q=0.8",
30
- "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=a3VzdW1rdW1hcmlwYW5kZXkxMkBnbWFpbC5jb206MTc1NzkxMTkxMDA5NzoyNmFkNz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SIsInN1YiI6Imt1c3Vta3VtYXJpcGFuZGV5MTJAZ21haWwuY29tIiwicm9sZXMiOlsiUk9MRV9NRU1CRVIiXSwiZXhwIjoyMDM3ODQ3OTEwLCJpYXQiOjE3MjY4MDc5MTB9.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
31
-
32
  }
33
 
34
  data = {"OFFSET": 0, "MAX": 30, "type": "NEW"}
@@ -42,18 +51,18 @@ def generate_response():
42
  result = []
43
  for i, entry in enumerate(data_list, start=1):
44
  result.append({
45
- "Index": i,
46
- "Name": entry['name'],
47
- "Phone Number": entry['phoneNumber'],
48
- "EnqId": entry['enqId'],
49
- "Location": entry.get('location', ''),
50
- "classLocPref": entry.get('classLocPref', ''),
51
- "PostedOn": entry.get('postedOn', ''),
52
- })
53
 
54
  return jsonify(result)
55
 
56
  return jsonify({"error": f"Error: {response.status_code}, {response.text}"}), 500
57
 
58
  if __name__ == '__main__':
59
- app.run(host='0.0.0.0', port=7860)
 
1
  from flask import Flask, jsonify
2
  import requests
3
  from flask_cors import CORS
4
+ from flask_caching import Cache
5
 
6
  app = Flask(__name__)
7
  CORS(app)
8
 
9
+ # Configure caching
10
+ app.config['CACHE_TYPE'] = 'simple' # You can choose a caching type based on your requirements
11
+ cache = Cache(app)
12
+
13
+ # Use a production-ready server like Gunicorn
14
+ # Install Gunicorn: pip install gunicorn
15
+ # Run your app with: gunicorn -w 4 -b 0.0.0.0:5000 your_flask_app:app
16
+
17
  @app.route('/generate_response', methods=['GET'])
18
+ @cache.cached(timeout=60) # Cache the response for 60 seconds
19
  def generate_response():
20
  url = "https://www.urbanpro.com/dashboardApi/myDashboard"
 
21
  headers = {
22
+ "Host": "www.urbanpro.com",
23
+ "Connection": "keep-alive",
24
+ "Content-Length": "34",
25
+ "sec-ch-ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
26
+ "Accept": "application/json, text/plain, */*",
27
+ "Content-Type": "application/json",
28
+ "DNT": "1",
29
+ "sec-ch-ua-mobile": "?0",
30
+ "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",
31
+ "sec-ch-ua-platform": '"Windows"',
32
+ "Origin": "https://www.urbanpro.com",
33
+ "Sec-Fetch-Site": "same-origin",
34
+ "Sec-Fetch-Mode": "cors",
35
+ "Sec-Fetch-Dest": "empty",
36
+ "Referer": "https://www.urbanpro.com/register/providerDashboard",
37
+ "Accept-Encoding": "gzip, deflate, br",
38
+ "Accept-Language": "en-US,en;q=0.9,hi;q=0.8",
39
+ "Cookie": "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.eyJwcmluY2lwYWwiOiJINHNJQUFBQUFBQUFBSlZTdTI0VFFSUzlObzZDWkFrU0pKQW9URU9RS05EYVhqOEF1UUZIQmdsdEVoVGpKa2lnOGU3c012SHN6REtQeEc2UUt5aFNCQUdSRVB4Q1N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_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",
40
+
41
  }
42
 
43
  data = {"OFFSET": 0, "MAX": 30, "type": "NEW"}
 
51
  result = []
52
  for i, entry in enumerate(data_list, start=1):
53
  result.append({
54
+ "Index": i,
55
+ "Name": entry['name'],
56
+ "Phone Number": entry['phoneNumber'],
57
+ "EnqId": entry['enqId'],
58
+ "Location": entry.get('location', ''),
59
+ "classLocPref": entry.get('classLocPref', ''),
60
+ "PostedOn": entry.get('postedOn', ''),
61
+ })
62
 
63
  return jsonify(result)
64
 
65
  return jsonify({"error": f"Error: {response.status_code}, {response.text}"}), 500
66
 
67
  if __name__ == '__main__':
68
+ app.run(host='0.0.0.0', port=7860, debug=True)