├── README.md ├── config.py ├── browser.py ├── LICENSE ├── win32.py ├── main.py ├── utils.py └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # SgsDaily 2 | 三国杀脚本做每日(逐鹿5次) 3 | 4 | 平台:Windows 5 | 使用浏览器: Chrome 6 | 需要库:win32api、selenium 7 | 8 | usage: main.py [-h] [-l LOOP_TIMES] username password 9 | 10 | 每日设置方法:Windows计划任务 11 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | __all__ = ['default_width' ,'default_height', 2 | 'battle_interval', 'operation_interval', 'page_load_interval', 3 | 'chrome_appendix', 'chrome_render_hwnd', 'game_url'] 4 | 5 | default_width = 1200 6 | default_height = 800 7 | 8 | battle_interval = 120.0 9 | operation_interval = 3.0 10 | page_load_interval = 20.0 11 | 12 | chrome_appendix = ' - Google Chrome' 13 | chrome_render_hwnd = 'Chrome_RenderWidgetHostHWND' 14 | game_url = 'http://web.sanguosha.com/login/index.html' 15 | -------------------------------------------------------------------------------- /browser.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | from config import * 6 | 7 | __all__ = ['OpenGame', 'QuitGame'] 8 | 9 | def OpenGame(url, username, password): 10 | driver = webdriver.Chrome() 11 | driver.get(url) 12 | title = driver.title 13 | username_input, password_input = driver.find_elements(By.CLASS_NAME, 'dobest_input') 14 | username_input.send_keys(username) 15 | password_input.send_keys(password) 16 | driver.find_element(By.CLASS_NAME, 'mycheckbox').click() 17 | driver.find_element(By.CLASS_NAME, 'dobest_de_btn').click() 18 | time.sleep(operation_interval) 19 | 20 | driver.find_element(By.CSS_SELECTOR, '.new_ser1:nth-child(2)').click() 21 | driver.find_element(By.ID, "newGoInGame").click() 22 | time.sleep(page_load_interval) 23 | return driver, title 24 | 25 | def QuitGame(driver): 26 | driver.quit() 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 江春源 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /win32.py: -------------------------------------------------------------------------------- 1 | import time 2 | import win32api, win32con, win32gui 3 | 4 | __all__ = ['FindWindow', 'RestoreWindow', 'SetWindowPos', 'EnumChildWindows', 'LButtonClick'] 5 | 6 | FindWindow = lambda classname, title: win32gui.FindWindow(classname, title) 7 | 8 | RestoreWindow = lambda hwnd: win32gui.ShowWindow(hwnd, win32con.SW_RESTORE) 9 | 10 | SetWindowPos = lambda hwnd, x, y, width, height: win32gui.SetWindowPos(hwnd, win32con.HWND_BOTTOM, x, y, width, height, win32con.SWP_SHOWWINDOW) 11 | 12 | def EnumChildWindows(hwnd): 13 | result = {} 14 | def enum_proc(hwnd, lParam): 15 | classname = win32gui.GetClassName(hwnd) 16 | lParam[classname] = hwnd 17 | return True 18 | win32gui.EnumChildWindows(hwnd, enum_proc, result) 19 | return result 20 | 21 | _PostMessage = lambda hwnd, msg, wParam, lParam: win32api.PostMessage(hwnd, msg, wParam, lParam) 22 | 23 | _LButtonDown = lambda hwnd, x, y: _PostMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, win32api.MAKELONG(x, y)) 24 | 25 | _LButtonUp = lambda hwnd, x, y: _PostMessage(hwnd, win32con.WM_LBUTTONUP, 0, win32api.MAKELONG(x, y)) 26 | 27 | def LButtonClick(hwnd, x, y): 28 | _LButtonDown(hwnd, x, y) 29 | time.sleep(0.1) 30 | _LButtonUp(hwnd, x, y) 31 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import argparse, sys 2 | 3 | if sys.platform not in ['win32']: 4 | raise OSError('Only have Implement on Windows Now') 5 | 6 | from browser import * 7 | from config import * 8 | from utils import * 9 | from win32 import * 10 | 11 | parser = argparse.ArgumentParser() 12 | parser.add_argument('username', help='用户名', type=str) 13 | parser.add_argument('password', help='密码', type=str) 14 | parser.add_argument('-l', '--loop_times', help='日常循环次数', default=5, type=int) 15 | args = parser.parse_args() 16 | 17 | print('用户名:{0}'.format(args.username)) 18 | print('密码:{0}'.format(args.password)) 19 | print('日常循环次数:{0}'.format(args.loop_times)) 20 | 21 | def main(): 22 | driver, title = OpenGame(game_url, args.username, args.password) 23 | 24 | sgs_chrome_hwnd = FindWindow(None, title + chrome_appendix) 25 | RestoreWindow(sgs_chrome_hwnd) 26 | SetWindowPos(sgs_chrome_hwnd, 0, 0, default_width, default_height) 27 | sgs_chrome_children_hwnds = EnumChildWindows(sgs_chrome_hwnd) 28 | sgs_host_hwnd = sgs_chrome_children_hwnds[chrome_render_hwnd] 29 | 30 | QuitLogoAndActivity(sgs_host_hwnd) 31 | Daily(sgs_host_hwnd, args.loop_times) 32 | 33 | QuitGame(driver) 34 | 35 | if __name__ == '__main__': 36 | main() 37 | -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from win32 import * 4 | from config import * 5 | 6 | __all__ = ['Daily', 'QuitLogoAndActivity'] 7 | 8 | def Daily(hwnd, loop_times): 9 | '''每日(逐鹿)''' 10 | LButtonClick(hwnd, 815, 432) # 进逐鹿 11 | time.sleep(operation_interval) 12 | 13 | LButtonClick(hwnd, 450, 50) # 跳过动画 14 | print('已进入逐鹿') 15 | time.sleep(operation_interval) 16 | 17 | LButtonClick(hwnd, 628, 44) # 困难 18 | print('已进入困难') 19 | time.sleep(operation_interval) 20 | 21 | LButtonClick(hwnd, 155, 240) # 第一章 22 | print('已进入第一章') 23 | time.sleep(operation_interval) 24 | 25 | # 打逐鹿 26 | for i in range(loop_times): 27 | print('开始第{0}次'.format(i + 1)) 28 | LButtonClick(hwnd, 385, 240) # 第一城 29 | time.sleep(operation_interval) 30 | 31 | LButtonClick(hwnd, 1085, 400) # 第五关 32 | time.sleep(operation_interval) 33 | 34 | LButtonClick(hwnd, 950, 570) # 进入挑战 35 | time.sleep(operation_interval) 36 | 37 | if i == 0: 38 | # 开5倍速 39 | for j in range(4): 40 | LButtonClick(hwnd, 100, 512) # 加速 41 | time.sleep(operation_interval) 42 | time.sleep(battle_interval) 43 | 44 | LButtonClick(hwnd, 550, 300) # 退出 45 | print('结束第{0}次'.format(i + 1)) 46 | time.sleep(operation_interval) 47 | 48 | def QuitLogoAndActivity(hwnd): 49 | '''关闭logo和活动''' 50 | time.sleep(operation_interval) 51 | LButtonClick(hwnd, 930, 158) # 关logo 52 | time.sleep(operation_interval) 53 | 54 | LButtonClick(hwnd, 1105, 88) # 关活动 55 | time.sleep(operation_interval) 56 | 57 | LButtonClick(hwnd, 450, 50) # 关莫名其妙的卡屏 58 | time.sleep(operation_interval) 59 | 60 | LButtonClick(hwnd, 450, 50) 61 | time.sleep(operation_interval) 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | --------------------------------------------------------------------------------