Commit 69515034 authored by Francesco Poldi's avatar Francesco Poldi

Added source field

parent 88141bc4
...@@ -120,6 +120,7 @@ def initialize(args): ...@@ -120,6 +120,7 @@ def initialize(args):
c.Min_retweets = args.min_retweets c.Min_retweets = args.min_retweets
c.Min_replies = args.min_replies c.Min_replies = args.min_replies
c.Links = args.links c.Links = args.links
c.Source = args.source
return c return c
def options(): def options():
...@@ -211,6 +212,7 @@ def options(): ...@@ -211,6 +212,7 @@ def options():
ap.add_argument("--min-replies", help="Filter the tweets by minimum number of replies.") ap.add_argument("--min-replies", help="Filter the tweets by minimum number of replies.")
ap.add_argument("--links", help="Include or exclude tweets containing one o more links. If not specified"+ ap.add_argument("--links", help="Include or exclude tweets containing one o more links. If not specified"+
" you will get both tweets that might contain links or not.") " you will get both tweets that might contain links or not.")
ap.add_argument("--source", help="Filter the tweets for specific source client.")
args = ap.parse_args() args = ap.parse_args()
return args return args
......
...@@ -77,6 +77,7 @@ def init(db): ...@@ -77,6 +77,7 @@ def init(db):
video integer, video integer,
geo text, geo text,
near text, near text,
source text,
time_update integer not null, time_update integer not null,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
...@@ -246,8 +247,9 @@ def tweets(conn, Tweet, config): ...@@ -246,8 +247,9 @@ def tweets(conn, Tweet, config):
Tweet.video, Tweet.video,
Tweet.geo, Tweet.geo,
Tweet.near, Tweet.near,
Tweet.source,
time_ms) time_ms)
cursor.execute('INSERT INTO tweets VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', entry) cursor.execute('INSERT INTO tweets VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', entry)
if config.Favorites: if config.Favorites:
query = 'INSERT INTO favorites VALUES(?,?)' query = 'INSERT INTO favorites VALUES(?,?)'
......
...@@ -87,7 +87,8 @@ def createIndex(config, instance, **scope): ...@@ -87,7 +87,8 @@ def createIndex(config, instance, **scope):
"geo_tweet": {"type": "geo_point"}, "geo_tweet": {"type": "geo_point"},
"photos": {"type": "text"}, "photos": {"type": "text"},
"user_rt_id": {"type": "integer"}, "user_rt_id": {"type": "integer"},
"mentions": {"type": "keyword"} "mentions": {"type": "keyword"},
"source": {"type": "keyword"}
} }
}, },
"settings": { "settings": {
...@@ -247,6 +248,8 @@ def Tweet(Tweet, config): ...@@ -247,6 +248,8 @@ def Tweet(Tweet, config):
_t_place = getLocation(Tweet.place) _t_place = getLocation(Tweet.place)
if _t_place: if _t_place:
j_data["_source"].update({"geo_tweet": getLocation(Tweet.place)}) j_data["_source"].update({"geo_tweet": getLocation(Tweet.place)})
if Tweet.source:
j_data["_source"].update({"source": Tweet.Source})
actions.append(j_data) actions.append(j_data)
es = Elasticsearch(config.Elasticsearch, verify_certs=config.Skip_certs) es = Elasticsearch(config.Elasticsearch, verify_certs=config.Skip_certs)
......
...@@ -89,18 +89,11 @@ def update(object, config): ...@@ -89,18 +89,11 @@ def update(object, config):
"nretweets": int(Tweet.retweets_count), "nretweets": int(Tweet.retweets_count),
"quote_url": Tweet.quote_url, "quote_url": Tweet.quote_url,
"search": str(config.Search), "search": str(config.Search),
"near": config.Near "near": Tweet.near,
"geo": Tweet.geo,
"source": Tweet.source,
"user_rt_id": Tweet.user_rt_id
} }
if Tweet.retweet:
_data.update({"user_rt_id": Tweet.user_rt_id})
try:
_data.update({"near": Tweet.near})
except AttributeError:
pass
try:
_data.update({"geo": Tweet.geo})
except AttributeError:
pass
_object_blocks[_type].append(_data) _object_blocks[_type].append(_data)
elif _type == "user": elif _type == "user":
user = object user = object
......
...@@ -22,18 +22,12 @@ def tweetData(t): ...@@ -22,18 +22,12 @@ def tweetData(t):
"link": t.link, "link": t.link,
"retweet": t.retweet, "retweet": t.retweet,
"quote_url": t.quote_url, "quote_url": t.quote_url,
"video": t.video "video": t.video,
"user_rt_id": t.user_rt_id,
"near": t.near,
"geo": t.geo,
"source": t.source
} }
if t.retweet:
data.update({"user_rt_id": t.user_rt_id})
try:
data.update({"near": t.near})
except AttributeError:
pass
try:
data.update({"geo": t.geo})
except AttributeError:
pass
return data return data
def tweetFieldnames(): def tweetFieldnames():
...@@ -63,7 +57,8 @@ def tweetFieldnames(): ...@@ -63,7 +57,8 @@ def tweetFieldnames():
"video", "video",
"user_rt_id", "user_rt_id",
"near", "near",
"geo" "geo",
"source"
] ]
return fieldnames return fieldnames
......
...@@ -100,4 +100,5 @@ def Tweet(tw, config): ...@@ -100,4 +100,5 @@ def Tweet(tw, config):
t.quote_url = getQuoteURL(tw) t.quote_url = getQuoteURL(tw)
t.near = config.Near if config.Near else "" t.near = config.Near if config.Near else ""
t.geo = config.Geo if config.Geo else "" t.geo = config.Geo if config.Geo else ""
t.source = config.Source if config.Source else ""
return t return t
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