yihong0618 / shanbay_remember

扇贝自动发送今日新词到 telegram
MIT License
190 stars 60 forks source link

python 版本的 api_utils.js #22

Closed x1uc closed 2 weeks ago

x1uc commented 2 weeks ago

测试了几百个单词,无错误。 测试程序

from main import Decoder
import mysql.connector
import requests
import time

# Connect to the MySQL database
connection = mysql.connector.connect(
    host='localhost',
    user='root',
    password='123456',
    database='shanbay'
)
cursor = connection.cursor()

# Execute a query
cursor.execute("SELECT * FROM words")

rows = cursor.fetchall()

for row in rows:
    url = "https://apiv3.shanbay.com/wordsapp/words/vocab?word=" + row[1]
    headers = {
        "cookie": "mycookie"
    }
    response = requests.get(url, headers=headers)
    time.sleep(0.2)
    print(response.json())
    try:
        print(Decoder.decode(response.json()["data"]))
    except:
        print(f'{row[1]} is missing in shanbay')

image

yihong0618 commented 2 weeks ago

Nice let's use python version instead of js