-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet.py
29 lines (27 loc) · 971 Bytes
/
tweet.py
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
from os import link
import tweepy
import config
import json
from urllib.request import urlopen
client = tweepy.Client(
consumer_key=config.api_key,
consumer_secret=config.api_key_secrets,
access_token=config.access_token,
access_token_secret=config.access_token_secret
)
try:
print("Authentication OK")
url = "https://clist.by/api/v2/contest/?format=json&username=muhammed-mizaj&api_key=eec5f945658a9e7b937ff881dd102967eca28e0a"
response = urlopen(url)
data_json = json.loads(response.read())
sample_data=data_json["objects"]
data = sorted(sample_data, key=lambda k: k['start'], reverse=True)
for i in range(0,15):
t=data[i]
link=t['href']
start_date=t['start']
end_date=t['end']
msg=t['event']
client.create_tweet(text="Hey there,\n"+str(msg)+" is happening from "+str(start_date)+" to "+str(end_date)+"! \Visit :"+str(link))
except Exception as error:
print(error)