Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -61,7 +61,7 @@ async def latest_earning():
|
|
61 |
url = "https://www.moneycontrol.com/markets/earnings/india-inc-earnings/?selected=all"
|
62 |
|
63 |
# Send a GET request to fetch the raw HTML content
|
64 |
-
response = requests.get(url)
|
65 |
|
66 |
# Parse the content using BeautifulSoup
|
67 |
soup = BeautifulSoup(response.content, "html.parser")
|
@@ -83,7 +83,7 @@ async def todays_news():
|
|
83 |
url = 'https://trendlyne.com/markets-today/'
|
84 |
# logging.info("getting news from %s", url)
|
85 |
# Fetch the HTML content of the webpage
|
86 |
-
html_content = requests.get(url).text
|
87 |
soup = BeautifulSoup(html_content, 'html.parser')
|
88 |
|
89 |
insights = soup.find_all(class_='insight-box')
|
@@ -210,7 +210,7 @@ def get_the_ticker(stock_name):
|
|
210 |
url = f'https://www.google.com/search?q={query}&FORM=HDRSC7'
|
211 |
# logging.info("searching ticker using url: %s",url)
|
212 |
# Fetch the HTML content of the webpage
|
213 |
-
html_content = requests.get(url).text # Fix: Added .text to access the response text
|
214 |
soup = BeautifulSoup(html_content, "html.parser")
|
215 |
pattern = re.compile(r'(\w+%[0-9A-Fa-f]{2}(?:[0-9A-Fa-f]{2}|[0-9A-Fa-f])*|[\w\.&%-]+)\.NS') # This pattern matches any word followed by .NS
|
216 |
matches = pattern.findall(str(soup))
|
@@ -230,7 +230,7 @@ async def get_the_ticker_stat(stock):
|
|
230 |
url = f'https://www.google.com/search?q={urllib.parse.quote(stock)}+site:businesstoday.in/stocks/&num=1&sca_esv=28795b6719ac1a08&sxsrf=ACQVn08xDA1EP1V6hJ-q4jLjjXSWWxgHTw:1711450545062&source=lnt&tbs=li:1&sa=X&ved=2ahUKEwj426eO4pGFAxX4n2MGHRXqBTUQpwV6BAgBEBM&biw=1280&bih=567&dpr=1.5'
|
231 |
# logging.info("getting ticker stat url from: %s", url)
|
232 |
# Fetch the HTML content of the webpage
|
233 |
-
html_content = requests.get(url).text # Fix: Added .text to access the response text
|
234 |
pattern = r'href="/url[?]q=(https://www.businesstoday.in/stocks/[^"]+)"'
|
235 |
# Find all matches using re.findall
|
236 |
links = re.findall(pattern, html_content)
|
@@ -239,7 +239,7 @@ async def get_the_ticker_stat(stock):
|
|
239 |
url = (links[0].split("&"))[0]
|
240 |
# logging.info("Final URL to fetch stats %s" , url)
|
241 |
# Fetch the HTML content of the webpage
|
242 |
-
html_content = requests.get(url).text
|
243 |
soup = BeautifulSoup(html_content, "html.parser")
|
244 |
script = soup.find("script", type="application/ld+json")
|
245 |
|
@@ -270,7 +270,7 @@ async def get_the_ticker_news(stock):
|
|
270 |
url = f'https://www.google.com/search?q={urllib.parse.quote(stock)}+site:trendlyne.com/research-reports&num=3&sca_esv=28795b6719ac1a08&sxsrf=ACQVn08xDA1EP1V6hJ-q4jLjjXSWWxgHTw:1711450545062&source=lnt&tbs=li:1&sa=X&ved=2ahUKEwj426eO4pGFAxX4n2MGHRXqBTUQpwV6BAgBEBM&biw=1280&bih=567&dpr=1.5'
|
271 |
# logging.info(url)
|
272 |
# Fetch the HTML content of the webpage
|
273 |
-
html_content = requests.get(url).text # Fix: Added .text to access the response text
|
274 |
pattern = r'href="/url[?]q=(https://trendlyne.com/research-reports/[^"]+)"'
|
275 |
# Find all matches using re.findall
|
276 |
links = re.findall(pattern, html_content)
|
|
|
61 |
url = "https://www.moneycontrol.com/markets/earnings/india-inc-earnings/?selected=all"
|
62 |
|
63 |
# Send a GET request to fetch the raw HTML content
|
64 |
+
response = requests.get(url,headers={'User-Agent': 'Mozilla/5.0'})
|
65 |
|
66 |
# Parse the content using BeautifulSoup
|
67 |
soup = BeautifulSoup(response.content, "html.parser")
|
|
|
83 |
url = 'https://trendlyne.com/markets-today/'
|
84 |
# logging.info("getting news from %s", url)
|
85 |
# Fetch the HTML content of the webpage
|
86 |
+
html_content = requests.get(url,headers={'User-Agent': 'Mozilla/5.0'}).text
|
87 |
soup = BeautifulSoup(html_content, 'html.parser')
|
88 |
|
89 |
insights = soup.find_all(class_='insight-box')
|
|
|
210 |
url = f'https://www.google.com/search?q={query}&FORM=HDRSC7'
|
211 |
# logging.info("searching ticker using url: %s",url)
|
212 |
# Fetch the HTML content of the webpage
|
213 |
+
html_content = requests.get(url,headers={'User-Agent': 'Mozilla/5.0'}).text # Fix: Added .text to access the response text
|
214 |
soup = BeautifulSoup(html_content, "html.parser")
|
215 |
pattern = re.compile(r'(\w+%[0-9A-Fa-f]{2}(?:[0-9A-Fa-f]{2}|[0-9A-Fa-f])*|[\w\.&%-]+)\.NS') # This pattern matches any word followed by .NS
|
216 |
matches = pattern.findall(str(soup))
|
|
|
230 |
url = f'https://www.google.com/search?q={urllib.parse.quote(stock)}+site:businesstoday.in/stocks/&num=1&sca_esv=28795b6719ac1a08&sxsrf=ACQVn08xDA1EP1V6hJ-q4jLjjXSWWxgHTw:1711450545062&source=lnt&tbs=li:1&sa=X&ved=2ahUKEwj426eO4pGFAxX4n2MGHRXqBTUQpwV6BAgBEBM&biw=1280&bih=567&dpr=1.5'
|
231 |
# logging.info("getting ticker stat url from: %s", url)
|
232 |
# Fetch the HTML content of the webpage
|
233 |
+
html_content = requests.get(url,headers={'User-Agent': 'Mozilla/5.0'}).text # Fix: Added .text to access the response text
|
234 |
pattern = r'href="/url[?]q=(https://www.businesstoday.in/stocks/[^"]+)"'
|
235 |
# Find all matches using re.findall
|
236 |
links = re.findall(pattern, html_content)
|
|
|
239 |
url = (links[0].split("&"))[0]
|
240 |
# logging.info("Final URL to fetch stats %s" , url)
|
241 |
# Fetch the HTML content of the webpage
|
242 |
+
html_content = requests.get(url,headers={'User-Agent': 'Mozilla/5.0'}).text
|
243 |
soup = BeautifulSoup(html_content, "html.parser")
|
244 |
script = soup.find("script", type="application/ld+json")
|
245 |
|
|
|
270 |
url = f'https://www.google.com/search?q={urllib.parse.quote(stock)}+site:trendlyne.com/research-reports&num=3&sca_esv=28795b6719ac1a08&sxsrf=ACQVn08xDA1EP1V6hJ-q4jLjjXSWWxgHTw:1711450545062&source=lnt&tbs=li:1&sa=X&ved=2ahUKEwj426eO4pGFAxX4n2MGHRXqBTUQpwV6BAgBEBM&biw=1280&bih=567&dpr=1.5'
|
271 |
# logging.info(url)
|
272 |
# Fetch the HTML content of the webpage
|
273 |
+
html_content = requests.get(url,headers={'User-Agent': 'Mozilla/5.0'}).text # Fix: Added .text to access the response text
|
274 |
pattern = r'href="/url[?]q=(https://trendlyne.com/research-reports/[^"]+)"'
|
275 |
# Find all matches using re.findall
|
276 |
links = re.findall(pattern, html_content)
|