Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Counter
- from time import sleep
- import pymongo
- from geopy.exc import GeocoderTimedOut, GeocoderServiceError
- from geopy.geocoders import Nominatim
- geolocator = Nominatim()
- client = pymongo.MongoClient('130.212.214.188',27017)
- db = client.hepc_hiv_addiction_users
- collection1 = db.friends_followers_of_new_york_collection
- while(True):
- cursor1 = collection1.find({"classifier_type" : 4},no_cursor_timeout = True).sort("_id",-1)
- # cursor1 = collection1.find({"screen_name":"cleymonart"})
- for i in cursor1:
- if "geolocated_geopy_second" not in i:
- print "****************"
- print i["screen_name"]
- print "***************"
- try:
- loc = geolocator.geocode(i["location"],addressdetails=True, timeout= None)
- if loc != None:
- # print loc.raw['address']
- if "city" in loc.raw['address']:
- i["city"] = loc.raw['address']['city']
- if "state" in loc.raw['address']:
- i["state"] = loc.raw['address']['state']
- print i["state"]
- i["geolocated_geopy_second"]=1
- collection1.save(i)
- except GeocoderTimedOut as e:
- i["geolocated_geopy_second"]=1
- collection1.save(i)
- print("Error: geocode failed on input %s with message %s"%(i["location"], e.message))
- except GeocoderServiceError as e:
- print e.message
- print "sleeping"
- sleep(900)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement