My Projects

 8. Today's News

import requests
from ShoutOut import speak

def getNews() -> str:
    queries = input("What type of news you are interested in? : ")
    api_key = "b08c708b964844338697e322498f065b"
    url = f"https://newsapi.org/v2/everything?q={queries}&from=2024-07-18&sortBy=publishedAt&apiKey="+api_key
    news = requests.get(url).json()
    articles = news["articles"]
    # myarticle = []
    mynews = ""
    i = 0
    for num,article in enumerate(articles):
        # myarticle.append(article["title"])
        print(f"{i+1}: "+article["title"])
        speak(f"{i+1}: "+article["title"])
        print("Description:\n"+str(article["description"]))
        speak("Description:\n"+str(article["description"]))
        print("content:\n"+str(article["content"]))
        speak("content:\n"+str(article["content"]))
        print("-"*183)
        # myarticle.append(article["title"])
        i+=1
        if num == 51:
            break

    # for i in range(1):
    #     mynews+=f"{i+1}: "+myarticle[i] + "\n"+"-"*10
    # return mynews
(getNews())

Comments

Popular posts from this blog

Advance Calculator Made For Mathematicans and Coders | Made with Python

My Projects

Functions Module