Merge pull request #4 from RandomisedName/БазовыйОтвет

Retweet
This commit is contained in:
2017-05-16 17:52:10 +03:00
committed by GitHub
2 changed files with 26 additions and 4 deletions

13
main.py
View File

@@ -9,6 +9,8 @@ import random
import filecmp
import shutil
from check import *
from retweet import *
import authorization
import PIL
@@ -39,18 +41,21 @@ def main():
if (filecmp.cmp(dir+'img.jpg', dir+'imgold.jpg') == False) and (filecmp.cmp(dir+'img.jpg', dir+'nla1.jpg') == False) and (filecmp.cmp(dir+'img.jpg', dir+'nla2.jpg') == False):
break
string = ''
tweet_text = ''
data = authorization.app.tag_urls(['https://imgur.com/'+id+'.jpg'])
i=0
for i in range(5):
string = string+'#'+data['outputs'][0]['data']['concepts'][i]['name'].replace(" ", "")+" "
tweet_text = tweet_text+'#'+data['outputs'][0]['data']['concepts'][i]['name'].replace(" ", "")+" "
tweetimg = open(dir+'img.jpg')
authorization.twitter.update_status_with_media(status = string, media = tweetimg)
authorization.twitter.update_status_with_media(status = tweet_text, media = tweetimg)
log_str = "https://imgur.com/"+id+".jpg "+string+"\n"
log_str = "https://imgur.com/"+id+".jpg "+tweet_text+"\n"
log_file=open('log_file.txt', 'a')
log_file.write(log_str)
log_file.close()
print log_str,
retweet()
time.sleep (60*30)

17
retweet.py Normal file
View File

@@ -0,0 +1,17 @@
from twython import Twython, TwythonError
import authorization
def retweet(): #retweet tweets with a set hashtag
search_results = authorization.twitter.search(q="#TwitterShitter", count=5)
try:
for tweet in search_results["statuses"]:
authorization.twitter.retweet(id = tweet["id_str"])
log_str = "retweeted "+tweet["id_str"]
log_file=open('log_file.txt', 'a')
log_file.write(log_str)
log_file.close()
print log_str,
except TwythonError as e:
print e
return