Skip to content

Instantly share code, notes, and snippets.

@vim13
Last active November 15, 2017 12:26
Show Gist options
  • Save vim13/a39b40312f4ec8a7cf94945ca02cfaa6 to your computer and use it in GitHub Desktop.
Save vim13/a39b40312f4ec8a7cf94945ca02cfaa6 to your computer and use it in GitHub Desktop.
kenmo lot
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import tweepy
import random
import time
def readFile(path):
opened_file = open(path, 'r')
logs = []
for line in opened_file:
logs.append(line[:-1])
opened_file.close()
return logs
def writeFile(path,ids):
opend_file = open(path, 'w')
for x in ids:
opend_file.write(str(x)+'\n')
opend_file.close()
def checkId(ids,logs):
new = []
for x in ids:
if x not in logs:
new.append(x)
return new
def lot(new):
for x in new:
r = random.randint(1,10)
if r == 10:
text = "@" + x.encode('utf-8') + " " + "当選おめでとうございます!"
api.update_with_media('/home/ubuntu/html/src/atari.jpg', text)
else:
text = "@" + x.encode('utf-8') + " " + "残念!またの機会をお待ちしております"
api.update_with_media('/home/ubuntu/html/src/hazure.jpg', text)
time.sleep(20)
if __name__ == '__main__':
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
path = '/home/ubuntu/python/log.txt'
status = api.retweets('')
logs = readFile(path)
ids = [tweet.user.screen_name for tweet in status]
new = checkId(ids,logs)
writeFile(path,ids)
if new:
lot(new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment