How to use the demoji.last_downloaded_timestamp function in demoji

To help you get started, weโ€™ve selected a few demoji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bsolomon1124 / demoji / tests / test_demoji.py View on Github external
def test_load_codes_from_file_raises_if_dne():
    if os.path.isfile(demoji.CACHEPATH):
        os.remove(demoji.CACHEPATH)
    with pytest.raises(IOError):
        demoji._load_codes_from_file()
    assert demoji.last_downloaded_timestamp() is None
github bsolomon1124 / demoji / tests / test_demoji.py View on Github external
woman_tipping_hand,
    )
    assert demoji.findall(allhands) == {
        person_tipping_hand: "person tipping hand",
        man_tipping_hand: "man tipping hand",
        woman_tipping_hand: "woman tipping hand",
    }
    assert (
        demoji.replace(allhands)
        == "Someone actually gets paid to make a , a , and a "
    )
    assert (
        demoji.replace(allhands, "X")
        == "Someone actually gets paid to make a X, a X, and a X"
    )
    assert isinstance(demoji.last_downloaded_timestamp(), datetime.datetime)

    # Something for everyone...
    batch = [
        "๐Ÿ˜€",
        "๐Ÿ˜‚",
        "๐Ÿคฉ",
        "๐Ÿค",
        "๐Ÿคข",
        "๐Ÿ™",
        "๐Ÿ˜ซ",
        "๐Ÿ™€",
        "๐Ÿ’“",
        "๐Ÿงก",
        "๐Ÿ–ค",
        "๐Ÿ‘๏ธโ€๐Ÿ—จ๏ธ",
        "โœ‹",
github bsolomon1124 / demoji / tests / test_demoji.py View on Github external
def test_last_downloaded_timestamp_rettype():
    ts = demoji.last_downloaded_timestamp()
    assert isinstance(ts, datetime.datetime)
github DiscordWebsite / discord_logview / api / formatter.py View on Github external
ยฉ 2018 Kyber, licensed under MIT
modified by https://github.com/EJH2
ยฉ 2019 EJH2
"""

import base64
import html
import re

import demoji
import pendulum

from api.emoji import EMOJI_LIST, EMOJI_REGEX, UNICODE_LIST

if not demoji.last_downloaded_timestamp() or pendulum.now() > \
        (pendulum.instance(demoji.last_downloaded_timestamp()).add(days=7)):
    demoji.download_codes()

demoji.set_emoji_pattern()
# This is taken from the Demoji module, because they decided to make the emoji pattern private
esc = (re.escape(c) for c in sorted(dict(demoji.stream_unicodeorg_emojifile(demoji.URL)), key=len, reverse=True))
UNICODE_EMOJI_PAT = re.compile(r"|".join(esc)).pattern


def _encode_codeblock(m):
    return f'\x1AM{base64.b64encode(m.group(1).encode()).decode()}\x1AM'


def _encode_link(m):
    encoded_1 = base64.b64encode(m.group(1).encode()).decode()
    encoded_2 = base64.b64encode(m.group(2).encode()).decode()
    encoded_3 = f'|{base64.b64encode(m.group(5).encode()).decode()}' if m.group(3) else ''
github DiscordWebsite / discord_logview / api / formatter.py View on Github external
using code from 
ยฉ 2018 Kyber, licensed under MIT
modified by https://github.com/EJH2
ยฉ 2019 EJH2
"""

import base64
import html
import re

import demoji
import pendulum

from api.emoji import EMOJI_LIST, EMOJI_REGEX, UNICODE_LIST

if not demoji.last_downloaded_timestamp() or pendulum.now() > \
        (pendulum.instance(demoji.last_downloaded_timestamp()).add(days=7)):
    demoji.download_codes()

demoji.set_emoji_pattern()
# This is taken from the Demoji module, because they decided to make the emoji pattern private
esc = (re.escape(c) for c in sorted(dict(demoji.stream_unicodeorg_emojifile(demoji.URL)), key=len, reverse=True))
UNICODE_EMOJI_PAT = re.compile(r"|".join(esc)).pattern


def _encode_codeblock(m):
    return f'\x1AM{base64.b64encode(m.group(1).encode()).decode()}\x1AM'


def _encode_link(m):
    encoded_1 = base64.b64encode(m.group(1).encode()).decode()
    encoded_2 = base64.b64encode(m.group(2).encode()).decode()
github DiscordWebsite / discord_logview / django_logs / formatter.py View on Github external
import base64
import html
import re
from datetime import timedelta, datetime

import demoji
import pytz

from django_logs.emoji import EMOJI_LIST, EMOJI_REGEX, UNICODE_LIST

if not demoji.last_downloaded_timestamp() or datetime.now(pytz.UTC) > \
        (demoji.last_downloaded_timestamp() + timedelta(days=7)):
    demoji.download_codes()

if not demoji._EMOJI_PAT:
    demoji.set_emoji_pattern()


def format_content_html(content: str, users: dict = None, masked_links: bool = False, newlines: bool = True) -> str:
    # HTML-encode content

    def encode_codeblock(m):
        encoded = base64.b64encode(m.group(1).encode()).decode()
        return '\x1AM' + encoded + '\x1AM'

    # Encode multiline codeblocks (```text```)
    content = re.sub(r'```+((?:[^`]*?\n)?(?:[\s\S]+))\n?```+', encode_codeblock, content)