def AWS_handler(event, context): pardir=os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(pardir) auth=account.Initialize() api = tweepy.API(auth) twitter_id=account.id() # ツイートのみ # api.update_status(status="test by tweepy")#status #原稿のロードのためにclass継承 from manuscript.py tweet=manuscript.Manuscript() # 指定された写真の範囲からランダムに選ぶ import random min=1 max=tweet.max_num()#写真と記事の割り振り番号の最大値 num=random.randint(min,max) num_padded='{0:03d}'.format(num)#ゼロパディング:0で3桁左詰する。 example 1→001 # # #一番から順にツイートする機能 # # tweetnum=outputtext.Tweet_num() # # num=tweetnum.load()#今ツイートする番号を取得 # # tweetnum.write(num+1)#次のツイート番号を返却 # # num_padded='{0:03d}'.format(num) # 画像付きツイート pic="/Users/kenkato/Pictures/forbot/"+str(num_padded)+".jpg" #画像を投稿するなら画像のパス status=tweet.manus(num-1)+"\ninstagram.com/ken_4y4"#ツイート内容 api.update_with_media(filename=pic,status=status) print("tweet No:"+str(num)) return "tweet.py works"
def AWS_handler(event, context): pardir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(pardir) auth = account.Initialize() api = tweepy.API(auth) twitter_id = account.id() #get timeline public_tweets = api.home_timeline(count=5) # print(public_tweets[0]) print("取得ツイート数:" + str(len(public_tweets))) for tweet in public_tweets: #複数形と単数形でしか対応しない print("\n" + tweet.text) print("\nfavorite count:" + str(tweet.favorite_count)) print("retweet count:" + str(tweet.retweet_count)) if 0 < (int(tweet.favorite_count) + int(tweet.retweet_count) * 2) < 5: if tweet.favorited == False: print("favorite it!") #favorite api.create_favorite(tweet.id) pass else: print("I already favorited it") else: print("This tweet doesn't suit your rules") return "favorite.py success"
def AWS_handler(event, context): pardir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(pardir) auth = account.Initialize() api = tweepy.API(auth) twitter_id = account.id() othertimelines = api.user_timeline("togetter_jp") for tweet in othertimelines: print(tweet.text) return "othertimeline.py works"
def main(): auth = account.Initialize() api = tweepy.API(auth) twitter_id=account.id() public_tweets = api.home_timeline(count=10) for tweet in public_tweets: print("\n"+tweet.user.name) # print(tweet.user.screen_name)#@以下のID print(tweet.text) print(text_to_noun(tweet.text))
def AWS_handler(event, context): pardir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(pardir) #account情報ロード auth = account.Initialize() api = tweepy.API(auth) twitter_id = account.id() public_tweets = api.home_timeline() for tweet in public_tweets: print(tweet.text) return "timeline.py works"
def AWS_handler(event, context): pardir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(pardir) auth = account.Initialize() api = tweepy.API(auth) twitter_id = account.id() count = 10 #データ取得人数 # random num = random.randint(0, count - 1) #フォロー先ロード following_ids = api.friends_ids(twitter_id, count=10) following_date = api.lookup_users(user_ids=following_ids) for u in following_date: print(u.screen_name) print(num) #フォロー先のフォロワーを取得 # followers=t.followers.list(screen_name=following_twitter_id[num],count=count) followers = api.followers_ids(id=following_ids[num], count=count) followers2 = api.lookup_users(user_ids=followers) #random # print(followers) for u in followers2: print(u.screen_name) # print(u.id) # print(u.follow_request_sent) # print(u._json["following"]) #ランダムもう一回 following_id = [] for i in range(3): num1 = random.randint(0, count - 1) print(num1) following_id.append(followers[num1]) print(following_id) following_date = api.lookup_users(user_ids=following_id) for u in following_date: # #follow-part if u.follow_request_sent or u._json["following"]: print("I already follow " + str(u.screen_name)) elif u.screen_name == twitter_id: print("You can't follow yourself!!") else: api.create_friendship(u.screen_name) print("success!! you followed " + str(u.screen_name) + "!!") return "new_following.py works"
def AWS_handler(event, context): pardir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(pardir) auth = account.Initialize() api = tweepy.API(auth) twitter_id = account.id() #最近のフォロワーからその人のtweetやid情報取得 # followers=api.followers_ids(screen_name=twitter_id)#全てのフォロワーidを取得 # friends=api.friends_ids(twitter_id)#フォローしている人のidを取得 followers = api.followers_ids(twitter_id) friends = api.friends_ids(twitter_id) # following # for follower in followers['users']: # name=follower['screen_name'] # print(name) # if follower['following'] or follower['follow_request_sent']:#if follow that follower or sent follow request, pass that follower # pass # else:#フォローしてないときはフォロー申請 if i dont follow that follower, request following # # t.friendships.create(screen_name=name) # pass # print(followers) #フォロワーからフォローしている人を引く set_followback = set(followers) - set(friends) list_followback = list(set_followback) #フォローバックすべき一覧 print("list_followback,count=", len(list_followback)) #follow back-part #num of follow once count = 10 for follownum in range(count): # follow-part try: api.create_friendship(list_followback[follownum]) print("success follow!" + str(list_followback[follownum])) except tweepy.error.TweepError: print("Error: You've already requested to follow") return "followback.py works"
def AWS_handler(event, context): auth = account.Initialize() api = tweepy.API(auth) twitter_id = account.id() # ツイートのみ # api.update_status(status="test by tweepy")#status #原稿のロードのためにclass継承 from manuscript.py tweet = manuscript.Manuscript() # 指定された写真の範囲からランダムに選ぶ min = 1 max = tweet.max_num() #写真と記事の割り振り番号の最大値 num = random.randint(min, max) num_padded = '{0:03d}'.format(num) #ゼロパディング:0で3桁左詰する。 example 1→001 # # #一番から順にツイートする機能 # # tweetnum=outputtext.Tweet_num() # # num=tweetnum.load()#今ツイートする番号を取得 # # tweetnum.write(num+1)#次のツイート番号を返却 # # num_padded='{0:03d}'.format(num) s3 = boto3.resource("s3") # boto3.DEFAULT_SESSION bucket = s3.Bucket("photofortweet") # obj=bucket.Object("forbot/001.jpg") bucket.download_file("forbot/" + str(num_padded) + ".jpg", "/tmp/001.jpg") # 画像付きツイート pic = "/tmp/001.jpg" #画像を投稿するなら画像のパス status = tweet.manus(num - 1) + "\ninstagram.com/ken_4y4" #ツイート内容 api.update_with_media(filename=pic, status=status) print("tweet No:" + str(num)) return "its work"
#encoding:utf-8 # 参照url #https://syncer.jp/Web/API/Twitter/REST_API/POST/statuses/update/ #http://ailaby.com/twitter_api/ import certifi import tweepy #親ディレクトリにあるアカウント情報へのパス import sys, os pardir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(pardir) #account情報をaccount.pyからロード from account import account #load account auth = account.Initialize() api = tweepy.API(auth) twitter_id = account.id() #get timeline public_tweets = api.home_timeline(count=5) # print(public_tweets[0]) print("取得ツイート数:" + str(len(public_tweets))) for tweet in public_tweets: #複数形と単数形でしか対応しない print("\n" + tweet.text) print("\nfavorite count:" + str(tweet.favorite_count)) print("retweet count:" + str(tweet.retweet_count)) if 0 < (int(tweet.favorite_count) + int(tweet.retweet_count) * 2) < 5: if tweet.favorited == False: print("favorite it!") #favorite