Commit 343bd2bf authored by Francesco Poldi's avatar Francesco Poldi

Added geopoint

Now we will map tweets when scraping with --near
parent 761afcf1
...@@ -36,7 +36,8 @@ PUT twinttweets ...@@ -36,7 +36,8 @@ PUT twinttweets
"quote_id_str": {"type": "text"}, "quote_id_str": {"type": "text"},
"quote_url": {"type": "text"}, "quote_url": {"type": "text"},
"search": {"type": "text"}, "search": {"type": "text"},
"near": {"type": "text"} "near": {"type": "text"},
"geo_point": {"type": "geopoint"}
} }
} }
} }
......
## TODO - Fix Weekday situation ## TODO - Fix Weekday situation
from elasticsearch import Elasticsearch, helpers from elasticsearch import Elasticsearch, helpers
from geopy.geocoders import Nominatim
from time import strftime, localtime from time import strftime, localtime
import contextlib import contextlib
import sys import sys
...@@ -8,10 +9,18 @@ _index_tweet_status = False ...@@ -8,10 +9,18 @@ _index_tweet_status = False
_index_follow_status = False _index_follow_status = False
_index_user_status = False _index_user_status = False
geolocator = Nominatim(user_agent="twint-1.2")
class RecycleObject(object): class RecycleObject(object):
def write(self, junk): pass def write(self, junk): pass
def flush(self): pass def flush(self): pass
def getLocation(place):
location = geolocator.geocode(place)
if location:
return {"lat": location.latitude, "lon": location.longitude}
return {}
def handleIndexResponse(response): def handleIndexResponse(response):
try: try:
if response["status"] == 400: if response["status"] == 400:
...@@ -171,6 +180,8 @@ def Tweet(Tweet, config): ...@@ -171,6 +180,8 @@ def Tweet(Tweet, config):
} }
day = weekdays[strftime("%A", localtime(Tweet.datetime))] day = weekdays[strftime("%A", localtime(Tweet.datetime))]
location = getLocation(config.Near)
actions = [] actions = []
dt = f"{Tweet.datestamp} {Tweet.timestamp}" dt = f"{Tweet.datestamp} {Tweet.timestamp}"
...@@ -213,7 +224,8 @@ def Tweet(Tweet, config): ...@@ -213,7 +224,8 @@ def Tweet(Tweet, config):
"quote_id_str": Tweet.quote_id_str, "quote_id_str": Tweet.quote_id_str,
"quote_url": Tweet.quote_url, "quote_url": Tweet.quote_url,
"search": str(config.Search), "search": str(config.Search),
"near": config.Near "near": config.Near,
"geo_point": location
} }
} }
actions.append(j_data) actions.append(j_data)
......
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