-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecretosbot.py
33 lines (30 loc) · 1.12 KB
/
decretosbot.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
30
31
32
33
import tweepy, time, sys, json
import urllib3
import urllib
from decretosv2 import connection, write_output
from datetime import date, datetime
from config import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
def maketweet():
write_output()
db=connection()
tweet=db.decretos.find({"tweet":False})
if tweet.count()!=0:
for i in tweet:
try:
api.update_status("%s %s"%(i['descripcion'][:240], i['link'].replace(" ", "%20")))
db.decretos.update_one(i, {"$set": { "tweet": True}})
except tweepy.TweepError as error:
if error.api_code != 187:
raise error
else:
tweet=db.decretos.find().sort("_id",-1).limit(5)
for i in tweet:
try:
api.update_status("%s %s"%(i['descripcion'][:240], i['link'].replace(" ","%20")))
except tweepy.TweepError as error:
if error.api_code != 187:
raise error
maketweet()