Ejemplo n.º 1
0
def sent_message(sender, **kwargs):
    msg = kwargs["message"]
    resp = kwargs["response"]

    for recipient in (
        list(izip_longest(msg["To"].split(","), [], fillvalue='to')) +
        list(izip_longest(msg.get("Cc", "").split(","), [], fillvalue='cc')) +
        list(izip_longest(msg.get("Bcc", "").split(","), [], fillvalue='bcc'))
    ):

        if not recipient[0]:
            continue

        submitted_at = parsedatetime(resp['SubmittedAt'])

        emsg = EmailMessage(
            message_id=resp["MessageID"],
            submitted_at=submitted_at,
            status=resp["Message"],
            to=recipient[0],
            to_type=recipient[1],
            sender=msg["From"],
            reply_to=msg.get("ReplyTo", ""),
            subject=msg["Subject"],
            tag=msg.get("Tag", ""),
            text_body=msg["TextBody"],
            html_body=msg.get("HtmlBody", ""),
            headers=msg.get("Headers", ""),
            attachments=msg.get("Attachments", "")
        )
        emsg.save()
Ejemplo n.º 2
0
    def __init__(self,
                 client,
                 data: dict,
                 keys=[],
                 dtkeys=['created_at', 'updated_at']):
        self._data = data
        self.client = client

        for key in keys:
            setattr(self, key, data.get(key))

        for key in dtkeys:
            if data.get(key):
                parsed_date = parsedatetime(data[key])
                setattr(self, key, parsed_date)

        if isinstance(self._data.get('anime'), dict):
            self.anime = Anime(client, data.get('anime', {}))

        if isinstance(self._data.get('theme'), dict):
            self.theme = Theme(client, data.get('theme', {}))

        if isinstance(self._data.get('song'), dict):
            self.song = Song(client, data.get('song', {}))

        self._set_list_attrib('songs', Song)
        self._set_list_attrib('anime', Anime)
        self._set_list_attrib('themes', Theme)
        self._set_list_attrib('videos', Video)
        self._set_list_attrib('series', Series)
        self._set_list_attrib('entries', Entry)
        self._set_list_attrib('artists', Artist)
        self._set_list_attrib('synonyms', Synonym)
        self._set_list_attrib('resources', Resource)
        self._set_list_attrib('announcements', Announcement)
Ejemplo n.º 3
0
def sent_message(sender, **kwargs):
    msg = kwargs["message"]
    resp = kwargs["response"]

    for recipient in (
            list(izip_longest(msg["To"].split(","), [], fillvalue='to')) +
            list(izip_longest(msg.get(
                "Cc", "").split(","), [], fillvalue='cc')) + list(
                    izip_longest(msg.get("Bcc", "").split(","), [],
                                 fillvalue='bcc'))):

        if not recipient[0]:
            continue

        submitted_at = parsedatetime(resp['SubmittedAt'])

        emsg = EmailMessage(message_id=resp["MessageID"],
                            submitted_at=submitted_at,
                            status=resp["Message"],
                            to=recipient[0],
                            to_type=recipient[1],
                            sender=msg["From"],
                            reply_to=msg.get("ReplyTo", ""),
                            subject=msg["Subject"],
                            tag=msg.get("Tag", ""),
                            text_body=msg["TextBody"],
                            html_body=msg.get("HtmlBody", ""),
                            headers=msg.get("Headers", ""),
                            attachments=msg.get("Attachments", ""))
        emsg.save()
Ejemplo n.º 4
0
 def _update_app_token(self, response_future):
     if response_future.response_code == 200:
         app_token_response = response_future.get_entity()
         self._app_token = app_token_response['token']
         self._app_token_expiry = parsedatetime(
             app_token_response['expiresAt'])
     else:
         self._app_token = None
Ejemplo n.º 5
0
def compile_page(page, page_text, templates, config, extra_config):
    if config:
        with open(config) as defaults_file:
            default_config = json.load(defaults_file)
    else:
        default_config = dict()

    if not templates:
        templates = os.getcwd()

    raw_markdown = frontmatter.load(page)
    md = raw_markdown.content

    merged = dict()
    merged.update(default_config)
    merged.update(extra_config)
    merged.update(raw_markdown)

    # mandatory attributes
    if 'canonical' not in merged:
        merged['canonical'] = None

    if 'template' not in merged:
        merged['template'] = 'default.html'

    if 'markdown_extensions' in merged:
        markdown_extensions = merged['markdown_extensions']
    else:
        markdown_extensions = []

    merged['content_raw'] = md

    if 'process_raw' in merged:
        merged['content'] = merged['content_raw']
    else:
        merged['content'] = BeautifulSoup(
            markdown(md, extensions=markdown_extensions),
            'html.parser').prettify()

    if 'canonical' not in raw_markdown.keys():
        page_path = page

        if 'canonical_remove_path_prefix' in merged:
            page_path = page_path[
                page_path.find(merged['canonical_remove_path_prefix']) +
                len(merged['canonical_remove_path_prefix']):]

        if 'canonical_relative_path' in merged:
            merged['canonical'] = urllib.parse.urljoin(
                merged['canonical'], merged['canonical_relative_path'])
        else:
            merged['canonical'] = urllib.parse.urljoin(
                merged['canonical'], change_file_extension(page_path, '.html'))

    if 'updated' not in merged.keys():
        (mode, ino, dev, nlink, uid, gid, size, atime, mtime,
         ctime) = os.stat(page)
        merged['updated'] = "%s" % time.ctime(mtime)

    updated = parsedatetime(merged['updated'])
    merged['updated'] = updated.strftime("%a %b %d, %Y")
    if not (updated.hour == 0 and updated.minute == 0 and updated.second == 0):
        merged['updated'] = merged['updated'] + ', ' + updated.strftime(
            "%H:%M:%S")

    merged['year'] = updated.year
    merged['month'] = updated.month
    merged['day'] = updated.day
    merged['templates'] = templates or None
    merged['page'] = os.path.splitext(os.path.basename(page))[0]

    merged['template'] = ensure_a_file_extension(merged['template'], '.html')

    if 'sitestructure' in merged:
        with open(merged['sitestructure'], "r") as f:
            merged['sitestructure'] = json.load(f)

    return merged