Skip to content

Commit f996021

Browse files
authored
feat: enable local test (#12)
1 parent 49ea2fd commit f996021

File tree

9 files changed

+56
-21
lines changed

9 files changed

+56
-21
lines changed

.env.test

Whitespace-only changes.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*/__pycache__
2-
node_modules/
2+
node_modules/
3+
.env

README-en.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ https://github.com/timerring/CloudCheckin/blob/0b719258ab4f5f746b067798eb2a4185a
106106

107107
After configuring all content, please manually execute the `Setup CircleCI Context and Secrets` and `Deploy Cloudflare Worker` workflows once to ensure that configuration secrets are correctly synchronized to CircleCI contexts secrets through CircleCI CLI, and that the Cloudflare Worker is properly deployed. (Actions -> `Setup CircleCI Context and Secrets` -> `Run workflow` and Actions -> `Deploy Cloudflare Worker` -> `Run workflow`)
108108

109+
## Local Development
110+
111+
```bash
112+
# Install dependencies
113+
pip install -r requirements.txt
114+
115+
# Copy env template and fill in your config
116+
cp .env.test .env
117+
118+
# Run check-in scripts
119+
python -m nodeseek.nodeseek
120+
python -m v2ex.v2ex
121+
python -m onepoint3acres.onepoint3acres
122+
```
123+
109124
## FAQ
110125

111126
1. **Why use CircleCI instead of GitHub Actions directly?**

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ https://github.com/timerring/CloudCheckin/blob/0b719258ab4f5f746b067798eb2a4185a
149149
> [!IMPORTANT]
150150
> 有时 cookie 会过期导致签到失败,如果遇到失败情况,请考虑重新获取 cookie 填入 Secrets,再手动执行 `Setup CircleCI Context and Secrets` workflow 同步 cookie 到 CircleCI。
151151
152+
## 本地调试
153+
154+
```bash
155+
# 安装依赖
156+
pip install -r requirements.txt
157+
158+
# 复制环境变量模板并填入你的配置
159+
cp .env.test .env
160+
161+
# 运行签到脚本
162+
python -m nodeseek.nodeseek
163+
python -m v2ex.v2ex
164+
python -m onepoint3acres.onepoint3acres
165+
```
166+
152167
## 常见问题
153168

154169
1. 为什么要采用 CircleCI,不直接用 Github Actions?

nodeseek/nodeseek.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
from curl_cffi import requests
44
import random
55
import time
6+
from dotenv import load_dotenv
67
from telegram.notify import send_tg_notification
78

9+
load_dotenv()
10+
811
# Get COOKIE from environment variable, multiple cookies separated by &
9-
cookies = os.environ.get('NODESEEK_COOKIE').strip()
12+
cookies = os.environ.get('NODESEEK_COOKIE', '').strip()
1013

1114
if not cookies:
1215
raise ValueError("Environment variable NODESEEK_COOKIE is not set")
@@ -17,19 +20,10 @@
1720

1821
# Request headers
1922
headers = {
20-
'Accept': '*/*',
21-
'Accept-Encoding': 'gzip, deflate, br, zstd',
22-
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
23-
'Content-Length': '0',
23+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0',
2424
'Origin': 'https://www.nodeseek.com',
2525
'Referer': 'https://www.nodeseek.com/board',
26-
'Sec-CH-UA': '"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
27-
'Sec-CH-UA-Mobile': '?0',
28-
'Sec-CH-UA-Platform': '"Windows"',
29-
'Sec-Fetch-Dest': 'empty',
30-
'Sec-Fetch-Mode': 'cors',
31-
'Sec-Fetch-Site': 'same-origin',
32-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
26+
'Content-Type': 'application/json',
3327
}
3428

3529
# Iterate over multiple account cookies for check-in
@@ -47,7 +41,7 @@
4741
try:
4842
# random=true means get a random bonus
4943
url = 'https://www.nodeseek.com/api/attendance?random=true'
50-
response = requests.post(url, headers=headers, impersonate="chrome110")
44+
response = requests.post(url, headers=headers, impersonate="chrome124")
5145

5246
# Output the status code and response content
5347
print(f"The {idx+1} account's Status Code: {response.status_code}", flush=True)

onepoint3acres/onepoint3acres.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
import requests
77
import http.cookies
88
import time
9+
from dotenv import load_dotenv
910
from .questions import questions
1011
from telegram.notify import send_tg_notification
1112

13+
load_dotenv()
14+
1215
class OnePointThreeAcres:
1316
def __init__(self, cookie: str, solver: TwoCaptcha):
1417
self.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"
@@ -209,8 +212,8 @@ def answer_daily_question(self, question: int, answer: int) -> bool:
209212

210213

211214
if __name__ == "__main__":
212-
cookie = os.environ.get('ONEPOINT3ACRES_COOKIE').strip()
213-
TwoCaptcha_apikey = os.environ.get('TWOCAPTCHA_APIKEY').strip()
215+
cookie = os.environ.get('ONEPOINT3ACRES_COOKIE', '').strip()
216+
TwoCaptcha_apikey = os.environ.get('TWOCAPTCHA_APIKEY', '').strip()
214217

215218
try:
216219
if not cookie:

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
requests
22
2captcha-python
3-
curl_cffi
3+
curl_cffi
4+
python-dotenv

telegram/notify.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import json
44
import os
55
import sys
6+
from dotenv import load_dotenv
7+
8+
load_dotenv()
69

710
# follow the instructions from https://core.telegram.org/bots/features#botfather and get the bot token
8-
TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN').strip()
11+
TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN', '').strip()
912
# add the bot to your contact and send a message to it
1013
# then check the url https://api.telegram.org/bot{TELEGRAM_TOKEN}/getUpdates to get the chat id
11-
TELEGRAM_CHAT_ID = os.environ.get('TELEGRAM_CHAT_ID').strip()
14+
TELEGRAM_CHAT_ID = os.environ.get('TELEGRAM_CHAT_ID', '').strip()
1215

1316
def send_tg_notification(message):
1417
"""Send Telegram notification

v2ex/v2ex.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import os
44
from datetime import datetime, timedelta
55
import sys
6+
from dotenv import load_dotenv
67
from telegram.notify import send_tg_notification
78

8-
cookie = os.environ.get('V2EX_COOKIE').strip()
9+
load_dotenv()
10+
11+
cookie = os.environ.get('V2EX_COOKIE', '').strip()
912
# Initial the message time
1013
time = datetime.now() + timedelta(hours=8)
1114
message = time.strftime("%Y/%m/%d %H:%M:%S") + " from V2EX \n"
@@ -24,7 +27,7 @@
2427
"sec-fetch-user": "?1",
2528
"upgrade-insecure-requests": "1",
2629
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
27-
"cookie": f"'{cookie}'",
30+
"cookie": cookie,
2831
}
2932

3033
def get_once() -> tuple[str, bool]:

0 commit comments

Comments
 (0)