Skip to content

Commit

Permalink
Revert "feat: aliyunpan refresh token support shell qrcode"
Browse files Browse the repository at this point in the history
This reverts commit 42bb8c9.
  • Loading branch information
DDSRem committed Nov 30, 2024
1 parent 02a3bd4 commit 84a9402
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 128 deletions.
47 changes: 6 additions & 41 deletions glue_python/aliyuntoken/aliyuntoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
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 @@ -42,7 +39,7 @@
}


def poll_qrcode_status(data, log_print):
def poll_qrcode_status(data):
global last_status
while True:
re = requests.post('https://api.xhofe.top/alist/ali/ck', json=data, headers=headers)
Expand All @@ -62,18 +59,10 @@ def poll_qrcode_status(data, log_print):
last_status = 1
break
else:
if log_print:
logging.info('等待用户扫码...')
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 @@ -104,11 +93,7 @@ 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 @@ -126,27 +111,7 @@ def shutdown():
if os.path.isfile(qrcode_dir):
logging.info('二维码生成完成!')
break
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)
else:
time.sleep(1)
threading.Thread(target=poll_qrcode_status, args=(data,)).start()
app.run(host='0.0.0.0', port=34256)
47 changes: 6 additions & 41 deletions glue_python/aliyuntoken/aliyuntoken_nn.ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
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 @@ -25,7 +22,7 @@
qrcode_dir= '/aliyuntoken/qrcode.png'


def poll_qrcode_status(data, log_print):
def poll_qrcode_status(data):
global last_status
while True:
re = requests.post('https://api-cf.nn.ci/alist/ali/ck', json=data)
Expand All @@ -45,18 +42,10 @@ def poll_qrcode_status(data, log_print):
last_status = 1
break
else:
if log_print:
logging.info('等待用户扫码...')
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 @@ -87,11 +76,7 @@ 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 @@ -109,27 +94,7 @@ def shutdown():
if os.path.isfile(qrcode_dir):
logging.info('二维码生成完成!')
break
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)
else:
time.sleep(1)
threading.Thread(target=poll_qrcode_status, args=(data,)).start()
app.run(host='0.0.0.0', port=34256)
50 changes: 7 additions & 43 deletions glue_python/aliyuntoken/aliyuntoken_vercel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
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 @@ -25,7 +22,7 @@
qrcode_dir= '/aliyuntoken/qrcode.png'


def poll_qrcode_status(data, log_print):
def poll_qrcode_status(data):
global last_status
ck = str(data['ck'])
t = str(data['t'])
Expand All @@ -45,18 +42,10 @@ def poll_qrcode_status(data, log_print):
last_status = 1
break
else:
if log_print:
logging.info('等待用户扫码...')
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 @@ -87,12 +76,8 @@ 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 @@ -106,28 +91,7 @@ def shutdown():
if os.path.isfile(qrcode_dir):
logging.info('二维码生成完成!')
break
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)

else:
time.sleep(1)
threading.Thread(target=poll_qrcode_status, args=(data,)).start()
app.run(host='0.0.0.0', port=34256)
4 changes: 1 addition & 3 deletions glue_python/aliyuntoken/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
flask
pillow
pyzbar
requests
pillow

0 comments on commit 84a9402

Please sign in to comment.