File size: 1,729 Bytes
919ec8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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)