88 lines
2.3 KiB
Python
88 lines
2.3 KiB
Python
import random
|
|
import re
|
|
import jieba
|
|
from typing import List
|
|
|
|
SKILL_TAGS = [
|
|
"C++",
|
|
"Java",
|
|
"Python",
|
|
"TypeScript",
|
|
"iOS",
|
|
"Android",
|
|
"Web",
|
|
"Javascript",
|
|
"Vue",
|
|
"Go",
|
|
]
|
|
|
|
# dynamically update skill tags? maybe based on the most commonly extracted keywords to help the system adapt to change
|
|
def updateSkillTags(string):
|
|
SKILL_TAGS.append(string)
|
|
|
|
|
|
def generate_auth_code():
|
|
filtered = "0123456789"
|
|
code = "".join(random.choice(filtered) for i in range(6))
|
|
return code
|
|
|
|
|
|
# TODO: Need to optimize
|
|
def generate_self_intro_summary(content_html: str) -> str:
|
|
element_html = re.compile("<.*?>")
|
|
content_text = re.sub(element_html, "", content_html).strip()
|
|
return content_text[:50]
|
|
|
|
|
|
# TODO: Need to optimize
|
|
def extract_skill_tags(content_html: str) -> List[str]:
|
|
element_html = re.compile("<.*?>")
|
|
content_text = re.sub(element_html, "", content_html).strip()
|
|
words = set([word.lower() for word in jieba.cut(content_text) if word.strip()])
|
|
|
|
results = []
|
|
for tag in SKILL_TAGS:
|
|
if tag.lower() in words:
|
|
results.append(tag)
|
|
return results
|
|
|
|
|
|
def extract_title(content_html: str) -> List[str]:
|
|
element_html = re.compile("<.*?>")
|
|
content_text = re.sub(element_html, "\n", content_html).strip()
|
|
|
|
cut_point_indexes = []
|
|
for cut_point in [".", ",", ";", "\r", "\n"]:
|
|
result = content_text.find(cut_point)
|
|
if result > 0:
|
|
cut_point_indexes.append(result)
|
|
|
|
title = (
|
|
content_text[: min(cut_point_indexes)]
|
|
if len(cut_point_indexes) > 0
|
|
else content_text
|
|
)
|
|
return title
|
|
|
|
|
|
def check_password_complexity(password):
|
|
lowercase_pattern = r"[a-z]"
|
|
uppercase_pattern = r"[A-Z]"
|
|
digit_pattern = r"\d"
|
|
special_pattern = r'[!@#$%^&*(),.?":{}|<>]'
|
|
|
|
password_lowercase_one = bool(re.search(lowercase_pattern, password))
|
|
password_uppercase_one = bool(re.search(uppercase_pattern, password))
|
|
password_digit_one = bool(re.search(digit_pattern, password))
|
|
password_special_one = bool(re.search(special_pattern, password))
|
|
|
|
if (
|
|
password_lowercase_one
|
|
and password_uppercase_one
|
|
and password_digit_one
|
|
and password_special_one
|
|
):
|
|
return True
|
|
else:
|
|
return False
|