Ejemplo n.º 1
0
    def __init__(self, datasource: str):
        self._datasource = datasource
        self.is_archived = 'archived_threads' in datasource
        self.messages = []
        self.participants = set()
        self.is_archived = False
        self.is_group = False
        message_files = [x for x in os.listdir(self._datasource) if re.match(r'message_\d+\.json$', x)]

        determined_properties = False

        for message_file in message_files:
            filename = os.path.join(datasource, message_file)
            with open(filename, 'r') as data:
                chat_json = json.load(data)
                self.participants.update([x['name'] for x in chat_json['participants']])
                self.messages.extend([Message(x) for x in chat_json['messages']])

                if not determined_properties:
                    determined_properties = True
                    self.name = chat_json['title']
                    self.is_group = chat_json['thread_type'] == 'RegularGroup'

        self.messages.sort(key=operator.attrgetter('timestamp'))

        validate_keys(
            'chat',
            set(chat_json.keys()),
            set(('participants', 'title', 'thread_type', 'messages', 'is_still_participant', 'thread_path'))
        )
Ejemplo n.º 2
0
 def __init__(self, sender: str, video_json: Dict[str, Any]):
     self.sender = sender
     self.location = video_json['uri']
     self.timestamp = video_json['creation_timestamp']
     self.thumbnail_uri = video_json['thumbnail']['uri']
     validate_keys('video', set(video_json.keys()),
                   set(('uri', 'creation_timestamp', 'thumbnail')))
Ejemplo n.º 3
0
    def __init__(self, message_json):
        # Common properties
        self.sender = message_json['sender_name']
        self.timestamp = message_json['timestamp_ms']
        self.message_type = MessageType[message_json['type']]
        self.call_duration = None
        self.content = None
        self.photos = []
        self.videos = []
        self.gifs = []
        self.files = []
        self.shares = []
        self.reactions = []
        self.sticker = None
        self.users = []

        if 'content' in message_json:
            self.content = message_json['content']

        # Media
        if 'photos' in message_json:
            self.photos = [
                Photo(self.sender, x) for x in message_json['photos']
            ]
        if 'videos' in message_json:
            self.videos = [
                Video(self.sender, x) for x in message_json['videos']
            ]
        if 'gifs' in message_json:
            self.gifs = [Gif(self.sender, x) for x in message_json['gifs']]
        self.has_media = self.photos or self.videos or self.gifs

        # Share
        if 'share' in message_json:
            self.shares = [SharedItem(self.sender, message_json['share'])]

        # Other
        if 'files' in message_json:
            self.files = [File(self.sender, x) for x in message_json['files']]
        if 'reactions' in message_json:
            self.reactions = [Reaction(x) for x in message_json['reactions']]
        if 'sticker' in message_json:
            self.sticker = Sticker(self.sender, message_json['sticker'])
        if 'users' in message_json:
            self.users = {x['name'] for x in message_json['users']}
        if 'call_duration' in message_json:
            self.call_duration = message_json['call_duration']

        validate_keys(
            'message', set(message_json.keys()),
            set(('sender_name', 'timestamp_ms', 'type', 'content', 'photos',
                 'videos', 'share', 'files', 'reactions', 'gifs', 'sticker',
                 'users', 'call_duration')))
Ejemplo n.º 4
0
 def __init__(self, sender: str, sticker_json: Dict[str, Any]):
     self.sender = sender
     self.location = sticker_json['uri']
     validate_keys('gif', set(sticker_json.keys()), set(['uri']))
Ejemplo n.º 5
0
 def __init__(self, reaction_json):
     self.sender = reaction_json['actor']
     self.reaction = reaction_json['reaction']
     validate_keys('reaction', set(reaction_json.keys()),
                   set(('actor', 'reaction')))
Ejemplo n.º 6
0
 def __init__(self, sender: str, file_json: Dict[str, Any]):
     self.sender = sender
     self.uri = file_json['uri']
     self.timestamp = file_json['creation_timestamp']
     validate_keys('file', set(file_json.keys()),
                   set(('uri', 'creation_timestamp')))
Ejemplo n.º 7
0
 def __init__(self, sender: str, share_json: Dict[str, Any]):
     self.sender = sender
     self.uri = share_json['link']
     validate_keys('share', set(share_json.keys()), set(['link']))
Ejemplo n.º 8
0
 def __init__(self, sender: str, photo_json: Dict[str, Any]):
     self.sender = sender
     self.location = photo_json['uri']
     self.timestamp = photo_json['creation_timestamp']
     validate_keys('photo', set(photo_json.keys()),
                   set(('uri', 'creation_timestamp')))