# Path: src/merveilles/constants.py
# PERSON_COLORS = ["#FFD923", "#AA2BEF", "#366EEF", "#A68B0B", "#18BECD",
#     "#4BFD03", "#32D7B7", "#E13611"
# ]
# 
# THUMBNAIL_SIZE = 256, 256
# 
# THUMBNAIL_DIR = "src/static/thumbnails/"


from .constants import PERSON_COLORS, THUMBNAIL_SIZE, THUMBNAIL_DIR
from flask import Markup, current_app
from merveilles.filters import get_domain_filter
from PIL import Image
    from merveilles.database import get_page_count
import re, requests, os, markdown, random, string

def get_domain(raw_url):
    return get_domain_filter(raw_url['url'])

def visible(element):
    if element.parent.name in ['style', 'script', '[document]',
        'head', 'title', 'link', 'meta', 'h1', 'h2', 'h3', 'h4',
        'ul']:
        return False
    elif re.match('<!--.*-->', str(element)):
        return False

    return True

def get_effective_page(page, filter_func=lambda x: True):
    page_count = get_page_count(filter_func)
    pages = list(range(0, int(page_count)))
    requested_page = int(page)
    if page_count > 0 and requested_page < 0:
        requested_page = 0
    elif page_count > 0 and requested_page > pages[-1]:
        requested_page = pages[-1]

    return (pages, requested_page)

def random_password():
    myrg = random.SystemRandom()
    length = 32
    # If you want non-English characters, remove the [0:52]
    alphabet = string.letters[0:52] + string.digits

# Path: src/merveilles/constants.py
# PERSON_COLORS = ["#FFD923", "#AA2BEF", "#366EEF", "#A68B0B", "#18BECD",
#     "#4BFD03", "#32D7B7", "#E13611"
# ]
# 
# THUMBNAIL_SIZE = 256, 256
# 
# THUMBNAIL_DIR = "src/static/thumbnails/"


# Path: src/merveilles/utils.py
from .constants import PERSON_COLORS, THUMBNAIL_SIZE, THUMBNAIL_DIR
from flask import Markup, current_app
from merveilles.filters import get_domain_filter
from PIL import Image
    from merveilles.database import get_page_count
import re, requests, os, markdown, random, string


def get_domain(raw_url):
    return get_domain_filter(raw_url['url'])

def visible(element):
    if element.parent.name in ['style', 'script', '[document]',
        'head', 'title', 'link', 'meta', 'h1', 'h2', 'h3', 'h4',
        'ul']:
        return False
    elif re.match('<!--.*-->', str(element)):
        return False

    return True

def get_effective_page(page, filter_func=lambda x: True):
    page_count = get_page_count(filter_func)
    pages = list(range(0, int(page_count)))
    requested_page = int(page)
    if page_count > 0 and requested_page < 0:
        requested_page = 0
    elif page_count > 0 and requested_page > pages[-1]:
        requested_page = pages[-1]

    return (pages, requested_page)

def random_password():
    myrg = random.SystemRandom()
    length = 32
    # If you want non-English characters, remove the [0:52]
    alphabet = string.letters[0:52] + string.digits

    pw = str().join(myrg.choice(alphabet) for _ in range(length))