This repository has been archived on 2023-10-01. You can view files and clone it, but cannot push or open issues or pull requests.
PyNyaaTa/pynyaata/utils.py

43 lines
1.1 KiB
Python
Raw Normal View History

2020-04-24 19:01:44 +00:00
import re
from datetime import datetime
from dateparser import parse
2022-12-21 14:53:50 +00:00
from .config import BLACKLIST_WORDS, DB_ENABLED
2020-04-24 19:01:44 +00:00
def link_exist_in_db(href):
2022-03-04 08:46:21 +00:00
if DB_ENABLED:
2020-04-24 19:01:44 +00:00
from .models import AnimeLink
return AnimeLink.query.filter_by(link=href).first()
return False
def parse_date(str_to_parse, date_format=''):
if str_to_parse is None:
2021-07-10 07:48:34 +00:00
date_to_format = datetime.fromtimestamp(0)
2020-04-24 19:01:44 +00:00
elif isinstance(str_to_parse, datetime):
2021-07-10 07:48:34 +00:00
date_to_format = str_to_parse
2020-04-24 19:01:44 +00:00
else:
date = parse(str_to_parse, date_formats=[date_format])
if date:
2021-07-10 07:48:34 +00:00
date_to_format = date
2020-04-24 19:01:44 +00:00
else:
2021-07-10 07:48:34 +00:00
date_to_format = datetime.fromtimestamp(0)
return date_to_format.isoformat(' ', 'minutes')
2020-04-24 19:01:44 +00:00
def boldify(str_to_replace, keyword):
if keyword:
return re.sub('(%s)' % keyword, r'<b>\1</b>', str_to_replace, flags=re.IGNORECASE)
else:
return str_to_replace
2020-04-27 18:47:54 +00:00
def check_blacklist_words(url):
return any(word.lower() in url.lower() for word in BLACKLIST_WORDS)
2021-01-30 18:40:36 +00:00
def check_if_vf(title):
return any(word.lower() in title.lower() for word in ['vf', 'multi', 'french'])