sfun commited on
Commit
75a98c8
1 Parent(s): 85d3c28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -4,6 +4,7 @@ import aiohttp
4
  import asyncio
5
  import datetime
6
  import sys
 
7
  from aiohttp import web
8
  from urllib.parse import parse_qs
9
 
@@ -86,9 +87,20 @@ async def log_request(request, response):
86
 
87
  @web.middleware
88
  async def logging_middleware(request, handler):
89
- response = await handler(request)
90
- await log_request(request, response)
91
- return response
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  async def handle_request(request):
94
  if request.path == '/':
@@ -96,11 +108,16 @@ async def handle_request(request):
96
  if 'url' in query_params:
97
  url = query_params['url'][0]
98
  try:
 
99
  async with aiohttp.ClientSession() as session:
100
  input_text = await fetch_url(url, session)
 
101
  result = await extract_and_transform_proxies(input_text)
 
102
  return web.Response(text=result, content_type='text/plain')
103
  except Exception as e:
 
 
104
  return web.Response(text=f"Error: {str(e)}", status=500)
105
  else:
106
  usage_guide = """
 
4
  import asyncio
5
  import datetime
6
  import sys
7
+ import traceback
8
  from aiohttp import web
9
  from urllib.parse import parse_qs
10
 
 
87
 
88
  @web.middleware
89
  async def logging_middleware(request, handler):
90
+ start_time = datetime.datetime.now()
91
+ try:
92
+ response = await handler(request)
93
+ await log_request(request, response)
94
+ end_time = datetime.datetime.now()
95
+ print(f"Request processing time: {end_time - start_time}", flush=True)
96
+ return response
97
+ except Exception as e:
98
+ end_time = datetime.datetime.now()
99
+ print(f"Error occurred: {str(e)}", flush=True)
100
+ print(f"Request processing time: {end_time - start_time}", flush=True)
101
+ print("Traceback:", flush=True)
102
+ traceback.print_exc()
103
+ return web.Response(text=f"Internal Server Error: {str(e)}", status=500)
104
 
105
  async def handle_request(request):
106
  if request.path == '/':
 
108
  if 'url' in query_params:
109
  url = query_params['url'][0]
110
  try:
111
+ print(f"Fetching URL: {url}", flush=True)
112
  async with aiohttp.ClientSession() as session:
113
  input_text = await fetch_url(url, session)
114
+ print(f"URL content length: {len(input_text)}", flush=True)
115
  result = await extract_and_transform_proxies(input_text)
116
+ print(f"Transformed result length: {len(result)}", flush=True)
117
  return web.Response(text=result, content_type='text/plain')
118
  except Exception as e:
119
+ print(f"Error processing request: {str(e)}", flush=True)
120
+ traceback.print_exc()
121
  return web.Response(text=f"Error: {str(e)}", status=500)
122
  else:
123
  usage_guide = """