-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User lookup #30
base: master
Are you sure you want to change the base?
User lookup #30
Conversation
@@ -265,3 +353,54 @@ def process_twitter(self, data): | |||
"output": pred[id] | |||
} | |||
return output | |||
|
|||
|
|||
def process_twitter_batch(self, data_list, batch_size, num_workers): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function seems largely overlaps with the non-batched version. Could you call the non-batched version and then aggregate the result?
for id in id_list: | ||
# If a json file exists, we'll use that. Otherwise go get the data. | ||
try: | ||
with open("{}/{}.json".format(self.cache_dir, id), "r") as fh: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.path.join
might be better?
if len(id_list) > 0: | ||
# the twitter API handles a maximum of 100 user IDs per request. Chunk up the user | ||
# id list into batches of max 100 IDs and run them through the pipeline sequentially | ||
API_batch_size = 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be defined as a global variable for easy tracking?
@@ -193,6 +193,34 @@ def _twitter_api(self,id=None,screen_name=None): | |||
return self.process_twitter(r.json()) | |||
|
|||
|
|||
def _twitter_api_lookup(self, ids=None, batch_size=16, num_workers=4): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably could reuse/extend the twitter_api
function by extending id
to ids
?
Added a new function "infer_ids" and corresponding helper functions that uses the GET /users/loopup endpoint to request information for up to 100 user IDs at the same time.