Last active
August 17, 2017 03:37
-
-
Save chun37/a13cc3e68791b128638d42d65a6986f5 to your computer and use it in GitHub Desktop.
TwitterのFF内の人のIDをdbにまとめる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import tweepy | |
import sqlite3 | |
import os | |
import time | |
if __name__ == "__main__": | |
auth = tweepy.OAuthHandler(CK, CS) | |
auth.set_access_token(AK, AS) | |
api = tweepy.API(auth) | |
path1 = os.path.isfile("followers.db") | |
try: | |
uu = int(time.time()) - int(os.stat("followers.db").st_mtime) | |
except: | |
uu = 114514 | |
if not path1 or uu >= 300: | |
if path1: | |
os.remove("followers.db") | |
con = sqlite3.connect("followers.db") | |
try: | |
a = con.cursor().execute("select id from followers") | |
except: | |
con.cursor().execute("create table followers(id INTEGER)") | |
for i in [followers_id for followers_id in tweepy.Cursor(api.followers_ids, id=api.me().screen_name, cursor=-1).items()]: | |
con.cursor().execute("INSERT INTO followers VALUES('%s')" % i) | |
con.commit() | |
con.close() | |
path2 = os.path.isfile("following.db") | |
try: | |
uu = int(time.time()) - int(os.stat("following.db").st_mtime) | |
except: | |
uu = 114514 | |
if uu >= 300 or not path2: | |
if path2: | |
os.remove("following.db") | |
con = sqlite3.connect("following.db") | |
try: | |
a = con.cursor().execute("select id from following") | |
except: | |
con.cursor().execute("create table following(id INTEGER)") | |
for i in [following_id for following_id in tweepy.Cursor(api.friends_ids, id=api.me().screen_name, cursor=-1).items()]: | |
con.cursor().execute("INSERT INTO following VALUES('%s')" % i) | |
con.commit() | |
con.close() | |
else: | |
print u"うんち" | |
con1 = sqlite3.connect("followers.db") | |
con2 = sqlite3.connect("following.db") | |
follower_list = [row[0] for row in con1.cursor().execute("select id from followers")] | |
follow_list = [row[0] for row in con2.cursor().execute("select id from following")] | |
con1.close() | |
con2.close() | |
t = set() | |
FFpath = os.path.isfile("FF.db") | |
try: | |
uu = int(time.time()) - int(os.stat("FF.db").st_mtime) | |
except: | |
uu = 114514 | |
if uu >= 300 or not FFpath: | |
con = sqlite3.connect("FF.db") | |
if FFpath: | |
os.remove("FF.db") | |
try: | |
a = con.cursor().execute("select id from FF") | |
except: | |
con.cursor().execute("create table FF(id INTEGER)") | |
for i in [x for x in follower_list + follow_list if x in t or t.add(x)]: | |
con.cursor().execute("INSERT INTO FF VALUES('%s')" % i) | |
con.commit() | |
con.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment