Commit 0709e143 authored by Francesco Poldi's avatar Francesco Poldi

Updated storing structures

parent 894655fd
...@@ -88,13 +88,27 @@ def init(db): ...@@ -88,13 +88,27 @@ def init(db):
CREATE TABLE IF NOT EXISTS CREATE TABLE IF NOT EXISTS
retweets( retweets(
user_id integer not null, user_id integer not null,
username text not null,
tweet_id integer not null, tweet_id integer not null,
retweet_id integer not null,
CONSTRAINT retweets_pk PRIMARY KEY(user_id, tweet_id), CONSTRAINT retweets_pk PRIMARY KEY(user_id, tweet_id),
CONSTRAINT user_id_fk FOREIGN KEY(user_id) REFERENCES users(id), CONSTRAINT user_id_fk FOREIGN KEY(user_id) REFERENCES users(id),
CONSTRAINT tweet_id_fk FOREIGN KEY(tweet_id) REFERENCES tweets(id) CONSTRAINT tweet_id_fk FOREIGN KEY(tweet_id) REFERENCES tweets(id)
); );
""" """
cursor.execute(table_retweets) cursor.execute(table_retweets)
table_reply_to = """
CREATE TABLE IF NOT EXISTS
replies(
tweet_id integer not null,
user_id integer not null,
username text not null,
CONSTRAINT replies_pk PRIMARY KEY (user_id, tweet_id),
CONSTRAINT tweet_id_fk FOREIGN KEY (tweet_id) REFERENCES tweets(id)
);
"""
cursor.execute(table_reply_to)
table_favorites = """ table_favorites = """
CREATE TABLE IF NOT EXISTS CREATE TABLE IF NOT EXISTS
...@@ -256,8 +270,13 @@ def tweets(conn, Tweet, config): ...@@ -256,8 +270,13 @@ def tweets(conn, Tweet, config):
cursor.execute(query, (config.User_id, Tweet.id)) cursor.execute(query, (config.User_id, Tweet.id))
if Tweet.retweet: if Tweet.retweet:
query = 'INSERT INTO retweets VALUES(?,?)' query = 'INSERT INTO retweets VALUES(?,?,?,?)'
cursor.execute(query, (config.User_id, Tweet.id)) cursor.execute(query, (int(Tweet.user_rt_id), Tweet.user_rt, Tweet.id, int(Tweet.retweet_id)))
if Tweet.reply_to:
for reply in Tweet.reply_to:
query = 'INSERT INTO replies VALUES(?,?,?)'
cursor.execute(query, (Tweet.id, int(reply['user_id']), reply['username']))
conn.commit() conn.commit()
except sqlite3.IntegrityError: except sqlite3.IntegrityError:
......
...@@ -66,7 +66,6 @@ def createIndex(config, instance, **scope): ...@@ -66,7 +66,6 @@ def createIndex(config, instance, **scope):
"tweet": {"type": "text"}, "tweet": {"type": "text"},
"hashtags": {"type": "keyword"}, "hashtags": {"type": "keyword"},
"cashtags": {"type": "keyword"}, "cashtags": {"type": "keyword"},
"user_id": {"type": "long"},
"user_id_str": {"type": "keyword"}, "user_id_str": {"type": "keyword"},
"username": {"type": "keyword"}, "username": {"type": "keyword"},
"name": {"type": "text"}, "name": {"type": "text"},
...@@ -86,9 +85,12 @@ def createIndex(config, instance, **scope): ...@@ -86,9 +85,12 @@ def createIndex(config, instance, **scope):
"geo_near": {"type": "geo_point"}, "geo_near": {"type": "geo_point"},
"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": "keyword"},
"mentions": {"type": "keyword"}, "mentions": {"type": "keyword"},
"source": {"type": "keyword"} "source": {"type": "keyword"},
"user_rt": {"type": "keyword"},
"retweet_id": {"type": "keyword"},
"reply_to": {"type": "nested"}
} }
}, },
"settings": { "settings": {
...@@ -203,7 +205,6 @@ def Tweet(Tweet, config): ...@@ -203,7 +205,6 @@ def Tweet(Tweet, config):
"tweet": Tweet.tweet, "tweet": Tweet.tweet,
"hashtags": Tweet.hashtags, "hashtags": Tweet.hashtags,
"cashtags": Tweet.cashtags, "cashtags": Tweet.cashtags,
"user_id": Tweet.user_id,
"user_id_str": Tweet.user_id_str, "user_id_str": Tweet.user_id_str,
"username": Tweet.username, "username": Tweet.username,
"name": Tweet.name, "name": Tweet.name,
...@@ -223,6 +224,10 @@ def Tweet(Tweet, config): ...@@ -223,6 +224,10 @@ def Tweet(Tweet, config):
} }
if Tweet.retweet: if Tweet.retweet:
j_data["_source"].update({"user_rt_id": Tweet.user_rt_id}) j_data["_source"].update({"user_rt_id": Tweet.user_rt_id})
j_data["_source"].update({"user_rt": Tweet.user_rt})
j_data["_source"].update({"retweet_id": Tweet.retweet_id})
if Tweet.reply_to:
j_data["_source"].update({"reply_to": Tweet.reply_to})
if Tweet.photos: if Tweet.photos:
_photos = [] _photos = []
for photo in Tweet.photos: for photo in Tweet.photos:
......
...@@ -92,7 +92,10 @@ def update(object, config): ...@@ -92,7 +92,10 @@ def update(object, config):
"near": Tweet.near, "near": Tweet.near,
"geo": Tweet.geo, "geo": Tweet.geo,
"source": Tweet.source, "source": Tweet.source,
"user_rt_id": Tweet.user_rt_id "user_rt_id": Tweet.user_rt_id,
"user_rt": Tweet.user_rt,
"retweet_id": Tweet.retweet_id,
"reply_to": Tweet.reply_to
} }
_object_blocks[_type].append(_data) _object_blocks[_type].append(_data)
elif _type == "user": elif _type == "user":
......
...@@ -23,10 +23,13 @@ def tweetData(t): ...@@ -23,10 +23,13 @@ def tweetData(t):
"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, "near": t.near,
"geo": t.geo, "geo": t.geo,
"source": t.source "source": t.source,
"user_rt_id": t.user_rt_id,
"user_rt": t.user_rt,
"retweet_id": t.retweet_id,
"reply_to": t.reply_to
} }
return data return data
...@@ -55,10 +58,13 @@ def tweetFieldnames(): ...@@ -55,10 +58,13 @@ def tweetFieldnames():
"retweet", "retweet",
"quote_url", "quote_url",
"video", "video",
"user_rt_id",
"near", "near",
"geo", "geo",
"source" "source",
"user_rt_id",
"user_rt",
"retweet_id",
"reply_to"
] ]
return fieldnames return fieldnames
......
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