RYMCU

社区每天自动做题

heycmmcn 1 年前
# 脚本 # python3 # answer

setting.py

# 登录 post
login_url = 'https://rymcu.com/api/console/login'
# 每日一题 get
today_url = 'https://rymcu.com/api/answer/today'
# 查询答案 get
show_answer_url = 'http://1.116.175.112:8089/question/show-answer/%s'
# 答题 post
answer_url = 'https://rymcu.com/api/answer/answer'

user.json

[
  {
    "account": "username",
    "password": "pw"
  }
]

main.py

pip install requests
import json

import requests
from setting import login_url, today_url, show_answer_url, answer_url

headers = {
    'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
    'authorization': '',
    'content-type': 'application/json;charset=UTF-8',
}


def auto_answer():
    with open("users.json", 'r') as load_f:
        users = json.load(load_f)
        for login_data in users:
            user = requests.post(login_url, headers=headers, data=json.dumps(login_data)).json()
            if user['code'] == 0:
                headers['authorization'] = user['data']['user']['token']
                today = requests.get(today_url, headers=headers).json()
                if today['code'] == 0:
                    answer_id = today['data']['answerRecords'][0]['id']
                    print('今日试题::%s' % today['data']['answerRecords'][0])
                    answer = requests.get(show_answer_url % (answer_id)).json()
                    if answer['success'] == True:
                        correct_answer = answer['data']['respData']
                        print('正确答案:%s' % (correct_answer))
                        answer_content = {'idSubjectQuestion': answer_id, 'answer': correct_answer}
                        print(requests.post(answer_url, headers=headers, data=json.dumps(answer_content)).json())
pip install apscheduler

job.py

from apscheduler.schedulers.blocking import BlockingScheduler
import time
from main import auto_answer

scheduler = BlockingScheduler(timezone='Asia/Shanghai')


def auto_answer_job():
    auto_answer()
    print("%s: 执行任务" % time.asctime())

# 每天早上八点半起床
scheduler.add_job(auto_answer_job, 'cron', day_of_week='*', hour='8', minute='30')
scheduler.start()

如何润

https://github.com/heycmm/rymcu-Auto-Answer

后发布评论

我跟他们讲科学,告诉他们地球是圆的,他们不信,还要打我!还问我什么是爱,我一个单身狗哪里知道,结果他们又一起打我!

💻 把工程丢到 github 上?