mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-06-10 07:26:47 +00:00
get random ja word
This commit is contained in:
@@ -3,10 +3,12 @@ from rsshub.extensions import cache
|
||||
|
||||
bp = Blueprint('main', __name__)
|
||||
|
||||
@bp.route('/word/<string:category>')
|
||||
@bp.route('/')
|
||||
def word():
|
||||
@cache.cached(timeout=3600)
|
||||
def word(category=''):
|
||||
from rsshub.spiders.word.word import ctx
|
||||
return render_template('main/word.html', **ctx())
|
||||
return render_template('main/word.html', **ctx(category))
|
||||
|
||||
@bp.route('/index')
|
||||
def index():
|
||||
|
||||
11
rsshub/spiders/word/Pipfile
Normal file
11
rsshub/spiders/word/Pipfile
Normal file
@@ -0,0 +1,11 @@
|
||||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "2.7"
|
||||
@@ -1,15 +1,34 @@
|
||||
import random
|
||||
import csv
|
||||
import random
|
||||
import requests
|
||||
import linecache
|
||||
import sys
|
||||
from os import path
|
||||
import requests
|
||||
from rsshub.utils import DEFAULT_HEADERS
|
||||
|
||||
|
||||
file_path = path.dirname(path.realpath(__file__))
|
||||
|
||||
def ctx():
|
||||
file = path.join(file_path,'toeflwords.txt')
|
||||
with open(file, encoding='utf-8') as inf:
|
||||
f = inf.readlines()
|
||||
count = len(f)
|
||||
wordnum = random.randrange(0, count, 1)
|
||||
word = linecache.getline(file, wordnum)
|
||||
return {"word": word}
|
||||
def get_csv_line(url):
|
||||
response = requests.get(url)
|
||||
lines = response.text.splitlines()
|
||||
reader = csv.reader(lines)
|
||||
data = list(reader)
|
||||
data = data[1:]
|
||||
random_line = random.choice(data)
|
||||
return random_line
|
||||
|
||||
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[3]} "
|
||||
else:
|
||||
file = path.join(file_path,'toeflwords.txt')
|
||||
with open(file, encoding='utf-8') as inf:
|
||||
f = inf.readlines()
|
||||
count = len(f)
|
||||
wordnum = random.randrange(0, count, 1)
|
||||
word = linecache.getline(file, wordnum)
|
||||
return {"word": word}
|
||||
Reference in New Issue
Block a user