def take_action(self, parsed_args): usernames = get_handles() # usernames = usernames[:2] # DEBUG userData = lookup_users(usernames) usernames = userData.keys() usernames = sorted(usernames, key=lambda n: userData[n]['followers_count'])[::-1] # TODO accept argument for filename self._write_dataset(userData, usernames, "astrotweeters.csv")
def _get_new_handles(self): """Get user handles from the AstroBetter wiki that are not yet in MonogoDB. The implementation is a bit messy here; can we run fewer mongodb lookups? """ allHandles = get_handles() newHandles = [] for handle in allHandles: if self.c.find({'screen_name': handle}).count() == 0: newHandles.append(handle) return newHandles