ccarbonell / NoLaTwit

utilidades twitter para NoLaPeles
http://www.nolapeles.com
2 stars 2 forks source link

Save user statues locally so we don't hit Rate Limits un-necessarily #3

Open gubatron opened 13 years ago

gubatron commented 13 years ago

@see NLPTwitterToolbox.java line 105. try { User friend = twitter.showUser(friendId); if (friend.getStatus().getCreatedAt().before(threeMonthsAgo.getTime())) { twitter.destroyFriendship(friendId); iterator.remove(); System.out.println("@"+ SCREEN_NAME+ " unfollows inactive @" + friend.getScreenName() + " Last Tweet was on ["+friend.getStatus().getCreatedAt()+"]"); } else { System.out.println("Keeping @" + friend.getScreenName() + " for @" + SCREEN_NAME); } } catch (Exception e) {

        }

Save statuses here to a serialized file.

A simple Map<User,Status> will do the trick. We should load this file at the begginning and manipulate it as we go on. The overhead of saving it every time we actually fetch a user status from twitter is irrelevant since we run offline and this script is run maybe once a day.

Whenever the saved status is too old, then we check again to update and see if it's worth it not following this guy, otherwise, if we know he's been active, we don't need to get the latest status.

gubatron commented 13 years ago

so basically, I'd suggest replacing

User friend = twitter.showUser(friendId);

for

User friend = getSavedUserStatus(friendId);

This function would encapsulate the logic of fetching the User object from disk, or from twitter, in which case it'd also take care of saving the new status.

It'd only go to twitter once the last known status of the user is over 3 months old.

Then the function that invoked it will take care of the rest of the logic.

Also, if a user is unfollowed, we remove it from the file where we are storing user statuses.