Optimize follower/following handling, print changes when running filler.py
This commit is contained in:
parent
c2d9547dcd
commit
f72a51fbee
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()):
|
||||
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:
|
||||
if follower not in current:
|
||||
db.executeQuery("INSERT INTO followers VALUES('%s', %i, NULL)" % (follower, int(time.time())))
|
||||
print("New follower: %s" % follower)
|
||||
gained += 1
|
||||
|
||||
for follower in current:
|
||||
if follower not in new:
|
||||
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()
|
||||
|
||||
return gained, lost
|
||||
|
||||
def getFollowing(db=dbtools.dbHelper(), two=twitools.twObject()):
|
||||
current = db.getFollowing()
|
||||
new = twitools.getNamesByIDs(twitools.getFollowingIDs())
|
||||
new = list(twitools.getNamesByIDs(twitools.getFollowingIDs()))
|
||||
gained = 0
|
||||
lost = 0
|
||||
|
||||
for following in new:
|
||||
if following not in current:
|
||||
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:
|
||||
if following not in new:
|
||||
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()
|
||||
|
||||
return gained, lost
|
||||
|
||||
if __name__ == "__main__":
|
||||
count, last, first = getTweets()
|
||||
print("Stored %i tweets after %i until %i." % (count, first, last))
|
||||
count, last, first = getMessages()
|
||||
print("Stored %i messages after %i until %i." % (count, first, last))
|
||||
getFollowers()
|
||||
print("Processed followers.")
|
||||
getFollowing()
|
||||
print("Processed following.")
|
||||
gained, lost = getFollowers()
|
||||
print("Gained %i followers, lost %i." % (gained, lost))
|
||||
gained, lost = getFollowing()
|
||||
print("Started following %i, stopped following %i." % (gained, lost))
|
||||
|
|
Loading…
Reference in a new issue