-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewsAPI.py
More file actions
51 lines (33 loc) · 1.08 KB
/
NewsAPI.py
File metadata and controls
51 lines (33 loc) · 1.08 KB
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
48
49
50
51
import requests
import tweepy
import time
from datetime import datetime, timedelta
def GetNews():
apiKey = ''
apikeySecret = ''
accessToken = ''
accessTokenSecret = ''
oauth = tweepy.OAuthHandler(apiKey, apikeySecret)
oauth.set_access_token(accessToken, accessTokenSecret)
query_params = {
"source": "engadget",
"sortBy": "top",
"category": "technology",
"apiKey": "",
"from": datetime.today() - timedelta(days=1)
}
main_url = " https://newsapi.org/v1/articles"
res = requests.get(main_url, params=query_params)
open_page = res.json()
article = open_page["articles"]
results = []
for ar in article:
results.append(ar["title"])
tweet = (results[i]).rsplit("|")[0]
api = tweepy.API(oauth)
result = api.update_status(status = tweet )
print("Successful: ",datetime.now().strftime("%H:%M:%S")," ",tweet)
time.sleep(7200)
GetNews()
if __name__ == '__main__':
GetNews()