Skip to content

Instantly share code, notes, and snippets.

@dpenfoldbrown
Created August 31, 2013 00:11
Show Gist options
  • Save dpenfoldbrown/6395407 to your computer and use it in GitHub Desktop.
Save dpenfoldbrown/6395407 to your computer and use it in GitHub Desktop.
# 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