mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-06-12 15:10:49 +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 = Blueprint('main', __name__)
|
||||||
|
|
||||||
|
@bp.route('/word/<string:category>')
|
||||||
@bp.route('/')
|
@bp.route('/')
|
||||||
def word():
|
@cache.cached(timeout=3600)
|
||||||
|
def word(category=''):
|
||||||
from rsshub.spiders.word.word import ctx
|
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')
|
@bp.route('/index')
|
||||||
def 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 linecache
|
||||||
import sys
|
|
||||||
from os import path
|
from os import path
|
||||||
|
import requests
|
||||||
|
from rsshub.utils import DEFAULT_HEADERS
|
||||||
|
|
||||||
|
|
||||||
file_path = path.dirname(path.realpath(__file__))
|
file_path = path.dirname(path.realpath(__file__))
|
||||||
|
|
||||||
def ctx():
|
def get_csv_line(url):
|
||||||
file = path.join(file_path,'toeflwords.txt')
|
response = requests.get(url)
|
||||||
with open(file, encoding='utf-8') as inf:
|
lines = response.text.splitlines()
|
||||||
f = inf.readlines()
|
reader = csv.reader(lines)
|
||||||
count = len(f)
|
data = list(reader)
|
||||||
wordnum = random.randrange(0, count, 1)
|
data = data[1:]
|
||||||
word = linecache.getline(file, wordnum)
|
random_line = random.choice(data)
|
||||||
return {"word": word}
|
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