Spaces:
Runtime error
Runtime error
| from GoogleNews import GoogleNews | |
| import pandas as pd | |
| import numpy as np | |
| import slack | |
| import time | |
| from datetime import datetime | |
| # Slack token | |
| SLACK_TOKEN = "xoxb-2557354538181-2570404709172-oNr1bsP5hQoFyOL1HqgqF8lv" | |
| # Initialize the slack client | |
| client = slack.WebClient(token = SLACK_TOKEN) | |
| # Google News Api | |
| googlenews = GoogleNews() | |
| googlenews = GoogleNews(lang='en', region='US') | |
| googlenews = GoogleNews(period='1h') | |
| googlenews.set_encode('utf-8') | |
| arr = [] | |
| while True: | |
| # Run this in for loop and is to be run continously | |
| today = datetime.now() | |
| # If its midnight reset the array | |
| if today.hour + today.minute == 0 and today.second<2: | |
| arr = [] | |
| # Search for the word crypto in googlenews | |
| googlenews.search("crypto") | |
| # Sort the results | |
| result = googlenews.results(sort=True) | |
| for i in result: | |
| # Now if a news has already been scraped, ignore it | |
| if i["title"] in arr: | |
| continue | |
| if "min" in i["date"]: | |
| # If the time for the news is in minute then only fetch it | |
| if "$" in i["desc"] or "$" in i["title"]: | |
| # If the title or decription contains dollar symbol, then go ahead | |
| if "million" in i["desc"].lower() or "raised" in i["desc"].lower(): | |
| # If million or raised keywords are present then go ahead | |
| arr.append(i["title"]) | |
| # Post the news on slack bot | |
| client.chat_postMessage(channel = "#bot_alerts", | |
| text = f'{i["datetime"]} {i["date"]} {i["title"]} {i["link"]} {i["desc"]}') | |
| # Clear the google news | |
| googlenews.clear() | |
| # Wait for 30seconds for next query | |
| time.sleep(30) |