BraydenMoore commited on
Commit
92f293d
·
1 Parent(s): f42ef1d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -0
main.py CHANGED
@@ -7,6 +7,7 @@ import datetime as dt
7
  import pytz
8
  from io import BytesIO
9
  import logging
 
10
 
11
  logging.basicConfig(level=logging.INFO)
12
 
@@ -22,6 +23,16 @@ with open('live_urls.pkl', 'rb') as f:
22
  with open('active_urls.pkl', 'rb') as f:
23
  live_urls = pkl.load(f)
24
 
 
 
 
 
 
 
 
 
 
 
25
  def get_ip_info(ip_address):
26
  try:
27
  response = requests.get(f"http://ipinfo.io/{ip_address}/json")
@@ -67,12 +78,15 @@ def proxy(url):
67
  logging.info(f"Status Code: {req.status_code}, Response Headers: {req.headers}")
68
  return Response(req.iter_content(chunk_size=512), content_type=req.headers['content-type'])
69
  except requests.exceptions.RequestException as e:
 
 
70
  logging.error(f"Error in proxy: {e}")
71
  return send_file('static/error.png', mimetype='image/png')
72
 
73
 
74
  @app.route('/')
75
  def index():
 
76
 
77
  if 'current_feed' in session and request.args.get('new', 'false') == 'false':
78
  feed = session['current_feed']
 
7
  import pytz
8
  from io import BytesIO
9
  import logging
10
+ import os
11
 
12
  logging.basicConfig(level=logging.INFO)
13
 
 
23
  with open('active_urls.pkl', 'rb') as f:
24
  live_urls = pkl.load(f)
25
 
26
+ def load_exception_urls():
27
+ url = os.environ['EXCEPTIONS']
28
+ response = requests.get(url)
29
+ return pkl.loads(response.content)
30
+
31
+ def save_exception_urls(exception_urls):
32
+ url = os.environ['EXCEPTIONS']
33
+ data = pkl.dumps(exception_urls)
34
+ requests.put(url, data=data)
35
+
36
  def get_ip_info(ip_address):
37
  try:
38
  response = requests.get(f"http://ipinfo.io/{ip_address}/json")
 
78
  logging.info(f"Status Code: {req.status_code}, Response Headers: {req.headers}")
79
  return Response(req.iter_content(chunk_size=512), content_type=req.headers['content-type'])
80
  except requests.exceptions.RequestException as e:
81
+ session['exception_urls'].append(url)
82
+ save_exception_urls(session['exception_urls'])
83
  logging.error(f"Error in proxy: {e}")
84
  return send_file('static/error.png', mimetype='image/png')
85
 
86
 
87
  @app.route('/')
88
  def index():
89
+ session['exception_urls'] = load_exception_urls()
90
 
91
  if 'current_feed' in session and request.args.get('new', 'false') == 'false':
92
  feed = session['current_feed']