Skip to content

Commit

Permalink
feat: aliyunpan refresh token support shell qrcode
Browse files Browse the repository at this point in the history
  • Loading branch information
DDSRem committed Nov 30, 2024
1 parent 3ec670d commit 42bb8c9
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 20 deletions.
47 changes: 41 additions & 6 deletions glue_python/aliyuntoken/aliyuntoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import os
import threading
import sys
import qrcode
import argparse
from PIL import Image
import pyzbar.pyzbar as pyzbar
from io import BytesIO
from flask import Flask, send_file, render_template, jsonify

Expand Down Expand Up @@ -39,7 +42,7 @@
}


def poll_qrcode_status(data):
def poll_qrcode_status(data, log_print):
global last_status
while True:
re = requests.post('https://api.xhofe.top/alist/ali/ck', json=data, headers=headers)
Expand All @@ -59,10 +62,18 @@ def poll_qrcode_status(data):
last_status = 1
break
else:
logging.info('等待用户扫码...')
if log_print:
logging.info('等待用户扫码...')
time.sleep(2)


def decode_qr_code(qr_code_image_path):
img = Image.open(qr_code_image_path)
decoded_objects = pyzbar.decode(img)
for obj in decoded_objects:
return obj.data.decode('utf-8')


@app.route("/")
def index():
return render_template('index.html')
Expand Down Expand Up @@ -93,7 +104,11 @@ def shutdown():
if __name__ == '__main__':
if os.path.isfile(qrcode_dir):
os.remove(qrcode_dir)
parser = argparse.ArgumentParser(description='AliyunPan Refresh Token')
parser.add_argument('--qrcode_mode', type=str, help='扫码模式')
args = parser.parse_args()
logging.info('二维码生成中...')
re_count = 0
while True:
re = requests.get('https://api.xhofe.top/alist/ali/qr', headers=headers)
if re.status_code == 200:
Expand All @@ -111,7 +126,27 @@ def shutdown():
if os.path.isfile(qrcode_dir):
logging.info('二维码生成完成!')
break
else:
time.sleep(1)
threading.Thread(target=poll_qrcode_status, args=(data,)).start()
app.run(host='0.0.0.0', port=34256)
time.sleep(1)
re_count += 1
if re_count == 3:
logging.error('二维码生成失败,退出进程')
os._exit(1)
if args.qrcode_mode == 'web':
threading.Thread(target=poll_qrcode_status, args=(data, True)).start()
app.run(host='0.0.0.0', port=34256)
elif args.qrcode_mode == 'shell':
threading.Thread(target=poll_qrcode_status, args=(data, False)).start()
decoded_data = decode_qr_code(qrcode_dir)
qr = qrcode.QRCode(border=1)
qr.add_data(decoded_data)
qr.make(fit=True)
qr.make_image(fill_color="black", back_color="white")
qr.print_ascii(invert=True, tty=sys.stdout.isatty())
while last_status != 1:
time.sleep(1)
if os.path.isfile(qrcode_dir):
os.remove(qrcode_dir)
os._exit(0)
else:
logging.error('未知的扫码模式')
os._exit(1)
47 changes: 41 additions & 6 deletions glue_python/aliyuntoken/aliyuntoken_nn.ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import os
import threading
import sys
import qrcode
import argparse
from PIL import Image
import pyzbar.pyzbar as pyzbar
from io import BytesIO
from flask import Flask, send_file, render_template, jsonify

Expand All @@ -22,7 +25,7 @@
qrcode_dir= '/aliyuntoken/qrcode.png'


def poll_qrcode_status(data):
def poll_qrcode_status(data, log_print):
global last_status
while True:
re = requests.post('https://api-cf.nn.ci/alist/ali/ck', json=data)
Expand All @@ -42,10 +45,18 @@ def poll_qrcode_status(data):
last_status = 1
break
else:
logging.info('等待用户扫码...')
if log_print:
logging.info('等待用户扫码...')
time.sleep(2)


def decode_qr_code(qr_code_image_path):
img = Image.open(qr_code_image_path)
decoded_objects = pyzbar.decode(img)
for obj in decoded_objects:
return obj.data.decode('utf-8')


@app.route("/")
def index():
return render_template('index.html')
Expand Down Expand Up @@ -76,7 +87,11 @@ def shutdown():
if __name__ == '__main__':
if os.path.isfile(qrcode_dir):
os.remove(qrcode_dir)
parser = argparse.ArgumentParser(description='AliyunPan Refresh Token')
parser.add_argument('--qrcode_mode', type=str, help='扫码模式')
args = parser.parse_args()
logging.info('二维码生成中...')
re_count = 0
while True:
re = requests.get('https://api-cf.nn.ci/alist/ali/qr')
if re.status_code == 200:
Expand All @@ -94,7 +109,27 @@ def shutdown():
if os.path.isfile(qrcode_dir):
logging.info('二维码生成完成!')
break
else:
time.sleep(1)
threading.Thread(target=poll_qrcode_status, args=(data,)).start()
app.run(host='0.0.0.0', port=34256)
time.sleep(1)
re_count += 1
if re_count == 3:
logging.error('二维码生成失败,退出进程')
os._exit(1)
if args.qrcode_mode == 'web':
threading.Thread(target=poll_qrcode_status, args=(data, True)).start()
app.run(host='0.0.0.0', port=34256)
elif args.qrcode_mode == 'shell':
threading.Thread(target=poll_qrcode_status, args=(data, False)).start()
decoded_data = decode_qr_code(qrcode_dir)
qr = qrcode.QRCode(border=1)
qr.add_data(decoded_data)
qr.make(fit=True)
qr.make_image(fill_color="black", back_color="white")
qr.print_ascii(invert=True, tty=sys.stdout.isatty())
while last_status != 1:
time.sleep(1)
if os.path.isfile(qrcode_dir):
os.remove(qrcode_dir)
os._exit(0)
else:
logging.error('未知的扫码模式')
os._exit(1)
50 changes: 43 additions & 7 deletions glue_python/aliyuntoken/aliyuntoken_vercel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import os
import threading
import sys
import qrcode
import argparse
from PIL import Image
import pyzbar.pyzbar as pyzbar
import io
from flask import Flask, send_file, render_template, jsonify

Expand All @@ -22,7 +25,7 @@
qrcode_dir= '/aliyuntoken/qrcode.png'


def poll_qrcode_status(data):
def poll_qrcode_status(data, log_print):
global last_status
ck = str(data['ck'])
t = str(data['t'])
Expand All @@ -42,10 +45,18 @@ def poll_qrcode_status(data):
last_status = 1
break
else:
logging.info('等待用户扫码...')
if log_print:
logging.info('等待用户扫码...')
time.sleep(2)


def decode_qr_code(qr_code_image_path):
img = Image.open(qr_code_image_path)
decoded_objects = pyzbar.decode(img)
for obj in decoded_objects:
return obj.data.decode('utf-8')


@app.route("/")
def index():
return render_template('index.html')
Expand Down Expand Up @@ -76,8 +87,12 @@ def shutdown():
if __name__ == '__main__':
if os.path.isfile(qrcode_dir):
os.remove(qrcode_dir)
parser = argparse.ArgumentParser(description='AliyunPan Refresh Token')
parser.add_argument('--qrcode_mode', type=str, help='扫码模式')
args = parser.parse_args()
logging.info('二维码生成中...')
re_count = 0
while True:
logging.info('二维码生成中...')
re = requests.get('https://aliyuntoken.vercel.app/api/generate?img=true')
if re.status_code == 200:
re_data = json.loads(re.content)
Expand All @@ -91,7 +106,28 @@ def shutdown():
if os.path.isfile(qrcode_dir):
logging.info('二维码生成完成!')
break
else:
time.sleep(1)
threading.Thread(target=poll_qrcode_status, args=(data,)).start()
app.run(host='0.0.0.0', port=34256)
time.sleep(1)
re_count += 1
if re_count == 3:
logging.error('二维码生成失败,退出进程')
os._exit(1)
if args.qrcode_mode == 'web':
threading.Thread(target=poll_qrcode_status, args=(data, True)).start()
app.run(host='0.0.0.0', port=34256)
elif args.qrcode_mode == 'shell':
threading.Thread(target=poll_qrcode_status, args=(data, False)).start()
decoded_data = decode_qr_code(qrcode_dir)
qr = qrcode.QRCode(border=1)
qr.add_data(decoded_data)
qr.make(fit=True)
qr.make_image(fill_color="black", back_color="white")
qr.print_ascii(invert=True, tty=sys.stdout.isatty())
while last_status != 1:
time.sleep(1)
if os.path.isfile(qrcode_dir):
os.remove(qrcode_dir)
os._exit(0)
else:
logging.error('未知的扫码模式')
os._exit(1)

4 changes: 3 additions & 1 deletion glue_python/aliyuntoken/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
flask
pillow
pillow
pyzbar
requests

0 comments on commit 42bb8c9

Please sign in to comment.