Skip to content

Commit

Permalink
update 1.0.4 version
Browse files Browse the repository at this point in the history
  • Loading branch information
ackness committed Nov 18, 2021
1 parent d5827e4 commit 84441aa
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ dmypy.json
auto-connect.log
release/*

.idea/*
.idea
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SZU Auto Connect

![web](https://img.shields.io/badge/SZU--AutoConnect-v1.0.3-green)
![web](https://img.shields.io/badge/SZU--AutoConnect-v1.0.4-green)

![web](https://img.shields.io/badge/Python-≥3.6-blue)

Expand All @@ -21,7 +21,7 @@
## 2.1 下载 exe 文件运行

前往 [Release](https://github.com/ackness/szu-autoconnect/releases) 下载所有版本,
或者 [点击直接下载 V1.0.3 版本](https://github.com/ackness/szu-autoconnect/releases/download/v1.0.3/SZU-AutoConnect-V1.0.3.exe).
或者 [点击直接下载 V1.0.4 版本](https://github.com/ackness/szu-autoconnect/releases/download/v1.0.4/SZU-AutoConnect-V1.0.4.exe). (暂时没更新, 有需要自己可以打包, 见2.3.3)

## 2.2 从 pip 安装与运行

Expand Down Expand Up @@ -116,7 +116,7 @@ python -m pysimplegui-exemaker.pysimplegui-exemaker

# 3. 原理

使用构造`POST 表单`完成上网请求, 和直接在网页端登录是一样的.
使用构造 `POST 表单` 完成上网请求, 和直接在网页端登录是一样的.


# 4. 前人的肩膀
Expand Down
Binary file modified _assets/ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='szu-autoconnect',
packages=find_packages(),
version='1.0.3',
version='1.0.4',
license='MIT',
description='A simple way to get different DEXs abis for block chains.',
author='Yong',
Expand Down
5 changes: 5 additions & 0 deletions szu_autoconnect/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from szu_autoconnect.core import auto, ui
from szu_autoconnect.run import run


if __name__ == '__main__':
run()
42 changes: 29 additions & 13 deletions szu_autoconnect/core/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,47 @@ def set_config(self, config: dict):
"OMKKey": "123456"
}
self.interval = config['interval']
logger.info(f"Auto-Connect Load config {config}")
print_config = config
# hide password
print_config['password'] = config['password'][:2] + '***' + config['password'][-2:]
logger.info(f"Auto-Connect Load config {print_config}")
except KeyError as e:
logger.error(f'Please check the config, {e}')

def connect(self):
# requests.packages.urllib3.disable_warnings()
session = requests.session()
r = session.post(self.login_url, headers=self.headers, data=self.data_send, verify=False)
logger.info("Posted")
# print(r.text)

# def check_connect(self):
# s = socket.socket()
# s.settimeout(3)
# try:
# status = s.connect_ex((self.ping_ip, 443))
# if status == 0:
# s.close()
# logger.info("Connected")
# return True
# else:
# logger.info("Disconnected")
# raise DisconnectError
# # return False
# except Exception as e:
# logger.error(f'Find Error in check connect, {e}')
# raise DisconnectError

def check_connect(self):
s = socket.socket()
s.settimeout(3)
timeout = 5
try:
status = s.connect_ex((self.ping_ip, 443))
if status == 0:
s.close()
logger.info("Connected")
return True
else:
logger.info("Disconnected")
raise DisconnectError
# return False
ping_ip = "https://" + self.ping_ip
request = requests.get(ping_ip, timeout=timeout)
logger.info("Connected")
return True
# except (requests.ConnectionError, requests.Timeout) as e:
except Exception as e:
logger.error(f'Find Error in check connect, {e}')
logger.error(f'Disconnected, Error [{e}]')
raise DisconnectError

def stop(self):
Expand Down
92 changes: 72 additions & 20 deletions szu_autoconnect/core/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'interval': 20,
'pin': True,
}

# "Map" from the settings dictionary keys to the window's element keys
SETTINGS_KEYS_TO_ELEMENT_KEYS = {
'username': '-username-',
Expand Down Expand Up @@ -74,11 +75,35 @@ def start_work(scheduler):
scheduler.start()


# Temp definitions of the Window methods added to 4.46.0.7 of PySimpleGUI
def keep_on_top_set(window):
"""
Sets keep_on_top after a window has been created. Effect is the same
as if the window was created with this set. The Window is also brought
to the front
"""
window.KeepOnTop = True
window.bring_to_front()
window.TKroot.wm_attributes("-topmost", 1)


def keep_on_top_clear(window):
"""
Clears keep_on_top after a window has been created. Effect is the same
as if the window was created with this set.
"""
window.KeepOnTop = False
window.TKroot.wm_attributes("-topmost", 0)


def create_ui(settings):
sg.theme('Topanga')
title_font = ('Gigi', 18)
config_name_font = ('宋体', 10)
log_font = ('宋体', 9)
# config_name_font = ('宋体', 10)
# log_font = ('宋体', 9)
config_name_font = ('Courier', 10)
log_font = ('Courier', 9)
PIN = '📌'

bar = [
[
Expand All @@ -91,8 +116,11 @@ def create_ui(settings):
sg.Col(
[
[
sg.Check('Pin', enable_events=True, key='-pin-'),
# sg.Check(PIN, enable_events=True, key='-pin-'),
sg.Text(PIN, enable_events=True, k='-pin-', font='_ 12', pad=(0,0), metadata=False,
text_color='yellow', background_color=sg.theme_background_color()),
sg.Text(sg.SYMBOL_X, enable_events=True, key='-X-') # '❎'

]
],
element_justification='r', grab=True, pad=(0, 0), expand_x=True)
Expand All @@ -106,26 +134,33 @@ def create_ui(settings):
]

author_ui = [
sg.Text('作者: 红领巾二号', text_color='red', font=config_name_font, size=(38, 1), justification='right')
# sg.Text('作者: 红领巾二号', text_color='red', font=config_name_font, size=(38, 1), justification='right')
sg.Text('Author: Mr. Red Scarf No.2', text_color='red', font=config_name_font, size=(38, 1), justification='right')
]

config_ui = [sg.Frame(
layout=[
[
sg.Text('网络选择: ', font=config_name_font, size=(10, 1)),
sg.Radio('教学区', key='-office-', group_id='zone', default=True),
sg.Radio('宿舍区', key='-dormitory-', group_id='zone')
# sg.Text('网络选择: ', font=config_name_font, size=(10, 1)),
# sg.Radio('教学区', key='-office-', group_id='zone', default=True),
# sg.Radio('宿舍区', key='-dormitory-', group_id='zone')
sg.Text('Zone: ', font=config_name_font, size=(12, 1)),
sg.Radio('office', key='-office-', group_id='zone', default=True),
sg.Radio('dormitory', key='-dormitory-', group_id='zone')
],
[
sg.Text('用户名: ', font=config_name_font, size=(10, 1)),
# sg.Text('用户名: ', font=config_name_font, size=(10, 1)),
sg.Text('Username: ', font=config_name_font, size=(12, 1)),
sg.In(key='-username-', size=(25, 1))
],
[
sg.Text('密码: ', font=config_name_font, size=(10, 1)),
# sg.Text('密码: ', font=config_name_font, size=(10, 1)),
sg.Text('Password: ', font=config_name_font, size=(12, 1)),
sg.In(key='-password-', size=(25, 1), password_char='*')
],
[
sg.Text('间隔(s): ', font=config_name_font, size=(10, 1)),
# sg.Text('间隔(s): ', font=config_name_font, size=(10, 1)),
sg.Text('Interval(s): ', font=config_name_font, size=(12, 1)),
sg.Spin(values=[i for i in range(1, 1000)], initial_value=10, key='-interval-', size=(23, 1))
]
],
Expand All @@ -135,26 +170,27 @@ def create_ui(settings):
log_ui = [sg.Frame(
layout=[
[
sg.MLine('', key='log', size=(40, 8), font=log_font)
sg.MLine('', key='log', size=(38, 8), font=log_font)
]
],
title='Logs'
)]

tail_ui = [
sg.Button("Login", size=(7, 1)),
sg.Save(size=(7, 1)),
sg.Button("Login", size=(8, 1)),
sg.Save(size=(8, 1)),
sg.Button('Pause', size=(7, 1)),
sg.Exit(size=(6, 1))
sg.Exit(size=(7, 1))
]

total_ui = [bar, title_ui, author_ui, config_ui, tail_ui, log_ui, ]

# return sg.Window('* SZU Auto Connector *', layout=total_ui, font='Helvetica 10', )

window = sg.Window('* SZU Auto Connector *', layout=total_ui, font='Helvetica 10',
no_titlebar=True, finalize=True, keep_on_top=settings['pin']
)
window = sg.Window(
'* SZU Auto Connector *', layout=total_ui, font='Helvetica 10',
no_titlebar=True, finalize=True, resizable=True, margins=(0,0), keep_on_top=settings['pin']
)

for k, v in SETTINGS_KEYS_TO_ELEMENT_KEYS.items(): # update window with the values read from settings file
try:
Expand All @@ -166,6 +202,12 @@ def create_ui(settings):


def main_loop():

if 'keep_on_top_set' not in dir(sg.Window):
# print('You do not have a PySimpleGUI version with required methods. Using the temp ones from this file.')
sg.Window.keep_on_top_set = keep_on_top_set
sg.Window.keep_on_top_clear = keep_on_top_clear

window, settings = None, load_settings(SETTINGS_FILE, DEFAULT_SETTINGS)
scheduler = None
pause_flag = None
Expand Down Expand Up @@ -224,9 +266,19 @@ def main_loop():
break

if event == '-pin-':
window.close()
window = None
settings['pin'] = values['-pin-']
window['-pin-'].metadata = not window['-pin-'].metadata # use metadata to store current state of pin
if window['-pin-'].metadata:
window['-pin-'].update(text_color='red')
window.keep_on_top_set()
else:
window['-pin-'].update(text_color='yellow')
window.keep_on_top_clear()

# if event == '-pin-':
# window.close()
# window = None
# settings['pin'] = values['-pin-']


window.close()

Expand Down
1 change: 1 addition & 0 deletions szu_autoconnect/settings.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"username": "", "password": "", "office": true, "dormitory": false, "interval": 20, "pin": true}

0 comments on commit 84441aa

Please sign in to comment.