Advertisement
Guest User

hashtag user mentions url

a guest
Mar 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import pymongo
  2. client = pymongo.MongoClient('130.212.214.188',27017)
  3. db = client.hepc_hiv_addiction_users
  4. collection = db.new_york_new
  5. collection1 = db.hashtags_and_user_mentions_new_york_new
  6. cursor = collection.find(no_cursor_timeout =True)
  7.  
  8. c=0
  9. for i in cursor.sort("_id",-1):
  10. user_hashtags = {}
  11. user_user_mentions = {}
  12. user_urls = {}
  13. if i["tweets"] != None:
  14. tweets = i["tweets"]
  15. for t in tweets:
  16. for h in t["hashtags"]:
  17. t_hash = h["text"].lower()
  18. if t_hash in user_hashtags:
  19. user_hashtags[t_hash] = user_hashtags[t_hash] + 1
  20. else:
  21. user_hashtags[t_hash] = 1
  22.  
  23. for u in t["user_mentions"]:
  24. # print u["screen_name"]
  25. t_user = u["screen_name"]
  26. if t_user in user_user_mentions:
  27. user_user_mentions[t_user] = user_user_mentions[t_user] + 1
  28. else:
  29. user_user_mentions[t_user] = 1
  30.  
  31.  
  32. for ur in t["urls"]:
  33. t_url = ur["expanded_url"].replace(".","*")
  34. if t_url in user_urls:
  35. user_urls[t_url] = user_urls[t_url] + 1
  36. else:
  37. user_urls[t_url] = 1
  38.  
  39. i["user_hashtags"]= user_hashtags
  40. i["user_mentions"]= user_user_mentions
  41. i["user_urls"] = user_urls
  42. collection.save(i)
  43. c=c+1
  44. print c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement