コード例 #1
0
async def create_item(item: Item):
    result = ""
    googlenews = GoogleNews()
    googlenews.set_lang('pt')
    googlenews.search(item.mensagem)
    googlenews.results()
    result = googlenews.get_texts()[0]
    translations  = translator.translate(result, dest='en')
    textTranslator = translations.text
    score = analyser.polarity_scores(textTranslator) # avaliação de polaridade de sentimento da mensagem
    compound = (analyser.polarity_scores(textTranslator)['compound'])  # capitura da média do sentimento da mensagem
    if compound > 0:
      mensagemSentimento = "noticia positiva" 
    elif compound >= 0:
      mensagemSentimento = "noticia neutra" 
    else:
      mensagemSentimento = "noticia negativa"
    return {"mensagem":googlenews.get_texts()[0],"sentimento":mensagemSentimento}
コード例 #2
0
ファイル: news.py プロジェクト: eriksonlb/TARS
def get_news(assunto):
    news = GoogleNews(period='d')
    news.setlang('pt')
    news.set_encode('utf-8')
    news.set_time_range('12/02/2021', '13/02/2021')
    news.get_news(assunto)
    results = news.get_texts()
    result = results[3:8] if len(results) > 0 else "Sem notícias recentes"
    return result
コード例 #3
0
def crawl(coin):
    page = news_pages[search_keyword.index(coin)]
    news = GoogleNews(lang='ko', encode='utf-8')
    news.search(coin)
    time.sleep(30)
    news.getpage(page)
    title = news.get_texts()
    url = news.get_links()
    desc = news.get_desc()
    for t, u, d in zip(title, url, desc):
        # print(d)
        idx = coin_index[search_keyword.index(coin)]
        if t != "" and u != "" and d != "":
            dic = {
                u"title": u'{}'.format(t),
                u"desc": u'{}'.format(d),
                u"link": u'{}'.format(u)
            }
            if coin_list[search_keyword.index(coin)] in t or coin_eng[
                    search_keyword.index(coin)] in t:
                if idx == 0:
                    ref = db.collection(u'{}'.format(
                        coin_eng[search_keyword.index(coin)]))
                    ref.add(dic)
                    time.sleep(random.uniform(2, 4))
                    coin_index[search_keyword.index(coin)] += 1
                else:
                    flag = True
                    ref = db.collection(u'{}'.format(
                        coin_eng[search_keyword.index(coin)])).stream()
                    for doc in ref:
                        time.sleep(random.uniform(1, 3))
                        check_dic = doc.to_dict()
                        #print('[check] {}'.format(check_dic))
                        if dic['title'] == check_dic['title']:
                            flag = False
                            break
                    if flag:
                        print('[{}] ///// {} '.format(coin, dic))
                        ref = db.collection(u'{}'.format(
                            coin_eng[search_keyword.index(coin)]))
                        ref.add(dic)
                        time.sleep(random.uniform(1, 5))
                        #print(coin,t,u)
                        coin_index[search_keyword.index(coin)] += 1
    news_pages[search_keyword.index(coin)] += 1
コード例 #4
0
    elif analysis.sentiment.polarity == 0:
        return 0
    else:
        return -1


# news_df.to_excel("articles.xlsx")

user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
config = Config()
config.browser_user_agent = user_agentgooglenews = GoogleNews(
    start='05/01/2020', end='05/31/2020')
googlenews = GoogleNews()
googlenews.search('Bitcoin')
# result=googlenews.result(sort=True)
result = googlenews.get_texts()
for i in result:
    sentiment = analyse_text(i)
    # print(i)
    if sentiment == 1:
        positive = positive + 1
    elif sentiment == 0:
        neutral = neutral + 1
    else:
        negative = negative + 1
    calculate_percentage()
df = pd.DataFrame(result)
# print(df.head())
for i in range(2, 20):
    googlenews.getpage(i)
    # result=googlenews.result(sort=True)
コード例 #5
0
 def _google(self):
     news = GoogleNews(period='1d')
     news.get_news(
         self._ticker
     )  # @TODO how to also accomodate full name (case insensitive)
     self._news = news.get_texts()
コード例 #6
0
ファイル: alexa.py プロジェクト: vimal0312/alexa
def run_alexa():
    command = take_command()
    print(command)
    if 'music' in command:
        song = command.replace('play song', '')
        talk('I am playing your favourite ' + song)
        # print('playing')
        print(song)
        # playing the first video that appears in yt search
        pywhatkit.playonyt(song)

    elif 'time' in command:
        now = datetime.now()
        time = now.strftime("%H:%M:%S")
        print("time:", time)
        talk("Current time is " + time)

    elif ('month' or 'year') in command:
        now = datetime.now()
        year = now.strftime("%Y")
        print("year:", year)
        talk("Current year is  " + year)
        month = now.strftime("%m")
        print("month:", month)
        talk("Current month is  " + month)

    elif 'date' in command:
        now = datetime.now()
        date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
        print("date and time:", date_time)
        talk("Current date and time is " + date_time)

    # opens web.whatsapp at specified time i.e before 10 minutes and send the msg
    elif 'whatsapp' in command:
        talk("To which number do you have to whatsapp")
        talk("Please dont forget to enter 10 digits with country code")
        num = input()
        talk("Enter the message you have to send")
        msg = input()
        talk("Enter the time to send the message")
        time = int(input())
        pywhatkit.sendwhatmsg(num, msg, time, 00)
        pywhatkit.showHistory()
        pywhatkit.shutdown(3000000000)
        # pywhatkit.sendwhatmsg("+919876543210", "This is a message", 15, 00)

    # Convert text to handwritten format
    elif 'convert' in command:
        text = command.replace('convert', '')
        pywhatkit.text_to_handwriting(text, rgb=[0, 0, 0])

    # Perform google search
    elif 'search' in command:
        key = command.replace('search', '')
        pywhatkit.search("key")

    elif 'wikipedia' in command:
        person = command.replace('wikipedia', '')
        talk("How many pages do you want to read")
        num_pages = int(input())
        # talk("In which language do you want to read")
        # l = input()
        # wikipedia.set_lang(l)
        info = wikipedia.summary(person, num_pages)
        print(info)
        talk(info)

    elif 'can you work for me' in command:
        talk("sorry, I have headache. Please do your work")

    elif 'are you single' in command:
        talk("I am in relationshhip with wifi")

    elif 'joke' in command:
        talk(pyjokes.get_joke())
        talk("sorry for the lamest joke")

    elif 'open google browser' in command:
        try:
            urL = 'https://www.google.com'
            chrome_path = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
            webbrowser.register('chrome', None,
                                webbrowser.BackgroundBrowser(chrome_path))
            webbrowser.get('chrome').open_new_tab(urL)
            talk("Successfully opened chrome its upto you to search")
        except:
            webbrowser.Error

    elif 'google search' in command:
        word_to_search = command.replace('google search', '')
        response = GoogleSearch().search(word_to_search)
        print(response)
        for result in response.results:
            print("Title: " + result.title)
            talk("You can look for the following titles  " + result.title)

    elif 'weather' in command:
        # base URL
        BASE_URL = "https://api.openweathermap.org/data/2.5/weather?"
        talk("Which city weather are you looking for")
        try:
            with sr.Microphone() as source:
                print('listening weather...')
                city_voice = listener.listen(source)
                city = listener.recognize_google(city_voice)
                # city = '\"'+city.lower()+'\"'

                print(city)
                # city="bangalore"
                # API key API_KEY = "Your API Key"
                API_KEY = "b5a362ef1dc8e16c673dd5049aa98d8f"
                # upadting the URL
                URL = BASE_URL + "q=" + city + "&appid=" + API_KEY
                # HTTP request
                response = requests.get(URL)
                # checking the status code of the request
                if response.status_code == 200:
                    # getting data in the json format
                    data = response.json()
                    # getting the main dict block
                    main = data['main']
                    # getting temperature
                    temperature = main['temp']
                    # getting the humidity
                    humidity = main['humidity']
                    # getting the pressure
                    pressure = main['pressure']
                    # weather report
                    report = data['weather']
                    print(f"{CITY:-^30}")
                    print(f"Temperature: {temperature}")
                    print(f"Humidity: {humidity}")
                    print(f"Pressure: {pressure}")
                    print(f"Weather Report: {report[0]['description']}")
                    talk("Temperature in " + city + " is " + temperature +
                         " humidity is " + humidity + " pressure is " +
                         pressure + " and your final weather report" + report)
                else:
                    # showing the error message
                    print("Error in the HTTP request")
                    talk("Error in the HTTP request")
        except:
            talk("Hmmmmm, it looks like there is something wrong")

    elif 'news' in command:
        try:
            googlenews = GoogleNews()
            googlenews.set_lang('en')
            # googlenews.set_period('7d')
            # googlenews.set_time_range('02/01/2020', '02/28/2020')
            googlenews.set_encode('utf-8')

            talk("What news are you looking for")
            try:
                with sr.Microphone() as source:
                    print('listening news ...')
                    news_voice = listener.listen(source)
                    news_input = listener.recognize_google(news_voice)
                    news_input = news_input.lower()
                    print(news_input)
                    googlenews.get_news(news_input)
                    googlenews.search(news_input)
                    googlenews.get_page(2)
                    result = googlenews.page_at(2)
                    news = googlenews.get_texts()
                    print(news)
                    talk(news)
            except:
                print("Error")
                talk("Error in reading input")

        except:
            print("No news")
            talk(" I couldn't find any news on this day")

    elif 'play book' or 'read pdf' in command:
        talk("Which pdf do you want me to read")
        book_input = input()
        print(book_input)
        book = open(book_input, 'rb')
        # create pdfReader object
        pdfReader = PyPDF2.PdfFileReader(book)
        # count the total pages
        total_pages = pdfReader.numPages
        total_pages = str(total_pages)
        print("Total number of pages " + total_pages)
        talk("Total number of pages " + total_pages)
        # initialise speaker object
        # speaker = pyttsx3.init()
        # talk("Enter your starting page")
        # start_page = int(input())
        talk(
            " here are the options for you, you can press 1 to  Play a single page     2 to   Play between start and end points  and  3 to  Play the entire book "
        )
        talk("Enter your choice")
        choice = int(input())
        if (choice == 1):
            talk("Enter index number")
            page = int(input())
            page = pdfReader.getPage(page)
            text = page.extractText()
            talk(text)
            # speaker.say(text)
            # speaker.runAndWait()
        elif (choice == 2):
            talk("Enter starting page number")
            start_page = int(input())
            talk("Enter ending page number")
            end_page = int(input())
            for page in range(start_page + 1, end_page):
                page = pdfReader.getPage(start_page + 1)
                text = page.extractText()
                talk(text)
                # speaker.say(text)
                # speaker.runAndWait()
        elif (choice == 3):
            for page in range(total_pages + 1):
                page = pdfReader.getPage(page)
                text = page.extractText()
                talk(text)
                # speaker.say(text)
                # speaker.runAndWait()
        else:
            talk("Haha!! Please enter valid choice")
    else:
        talk(
            "Hiii Rashika, I am so bored can you please give me some proper commands"
        )
コード例 #7
0
ファイル: main.py プロジェクト: saaalik/Cryptoconverter
def news_scraper(curr):
    cursor = GoogleNews('en','d')
    cursor.search(curr)
    cursor.getpage(1)
    cursor.result()
    return list(zip(cursor.get_texts(),cursor.get_links()))
コード例 #8
0
from GoogleNews import GoogleNews

googlenews = GoogleNews()
googlenews = GoogleNews(lang='en')

googlenews.get_news('APPLE')
googlenews.search('APPLE')
googlenews.get_page(1)

googlenews.result()
googlenews.get_texts()