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"}
} }
} }
......
...@@ -90,7 +90,7 @@ def ForceNewTorIdentity(config): ...@@ -90,7 +90,7 @@ def ForceNewTorIdentity(config):
except Exception as e: except Exception as e:
sys.stderr.write('Error connecting to Tor control port: {}\n'.format(repr(e))) sys.stderr.write('Error connecting to Tor control port: {}\n'.format(repr(e)))
sys.stderr.write('If you want to rotate Tor ports automatically - enable Tor control port\n') sys.stderr.write('If you want to rotate Tor ports automatically - enable Tor control port\n')
async def Request(url, connector=None, params=[], headers=[]): async def Request(url, connector=None, params=[], headers=[]):
#loggin.info("[<] " + str(datetime.now()) + ':: get+Request') #loggin.info("[<] " + str(datetime.now()) + ':: get+Request')
if connector: if connector:
......
...@@ -68,7 +68,7 @@ class Twint: ...@@ -68,7 +68,7 @@ class Twint:
continue continue
else: else:
print(str(e)) print(str(e))
break break
except Exception as e: except Exception as e:
# Sometimes Twitter says there is no data. But it's a lie. # Sometimes Twitter says there is no data. But it's a lie.
consecutive_errors_count += 1 consecutive_errors_count += 1
......
...@@ -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)
return {"lat": location.latitude, "lon": location.longitude} if location:
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"])
...@@ -155,4 +155,4 @@ def Tweet(tw, location, config): ...@@ -155,4 +155,4 @@ def Tweet(tw, location, config):
t.in_reply_to_status_id_str = "" t.in_reply_to_status_id_str = ""
t.in_reply_to_user_id = 0 t.in_reply_to_user_id = 0
t.in_reply_to_user_id_str = "" t.in_reply_to_user_id_str = ""
return t return t
\ No newline at end of file
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