Spaces:
DIVY118
/
Runtime error

File size: 787 Bytes
ad89eb2
 
 
b716d30
ad89eb2
 
c373e2a
b716d30
9c0a721
ad89eb2
 
 
 
 
 
 
 
 
 
 
 
 
b716d30
ad89eb2
 
 
 
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
import requests
from time import time as t

NEWSSS=""

def News(KEY,cache=True):
    global NEWSSS
    if NEWSSS:
        return NEWSSS, None, 0
    C = t()
    main_url = f'https://newsapi.org/v2/top-headlines?sources=techcrunch&apiKey={KEY}'
    main_page = requests.get(main_url).json()
    articles = main_page["articles"]
    head = []
    day = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"]
    for ar in articles:
        head.append(ar["title"])
    temp = []
    for i in range(len(day)):
        temp.append(f"today's {day[i]} news is: {head[i]}\n")
    result = "".join(temp)

    NEWSSS=result  # Cache the news
    return result, None, t() - C

if __name__ == "__main__":
    print(News("5b57a2e4baa74123b6db7dff6967881b"))