Skip to content

User lookup#30

Open
JanaLasser wants to merge 2 commits intoeuagendas:masterfrom
JanaLasser:user_lookup
Open

User lookup#30
JanaLasser wants to merge 2 commits intoeuagendas:masterfrom
JanaLasser:user_lookup

Conversation

@JanaLasser
Copy link
Copy Markdown

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.

return output


def process_twitter_batch(self, data_list, batch_size, num_workers):
Copy link
Copy Markdown
Member

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:
Copy link
Copy Markdown
Member

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
Copy link
Copy Markdown
Member

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?

return self.process_twitter(r.json())


def _twitter_api_lookup(self, ids=None, batch_size=16, num_workers=4):
Copy link
Copy Markdown
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants