-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter.py
More file actions
50 lines (40 loc) · 1.56 KB
/
twitter.py
File metadata and controls
50 lines (40 loc) · 1.56 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Twitter用
import tweepy
import time
import numpy as np
import sqlite3
def db_connect():
"""データベースに接続してtoken情報を取得する"""
db = sqlite3.connect('../token.db')
db_data = db.cursor()
db_data= db_data.execute("select * from ttoken;")
db_ret = db_data.fetchall()
db.close()
return db_ret
acctoken=db_connect()#データベース処理
time_list = np.random.randint(300,1000,size=100)#ランダム
#ツイート内容...そのうちデータベースかcsvに移行
twitt_list = ["やべー","かっこいい","おなか減った","やったー","あ","コート返してほしい...",
"おいしそう","美味","パケット...","数学...","fedora","なる","あのネクタイほしい",
"アニメ見よ...","眠たい...","眠い","マックに行きたい","楽しい!!","オフ","オン"]
#twitter
consumer_key=acctoken[0][0]
consumer_secret= acctoken[0][1]
token= acctoken[0][2]
tokensecret= acctoken[0][3]
#auth認証
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token, tokensecret)
api = tweepy.API(auth)
#ツイート
for i in range(10):
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token, tokensecret)
api = tweepy.API(auth)
randomv = np.random.choice(time_list)
random_comment = np.random.choice(twitt_list)
print(str(randomv)+"秒停止")
api.update_status(random_comment)
time.sleep(randomv)