Commit e5f47dbf authored by Francesco Poldi's avatar Francesco Poldi

Added index for users and more

Added new index for users

Added function `elasticsearch.UserProfile()` to index users into Elasticsearch instance

Added `_save_` to save the format of dates and times before formatting for Elasticsearch format
parent c110ed94
PUT twint
{
"mappings" : {
"mappings": {
"items": {
"properties": {
"id": {"type": "long"},
......
PUT twintUser
{
"mappings": {
"items": {
"properties": {
"id": {"type": "keyword"},
"name": {"type": "keyword"},
"username": {"type": "keyword"},
"bio": {"type": "text"},
"location": {"type": "keyword"},
"url": {"type": "text"},
"join_datetime": {"type": "date", "format": "yyyy-MM-dd HH:mm:ss"},
"join_date": {"type": "date", "format": "yyyy-MM-dd"},
"join_time": {"type": "date", "format": "HH:mm:ss"},
"tweets": {"type": "integer"},
"following": {"type": "integer"},
"followers": {"type": "integer"},
"likes": {"type": "integer"},
"media": {"type": "integer"},
"private": {"type": "boolean"},
"verified": {"type": "boolean"},
"avatar": {"type": "text"},
"session": {"type": "keyword"}
}
}
}
,
"settings": {
"number_of_shards": 1
}
}
\ No newline at end of file
......@@ -150,7 +150,7 @@ def Follow(es, user, follow, session):
actions = []
j_data = {
"_index": "twintgraph2",
"_index": "twintGraph",
"_type": "items",
"_id": user + "_" + follow + "_" + session,
"_source": {
......@@ -165,3 +165,38 @@ def Follow(es, user, follow, session):
with nostdout():
helpers.bulk(es, actions, chunk_size=2000, request_timeout=200)
actions = []
def UserProfile(es, user, follow, session):
actions = []
j_data = {
"_index": "twintUser",
"_type": "items",
"_id": user.id + "_" + user.join_date + "_" + user.join_time + "_" + session,
"_source": {
"id": user.id,
"name": user.name,
"username": user.username,
"bio": user.bio,
"location": user.location,
"url": user.url,
"join_datetime": user.join_date + " " + user.join_time,
"join_date": user.join_date,
"join_time": user.join_time,
"tweets": user.tweets,
"following": user.following,
"followers": user.followers,
"likes": user.likes,
"media": user.media_count,
"private": user.is_private,
"verified": user.is_verified,
"avatar": user.avatat,
"session": session
}
}
actions.append(j_data)
es = Elasticsearch(es)
with nostdout():
helpers.bulk(es, actions, chunk_size=2000, request_timeout=200)
actions = []
from datetime import datetime
from . import db, elasticsearch, format, write
from .tweet import Tweet
from .user import User
......@@ -53,8 +55,14 @@ async def Users(u, config, conn):
db.user(conn, config.Username, config.Followers, user)
#if config.Elasticsearch:
# elasticsearch.Follow(config.Elasticsearch, user,
# _save_date = user.join_date
# _save_time = user.join_time
# user.join_date = str(datetime.strptime(user.join_date, "%d %b %Y")).split()[0]
# user.join_time = str(datetime.strptime(user.join_time, "%I:%M %p")).split()[1]
# elasticsearch.UserProfile(config.Elasticsearch, user,
# config.Username, config.Essid)
# user.join_date = _save_date
# user.join_time = _save_time
_output(user, output, config)
......
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