Commit 7cf19d7a authored by Francesco Poldi's avatar Francesco Poldi

Fixed geo for user and tweet, updated tweet.place

parent 947c60a7
...@@ -37,6 +37,7 @@ PUT twinttweets ...@@ -37,6 +37,7 @@ PUT twinttweets
"quote_url": {"type": "text"}, "quote_url": {"type": "text"},
"search": {"type": "text"}, "search": {"type": "text"},
"near": {"type": "text"}, "near": {"type": "text"},
"geo_near": {"type": "geo_point"},
"geo_tweet": {"type": "geo_point"} "geo_tweet": {"type": "geo_point"}
} }
} }
......
...@@ -17,7 +17,10 @@ class RecycleObject(object): ...@@ -17,7 +17,10 @@ class RecycleObject(object):
def getLocation(place): def getLocation(place):
location = geolocator.geocode(place) location = geolocator.geocode(place)
if location:
return {"lat": location.latitude, "lon": location.longitude} return {"lat": location.latitude, "lon": location.longitude}
else:
return {}
def handleIndexResponse(response): def handleIndexResponse(response):
try: try:
...@@ -76,6 +79,7 @@ def createIndex(config, instance, **scope): ...@@ -76,6 +79,7 @@ def createIndex(config, instance, **scope):
"quote_url": {"type": "text"}, "quote_url": {"type": "text"},
"search": {"type": "text"}, "search": {"type": "text"},
"near": {"type": "text"}, "near": {"type": "text"},
"geo_near": {"type": "geopoint"},
"geo_tweet": {"type": "geopoint"} "geo_tweet": {"type": "geopoint"}
} }
} }
...@@ -226,7 +230,9 @@ def Tweet(Tweet, config): ...@@ -226,7 +230,9 @@ def Tweet(Tweet, config):
} }
} }
if config.Near: if config.Near:
j_data["_source"].update({"geo_tweet": getLocation(config.Near)}) j_data["_source"].update({"geo_near": getLocation(config.Near)})
if Tweet.place:
j_data["_source"].update({"geo_tweet": getLocation(Tweet.place)})
actions.append(j_data) actions.append(j_data)
es = Elasticsearch(config.Elasticsearch) es = Elasticsearch(config.Elasticsearch)
...@@ -290,7 +296,9 @@ def UserProfile(user, config): ...@@ -290,7 +296,9 @@ def UserProfile(user, config):
} }
} }
if config.Location: if config.Location:
j_data["_source"].update({"geo_user": getLocation(config.Location)}) _loc = getLocation(user.location)
if _loc:
j_data["_source"].update({"geo_user": _loc})
actions.append(j_data) actions.append(j_data)
es = Elasticsearch(config.Elasticsearch) es = Elasticsearch(config.Elasticsearch)
......
...@@ -129,7 +129,7 @@ def Tweet(tw, location, config): ...@@ -129,7 +129,7 @@ def Tweet(tw, location, config):
t.username = tw["data-screen-name"] t.username = tw["data-screen-name"]
t.name = tw["data-name"] t.name = tw["data-name"]
t.profile_image_url = tw.find("img", "js-action-profile-avatar").get('src').replace("_bigger","") t.profile_image_url = tw.find("img", "js-action-profile-avatar").get('src').replace("_bigger","")
t.place = tw.find("a","js-geo-pivot-link").text.strip() if tw.find("a","js-geo-pivot-link") else None t.place = tw.find("a",{'class':"u-textUserColor js-nav js-geo-pivot-link"}).text.strip() if tw.find("a","js-geo-pivot-link") else None
t.timezone = strftime("%Z", localtime()) t.timezone = strftime("%Z", localtime())
for img in tw.findAll("img", "Emoji Emoji--forText"): for img in tw.findAll("img", "Emoji Emoji--forText"):
img.replaceWith(img["alt"]) img.replaceWith(img["alt"])
......
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