add jlpt n3 word

This commit is contained in:
hillerliao
2023-12-06 22:25:55 +09:00
parent 99ae6693f5
commit f921abe399

View File

@@ -1,3 +1,4 @@
import re
import csv
import random
import requests
@@ -18,12 +19,22 @@ def get_csv_line(url):
random_line = random.choice(data)
return random_line
def remove_html_tags(text):
"""Remove html tags from a string"""
clean = re.compile('<.*?>')
return re.sub(clean, '', text)
def ctx(category=''):
word = ''
if category == 'ja':
url = 'https://raw.githubusercontent.com/hillerliao/img/main/words.csv'
res = get_csv_line(url)
word = f"{res[1]} {res[2]} {res[4]} {res[3]} "
elif category == 'jlpt3':
url = 'https://raw.githubusercontent.com/hillerliao/img/main/hongbaoshu_N3.csv'
res = get_csv_line(url)
word = f"{res[0]}{res[1]} {res[2]}{res[3]}{res[4]}{res[5]}{res[6]} "
word = remove_html_tags(word)
else:
file = path.join(file_path,'toeflwords.txt')
with open(file, encoding='utf-8') as inf: