Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymongo
- client = pymongo.MongoClient('130.212.214.188',27017)
- db = client.hepc_hiv_addiction_users
- collection = db.new_york_new
- collection1 = db.hashtags_and_user_mentions_new_york_new
- cursor = collection.find(no_cursor_timeout =True)
- c=0
- for i in cursor.sort("_id",-1):
- user_hashtags = {}
- user_user_mentions = {}
- user_urls = {}
- if i["tweets"] != None:
- tweets = i["tweets"]
- for t in tweets:
- for h in t["hashtags"]:
- t_hash = h["text"].lower()
- if t_hash in user_hashtags:
- user_hashtags[t_hash] = user_hashtags[t_hash] + 1
- else:
- user_hashtags[t_hash] = 1
- for u in t["user_mentions"]:
- # print u["screen_name"]
- t_user = u["screen_name"]
- if t_user in user_user_mentions:
- user_user_mentions[t_user] = user_user_mentions[t_user] + 1
- else:
- user_user_mentions[t_user] = 1
- for ur in t["urls"]:
- t_url = ur["expanded_url"].replace(".","*")
- if t_url in user_urls:
- user_urls[t_url] = user_urls[t_url] + 1
- else:
- user_urls[t_url] = 1
- i["user_hashtags"]= user_hashtags
- i["user_mentions"]= user_user_mentions
- i["user_urls"] = user_urls
- collection.save(i)
- c=c+1
- print c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement