From 5ab5155b4d873f9b376046857a95026b1ffcdeed Mon Sep 17 00:00:00 2001 From: Qubot <1445788683@qq.com> Date: Thu, 20 Jul 2023 17:10:31 +0800 Subject: [PATCH] add getcookies code --- 1.py => GetCookies.py | 0 check | 4 ++- checkin_1.py | 2 +- checkin_2.py | 59 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) rename 1.py => GetCookies.py (100%) create mode 100644 checkin_2.py diff --git a/1.py b/GetCookies.py similarity index 100% rename from 1.py rename to GetCookies.py diff --git a/check b/check index 0d1caaa..e6c369a 100755 --- a/check +++ b/check @@ -1 +1,3 @@ -python3 checkin_1.py +echo $(date) >> /tmp/check.log +echo "签到成功" >> /tmp/check.log +python3 /home/qubot/Checkin/checkin_1.py diff --git a/checkin_1.py b/checkin_1.py index e964d80..38e2bab 100644 --- a/checkin_1.py +++ b/checkin_1.py @@ -45,7 +45,7 @@ flarum_session, x_csrf_token = get_cookies_and_token() # 设置 cookies 和 headers cookies = { - 'flarum_remember': 'JT5tSxOH0QzglSmU67Wq7ici6ecxhIc1U7pEOOOh', + 'flarum_remember': 'ZPojFMvwsmz8fbboYNtIreQ1P8l4tXC8dLmxrJF5', 'flarum_session': flarum_session } diff --git a/checkin_2.py b/checkin_2.py new file mode 100644 index 0000000..e964d80 --- /dev/null +++ b/checkin_2.py @@ -0,0 +1,59 @@ +import requests + +def sign_in(headers, cookies): + data = { + 'data': { + 'type': 'users', + 'attributes': { + 'canCheckin': True, + 'totalContinuousCheckIn': 2 + }, + 'id': '1684' + } + } + + url = 'https://invites.fun/api/users/1684' + + response = requests.post(url, json=data, headers=headers, cookies=cookies) + + if response.status_code == 200: + print('签到成功!') + elif response.status_code == 401: # Unauthorized, indicating expired cookies + print('Cookies已过期,请重新输入。') + new_cookies = input('请输入新的Cookies:') + new_csrf_token = input('请输入新的X-Csrf-Token:') + cookies.update({'flarum_remember': new_cookies}) + headers.update({'X-Csrf-Token': new_csrf_token}) + sign_in(headers, cookies) + else: + print('签到失败。错误码:', response.status_code) + +def get_cookies_and_token(): + url = 'https://invites.fun/' + + response = requests.get(url) + + cookies = response.cookies.get_dict() + flarum_session = cookies.get('flarum_session') + + x_csrf_token = response.headers.get('X-Csrf-Token') + + return flarum_session, x_csrf_token + +# 获取 cookies 和 X-Csrf-Token +flarum_session, x_csrf_token = get_cookies_and_token() + +# 设置 cookies 和 headers +cookies = { + 'flarum_remember': 'JT5tSxOH0QzglSmU67Wq7ici6ecxhIc1U7pEOOOh', + 'flarum_session': flarum_session +} + +headers = { + 'Content-Type': 'application/vnd.api+json', + 'X-Csrf-Token': x_csrf_token, + 'X-Http-Method-Override': 'PATCH' +} + +# 执行签到请求 +sign_in(headers, cookies)