Commit 2a75783c authored by Francesco Poldi's avatar Francesco Poldi

Fixed timeouts for geopoints

parent 1b7bab7f
...@@ -8,6 +8,10 @@ import sys ...@@ -8,6 +8,10 @@ import sys
_index_tweet_status = False _index_tweet_status = False
_index_follow_status = False _index_follow_status = False
_index_user_status = False _index_user_status = False
_is_near_def = False
_is_location_def = False
_near = {}
_location = {}
geolocator = Nominatim(user_agent="twint-1.2") geolocator = Nominatim(user_agent="twint-1.2")
...@@ -15,9 +19,18 @@ class RecycleObject(object): ...@@ -15,9 +19,18 @@ class RecycleObject(object):
def write(self, junk): pass def write(self, junk): pass
def flush(self): pass def flush(self): pass
def getLocation(place): def getLocation(place, **options):
print("asking for " + place)
location = geolocator.geocode(place) location = geolocator.geocode(place)
if location: if location:
if options.get("near"):
global _near
_near = {"lat": location.latitude, "lon": location.longitude}
return True
elif options.get("location"):
global _location
_location = {"lat": location.latitude, "lon": location.longitude}
return True
return {"lat": location.latitude, "lon": location.longitude} return {"lat": location.latitude, "lon": location.longitude}
else: else:
return {} return {}
...@@ -173,6 +186,7 @@ def hour(datetime): ...@@ -173,6 +186,7 @@ def hour(datetime):
def Tweet(Tweet, config): def Tweet(Tweet, config):
global _index_tweet_status global _index_tweet_status
global _is_near_def
weekdays = { weekdays = {
"Monday": 1, "Monday": 1,
"Tuesday": 2, "Tuesday": 2,
...@@ -230,7 +244,10 @@ def Tweet(Tweet, config): ...@@ -230,7 +244,10 @@ def Tweet(Tweet, config):
} }
} }
if config.Near: if config.Near:
j_data["_source"].update({"geo_near": getLocation(config.Near)}) if not _is_near_def:
_is_near_def = getLocation(config.Near, near=True)
if _near:
j_data["_source"].update({"geo_near": _near})
if Tweet.place: if Tweet.place:
j_data["_source"].update({"geo_tweet": getLocation(Tweet.place)}) j_data["_source"].update({"geo_tweet": getLocation(Tweet.place)})
actions.append(j_data) actions.append(j_data)
...@@ -267,6 +284,7 @@ def Follow(user, config): ...@@ -267,6 +284,7 @@ def Follow(user, config):
def UserProfile(user, config): def UserProfile(user, config):
global _index_user_status global _index_user_status
global _is_location_def
actions = [] actions = []
j_data = { j_data = {
...@@ -296,9 +314,10 @@ def UserProfile(user, config): ...@@ -296,9 +314,10 @@ def UserProfile(user, config):
} }
} }
if config.Location: if config.Location:
_loc = getLocation(user.location) if not _is_location_def:
if _loc: _is_location_def = getLocation(user.location, location=True)
j_data["_source"].update({"geo_user": _loc}) if _location:
j_data["_source"].update({"geo_user": _location})
actions.append(j_data) actions.append(j_data)
es = Elasticsearch(config.Elasticsearch) es = Elasticsearch(config.Elasticsearch)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment