Optimize follower/following handling, print changes when running filler.py
This commit is contained in:
parent
0a4de77aae
commit
f87ad68b8b
1 changed files with 26 additions and 6 deletions
32
filler.py
32
filler.py
|
@ -54,38 +54,58 @@ def getMessages(db=dbtools.dbHelper(), two=twitools.twObject()):
|
||||||
|
|
||||||
def getFollowers(db=dbtools.dbHelper(), two=twitools.twObject()):
|
def getFollowers(db=dbtools.dbHelper(), two=twitools.twObject()):
|
||||||
current = db.getFollowers()
|
current = db.getFollowers()
|
||||||
new = twitools.getNamesByIDs(twitools.getFollowerIDs())
|
new = list(twitools.getNamesByIDs(twitools.getFollowerIDs()))
|
||||||
|
gained = 0
|
||||||
|
lost = 0
|
||||||
|
|
||||||
|
if len(new) == 0:
|
||||||
|
print("Something went wrong here. -.-")
|
||||||
|
return 0,0
|
||||||
|
|
||||||
for follower in new:
|
for follower in new:
|
||||||
if follower not in current:
|
if follower not in current:
|
||||||
db.executeQuery("INSERT INTO followers VALUES('%s', %i, NULL)" % (follower, int(time.time())))
|
db.executeQuery("INSERT INTO followers VALUES('%s', %i, NULL)" % (follower, int(time.time())))
|
||||||
|
print("New follower: %s" % follower)
|
||||||
|
gained += 1
|
||||||
|
|
||||||
for follower in current:
|
for follower in current:
|
||||||
if follower not in new:
|
if follower not in new:
|
||||||
db.executeQuery("UPDATE followers SET `until` = %i WHERE `id` = '%s' AND `until` IS NULL" % (int(time.time()), follower))
|
db.executeQuery("UPDATE followers SET `until` = %i WHERE `id` = '%s' AND `until` IS NULL" % (int(time.time()), follower))
|
||||||
|
print("Lost follower: %s" % follower)
|
||||||
|
lost += 1
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
return gained, lost
|
||||||
|
|
||||||
def getFollowing(db=dbtools.dbHelper(), two=twitools.twObject()):
|
def getFollowing(db=dbtools.dbHelper(), two=twitools.twObject()):
|
||||||
current = db.getFollowing()
|
current = db.getFollowing()
|
||||||
new = twitools.getNamesByIDs(twitools.getFollowingIDs())
|
new = list(twitools.getNamesByIDs(twitools.getFollowingIDs()))
|
||||||
|
gained = 0
|
||||||
|
lost = 0
|
||||||
|
|
||||||
for following in new:
|
for following in new:
|
||||||
if following not in current:
|
if following not in current:
|
||||||
db.executeQuery("INSERT INTO following VALUES('%s', %i, NULL)" % (following, int(time.time())))
|
db.executeQuery("INSERT INTO following VALUES('%s', %i, NULL)" % (following, int(time.time())))
|
||||||
|
print("You started following: %s" % following)
|
||||||
|
gained += 1
|
||||||
|
|
||||||
for following in current:
|
for following in current:
|
||||||
if following not in new:
|
if following not in new:
|
||||||
db.executeQuery("UPDATE following SET `until` = %i WHERE `id` = %s AND `until` IS NULL" % (int(time.time()), following))
|
db.executeQuery("UPDATE following SET `until` = %i WHERE `id` = %s AND `until` IS NULL" % (int(time.time()), following))
|
||||||
|
print("You no longer follow: %s" % following)
|
||||||
|
lost += 1
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
return gained, lost
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
count, last, first = getTweets()
|
count, last, first = getTweets()
|
||||||
print("Stored %i tweets after %i until %i." % (count, first, last))
|
print("Stored %i tweets after %i until %i." % (count, first, last))
|
||||||
count, last, first = getMessages()
|
count, last, first = getMessages()
|
||||||
print("Stored %i messages after %i until %i." % (count, first, last))
|
print("Stored %i messages after %i until %i." % (count, first, last))
|
||||||
getFollowers()
|
gained, lost = getFollowers()
|
||||||
print("Processed followers.")
|
print("Gained %i followers, lost %i." % (gained, lost))
|
||||||
getFollowing()
|
gained, lost = getFollowing()
|
||||||
print("Processed following.")
|
print("Started following %i, stopped following %i." % (gained, lost))
|
||||||
|
|
Loading…
Reference in a new issue