示例#1
0
def load_freshmen() -> List[ID]:
    freshmen = []
    text = Storage.read_text(path=freshmen_file)
    if text is None:
        return freshmen
    array = text.splitlines()
    for item in array:
        identifier = ID.parse(identifier=item)
        if identifier is None:
            Log.error('ID error: %s' % item)
        elif identifier.type == NetworkType.MAIN:
            freshmen.append(identifier)
        else:
            # Log.error('Not a user ID: %s' % identifier)
            pass
    return freshmen
示例#2
0
 def message(self, signature: str) -> Optional[dict]:
     msg = self.msg_table.load(signature=signature)
     if msg is None:
         Log.error('failed to load message: %s' % signature)
         return None
     # message content
     content = msg.get('content')
     if content is None:
         data = msg['data']
         content = Content.parse(content=json.loads(data))
         assert isinstance(content, TextContent), 'content error: %s' % data
         msg['content'] = content.dictionary
     # message url
     link = msg.get('link')
     if link is None:
         link = msg_url(signature=signature)
         msg['link'] = link
     return msg.dictionary
示例#3
0
 def error(self, msg: str):
     Log.error('%s >\t%s' % (self.__class__.__name__, msg))
示例#4
0
 def __query(self, content: Content, sender: ID) -> TextContent:
     dialog = self.dialog
     try:
         return dialog.query(content=content, sender=sender)
     except URLError as error:
         Log.error('%s' % error)