Illioa commited on
Commit
809bfe4
·
1 Parent(s): 4b61443

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -6,6 +6,24 @@ from requests_html import AsyncHTMLSession
6
  import streamlit as st
7
  import threading
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  async def get_dict_topic():
10
  asession = AsyncHTMLSession()
11
  response = await asession.get('https://uk.tgstat.com/')
@@ -71,8 +89,10 @@ async def get_channels_by_category(category_name):
71
 
72
  for key in dict_.keys():
73
  if key in required_columns and key != 'Возраст канала':
74
- dict_[key]=eval(dict_[key][0].replace(' ', '').replace('всего',' ').replace('%','/100').replace('k','*1000'))
75
-
 
 
76
  del dict_['Возраст канала']
77
  dict_['TG Link'] = list(r.find('body > div.wrapper > div > div.content.p-0.col > div.container-fluid.px-2.px-md-3 > div:nth-child(2) > div > div > div > div.col-12.col-sm-7.col-md-8.col-lg-6 > div.text-center.text-sm-left > a')[0].absolute_links)[0]
78
  return dict_
 
6
  import streamlit as st
7
  import threading
8
 
9
+ def safe_eval(expression):
10
+ operators = {
11
+ '+': '__add__',
12
+ '-': '__sub__',
13
+ '*': '__mul__',
14
+ '/': '__truediv__',
15
+ '%': '__mod__'
16
+ }
17
+
18
+ try:
19
+ for operator, method in operators.items():
20
+ if operator in expression:
21
+ return str(getattr(expression.split(operator)[0], method)(float(expression.split(operator)[1])))
22
+ return expression
23
+ except Exception as e:
24
+ print(f"Error evaluating expression '{expression}': {e}")
25
+ return None
26
+
27
  async def get_dict_topic():
28
  asession = AsyncHTMLSession()
29
  response = await asession.get('https://uk.tgstat.com/')
 
89
 
90
  for key in dict_.keys():
91
  if key in required_columns and key != 'Возраст канала':
92
+ transformed_value = safe_eval(dict_[key][0].replace(' ', '').replace('всего',' ').replace('%','/100').replace('k','*1000'))
93
+ if transformed_value is not None:
94
+ dict_[key] = transformed_value
95
+
96
  del dict_['Возраст канала']
97
  dict_['TG Link'] = list(r.find('body > div.wrapper > div > div.content.p-0.col > div.container-fluid.px-2.px-md-3 > div:nth-child(2) > div > div > div > div.col-12.col-sm-7.col-md-8.col-lg-6 > div.text-center.text-sm-left > a')[0].absolute_links)[0]
98
  return dict_