fix: correlations

This commit is contained in:
Terrtia 2023-08-23 16:13:20 +02:00
parent 3c1813ba02
commit 843b2d3134
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
4 changed files with 16 additions and 9 deletions

View file

@ -79,7 +79,7 @@ class TelegramFeeder(DefaultFeeder):
if meta.get('chat'): if meta.get('chat'):
chat = Chat(meta['chat']['id'], 'telegram') chat = Chat(meta['chat']['id'], 'telegram')
if meta['chat'].get('username'): # TODO USE ID AND SAVE USERNAME if meta['chat'].get('username'): # SAVE USERNAME
chat_username = meta['chat']['username'] chat_username = meta['chat']['username']
# Chat---Message # Chat---Message
@ -99,7 +99,7 @@ class TelegramFeeder(DefaultFeeder):
chat = None chat = None
# message sender # message sender
if meta.get('sender'): # TODO handle message channel forward if meta.get('sender'): # TODO handle message channel forward - check if is user
user_id = meta['sender']['id'] user_id = meta['sender']['id']
user_account = UsersAccount.UserAccount(user_id, 'telegram') user_account = UsersAccount.UserAccount(user_id, 'telegram')
# UserAccount---Message # UserAccount---Message
@ -117,10 +117,13 @@ class TelegramFeeder(DefaultFeeder):
if meta['sender'].get('username'): if meta['sender'].get('username'):
username = Username(meta['sender']['username'], 'telegram') username = Username(meta['sender']['username'], 'telegram')
user_account.add_correlation(username.type, username.get_subtype(r_str=True), username.id) user_account.add_correlation(username.type, username.get_subtype(r_str=True), username.id)
# TODO Update user_account<--->username timeline
# Username---Message # Username---Message
username.add(date, self.item_id) # TODO #################################################################### username.add(date, self.item_id) # TODO ####################################################################
if chat: if chat:
# Chat---Username
chat.add_correlation(username.type, username.get_subtype(r_str=True), username.id) chat.add_correlation(username.type, username.get_subtype(r_str=True), username.id)
# if meta.get('fwd_from'): # if meta.get('fwd_from'):

View file

@ -117,9 +117,15 @@ class Chat(AbstractSubtypeObject): # TODO # ID == username ?????
def get_name(self): # get username ???? def get_name(self): # get username ????
pass pass
# return username correlation # users that send at least a message else participants/spectator
def get_users(self): # get participants ??? -> passive users ??? # correlation created by messages
pass def get_users(self):
users = set()
accounts = self.get_correlation('user-account').get('user-account', [])
for account in accounts:
users.add(account[1:])
return users
# def get_last_message_id(self): # def get_last_message_id(self):
# #

View file

@ -91,7 +91,7 @@ class Message(AbstractObject):
# message_id = message_id[:-3] # message_id = message_id[:-3]
return message_id return message_id
def get_chat_id(self): # TODO optimize def get_chat_id(self): # TODO optimize -> use me to tag Chat
chat_id = self.get_basename().rsplit('_', 1)[0] chat_id = self.get_basename().rsplit('_', 1)[0]
# if chat_id.endswith('.gz'): # if chat_id.endswith('.gz'):
# chat_id = chat_id[:-3] # chat_id = chat_id[:-3]

View file

@ -87,9 +87,7 @@ class UserAccount(AbstractSubtypeObject):
def get_usernames(self): def get_usernames(self):
usernames = [] usernames = []
correl = self.get_correlation('username') # TODO TIMELINE
for partial_id in correl.get('username', []):
usernames.append(f'username:{partial_id}')
return usernames return usernames
def get_meta(self, options=set()): def get_meta(self, options=set()):