Created
August 31, 2013 00:11
-
-
Save dpenfoldbrown/6395407 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Do this to update URL documents (assuming you already have url_dic and all other lists and dicts) | |
for user in collection.find(): | |
for tweet in user['tweets']: | |
urls = tweet['urls'] | |
for url in urls: | |
url_string = url['url'] # DO NOT FORGET THIS. url is the url OBJECT, not the url string | |
if url_string in short_urls: | |
long_url = url_dic[url_string] | |
else: | |
long_url = url_string | |
domain = get_url_domain(url_string) | |
affiliation = get_url_affilation(url_string) | |
url['resolved_url'] = long_url | |
url['domain'] = domain | |
url['affiliation'] = affiliation | |
collection.update( | |
{"id": user['id'], "tweets.id": tweet['id']}, | |
{"$set": {"tweets.$.urls": urls}} | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment