Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add advanced header settings #38

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
```

* windows替代crontab方法

将"auto_run_windows.bat"中D:"替换为你的盘,"D:\replace_with_path_to_repo"路径替换为你的仓库路径 "。

```bat
Expand Down Expand Up @@ -67,12 +67,14 @@

这段时间逐渐有账户被要求强制微信扫码登录, 导致程序失效。

增加了直接用cookie签到和答题的方式, 需要修改配置文件configure/cookie.json,把已登录的浏览器复制的cookie 粘贴到这个文件,api key和以前一样也需要替换。
增加了直接用cookie签到和答题的方式, 需要修改配置文件configure/settings.json,把已登录的浏览器复制的header (user-agent, accept, accept-language, cookie) 粘贴到这个文件,api key和以前一样也需要替换。

> user-agent, accept, accept-language 不填写将使用默认配置

使用cookie.json 后,原先的data.json 就用不到了,所以不再需要配置。
使用settings.json 后,原先的data.json 就用不到了,所以不再需要配置。

<details>
<summary> 如何找到cookie, F12 打开浏览器 console -> network 标签 -> 找到 bbs/ 请求 -> 查看具体的请求头 -> 找到cookie -> 复制cookie 后面的内容 </summary>
<summary> 如何找到header, F12 打开浏览器 console -> network 标签 -> 找到 bbs/ 请求 -> 查看具体的请求头 -> 找到cookie -> 复制 user-agent, accept, accept-language, cookie 后面的内容 </summary>

![](screenshots/cookie.png)
</details>
Expand Down
8 changes: 0 additions & 8 deletions configure/cookie.json

This file was deleted.

8 changes: 0 additions & 8 deletions configure/cookie_template.json

This file was deleted.

11 changes: 11 additions & 0 deletions configure/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"users": [
{
"user_agent": "replace_with_your_user_agent",
"accept": "replace_with_your_accept",
"accept_language": "replace_with_your_accept_language",
"cookie": "replace_with_your_cookies"
}
],
"api_key": "replace_with_your_api_key"
}
11 changes: 11 additions & 0 deletions configure/settings_template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"users": [
{
"user_agent": "replace_with_your_user_agent",
"accept": "replace_with_your_accept",
"accept_language": "replace_with_your_accept_language",
"cookie": "replace_with_your_cookies"
}
],
"api_key": "replace_with_your_api_key"
}
Binary file modified screenshots/cookie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 25 additions & 4 deletions src/raw_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import http.cookies

user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"
accept = "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"
accept_language = "en-US,en;q=0.5"
# user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"

referer = "https://www.1point3acres.com/bbs/"
Expand Down Expand Up @@ -57,17 +59,22 @@ def check_status_code(response: requests.Response, error_desc: str = ""):
exit(-1)


def login_cookie(cookie: str) -> bool:
global session
def login_settings(login_settings: str) -> bool:
global session, user_agent, accept, accept_language
session = requests.session()
session.cookies.update(http.cookies.SimpleCookie(cookie))
session.cookies.update(http.cookies.SimpleCookie(login_settings["cookie"]))
for e in ["user_agent", "accept", "accept_language"]:
if e in login_settings and login_settings[e] != f"replace_with_your_{e}":
globals()[e] = login_settings[e]
return True


def get_login_info_() -> (str, str):
def get_login_info_() -> (str, str, str):
global session
header = {
"User-Agent": user_agent,
"Accept": accept,
"Accept-Language": accept_language,
"Referer": referer,
}
session = requests.session()
Expand Down Expand Up @@ -113,6 +120,8 @@ def get_login_info_v2() -> str:
# global proxy
header = {
"User-Agent": user_agent,
"Accept": accept,
"Accept-Language": accept_language,
"Referer": referer,
}
session = requests.session()
Expand Down Expand Up @@ -143,6 +152,8 @@ def login(username: str, password_hashed: str, form_hash: str, login_hash: str,
print("try login...")
header = {
"User-Agent": user_agent,
"Accept": accept,
"Accept-Language": accept_language,
'Content-Type': 'application/x-www-form-urlencoded',
}
# body = {
Expand Down Expand Up @@ -194,6 +205,8 @@ def login_v2(username: str, password_hashed: str, csrf_token: str, solver) -> bo
print("try login...")
header = {
"User-Agent": user_agent,
"Accept": accept,
"Accept-Language": accept_language,
'Content-Type': 'application/x-www-form-urlencoded',
'Referer': 'https://auth.1point3acres.com/login',
'Origin': 'https://auth.1point3acres.com',
Expand Down Expand Up @@ -247,6 +260,8 @@ def get_checkin_info_() -> (str, str):
sec_hash = ""
header = {
"User-Agent": user_agent,
"Accept": accept,
"Accept-Language": accept_language,
"Referer": referer
}
response = session.get(get_checkin_url, headers=header)
Expand Down Expand Up @@ -277,6 +292,8 @@ def get_checkin_info_() -> (str, str):
def do_daily_checkin_(solver, form_hash: str, sec_hash: str = "S00") -> bool:
header = {
"User-Agent": user_agent,
"Accept": accept,
"Accept-Language": accept_language,
"Content-Type": "application/x-www-form-urlencoded",
"Referer": "https://www.1point3acres.com/bbs/dsu_paulsign-sign.html"
}
Expand Down Expand Up @@ -329,6 +346,8 @@ def get_daily_task_answer() -> (str, str, str):
print("get question...")
header = {
"User-Agent": user_agent,
"Accept": accept,
"Accept-Language": accept_language,
"Referer": referer
}
response = session.get(get_question_url, headers=header)
Expand Down Expand Up @@ -381,6 +400,8 @@ def get_daily_task_answer() -> (str, str, str):
def do_daily_question_(answer: str, solver, form_hash: str, sec_hash: str = "SA00") -> bool:
header = {
"User-Agent": user_agent,
"Accept": accept,
"Accept-Language": accept_language,
"Referer": referer,
"Content-Type": "application/x-www-form-urlencoded",
}
Expand Down
18 changes: 9 additions & 9 deletions src/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
# return result


def daily_login_cookie(cookie: str):
return login_cookie(cookie)
def daily_login_settings(settings: dict):
return login_settings(settings)


def daily_login_v2(solver, username: str, password: str):
Expand Down Expand Up @@ -106,8 +106,8 @@ def daily_question(solver) -> bool:
return do_daily_question_(answer=answer, solver=solver, form_hash=form_hash, sec_hash=sec_hash)


def do_all_cookie(solver, cookie: str):
daily_login_cookie(cookie)
def do_all_settings(solver, settings: dict):
daily_login_settings(settings)
daily_checkin(solver)
daily_question(solver)
return
Expand All @@ -124,19 +124,19 @@ def do_all_password(solver, username: str, password: str):
def main(from_file: bool = False):
users = []
api_key = ""
cookie_file = "../configure/cookie.json"
settings_file = "../configure/settings.json"
password_file = "../configure/data.json"
if (len(sys.argv) > 1):
cookie_file = sys.argv[1]
if os.path.exists(cookie_file):
fp = open(cookie_file)
settings_file = sys.argv[1]
if os.path.exists(settings_file):
fp = open(settings_file)
data = json.load(fp)
users = data["users"]
api_key = data["api_key"]
solver = TwoCaptcha(api_key)
if api_key != "replace_with_your_api_key":
for user in users:
do_all_cookie(solver, user["cookie"])
do_all_settings(solver, user)
return

fp = open(password_file)
Expand Down