mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-08 12:27:33 +08:00
Add: Update check via github web page
- Add no update check if running multiple alas - Fix enable_update_check not working
This commit is contained in:
parent
c555e926fa
commit
e0241fa470
8
alas.py
8
alas.py
@ -4,9 +4,12 @@ import time
|
||||
from datetime import datetime
|
||||
|
||||
from module.config.config import AzurLaneConfig
|
||||
from module.logger import logger, pyw_name, log_file
|
||||
|
||||
from module.device.device import Device
|
||||
from module.logger import logger, pyw_name, log_file
|
||||
from module.update import Update
|
||||
|
||||
|
||||
Update(AzurLaneConfig()).get_latest_commit()
|
||||
|
||||
|
||||
class AzurLaneAutoScript:
|
||||
@ -168,6 +171,5 @@ class AzurLaneAutoScript:
|
||||
az.device.screenshot()
|
||||
az.retire_ships(amount=2000)
|
||||
|
||||
|
||||
# alas = AzurLaneAutoScript()
|
||||
# alas.reward()
|
||||
|
@ -101,6 +101,7 @@ device_screenshot_method = aScreenCap
|
||||
device_control_method = uiautomator2
|
||||
combat_screenshot_interval = 1.
|
||||
enable_update_check = yes
|
||||
update_method = api
|
||||
update_proxy =
|
||||
github_token =
|
||||
|
||||
|
@ -236,6 +236,7 @@ def main(ini_name=''):
|
||||
|
||||
update = emulator_parser.add_argument_group('更新检查', '')
|
||||
update.add_argument('--启用更新检查', default=default('--启用更新检查'), choices=['是', '否'])
|
||||
update.add_argument('--update_method', default=default('--update_method'), choices=['api', 'web'], help='')
|
||||
update.add_argument('--github_token', default=default('--github_token'), help='To generate your token visit https://github.com/settings/tokens')
|
||||
update.add_argument('--update_proxy', default=default('--update_proxy'), help='Local http or socks proxy, example: http://127.0.0.1:10809')
|
||||
|
||||
|
@ -237,6 +237,7 @@ def main(ini_name=''):
|
||||
|
||||
update = emulator_parser.add_argument_group('ALAS Update Check', '')
|
||||
update.add_argument('--enable_update_check', default=default('--enable_update_check'), choices=['yes', 'no'])
|
||||
update.add_argument('--update_method', default=default('--update_method'), choices=['api', 'web'], help='')
|
||||
update.add_argument('--github_token', default=default('--github_token'), help='To generate your token visit https://github.com/settings/tokens')
|
||||
update.add_argument('--update_proxy', default=default('--update_proxy'), help='Local http or socks proxy, example: http://127.0.0.1:10809')
|
||||
|
||||
|
@ -234,6 +234,7 @@ def main(ini_name=''):
|
||||
|
||||
update = emulator_parser.add_argument_group('ALAS Update Check', '')
|
||||
update.add_argument('--enable_update_check', default=default('--enable_update_check'), choices=['yes', 'no'])
|
||||
update.add_argument('--update_method', default=default('--update_method'), choices=['api', 'web'], help='')
|
||||
update.add_argument('--github_token', default=default('--github_token'), help='To generate your token visit https://github.com/settings/tokens')
|
||||
update.add_argument('--update_proxy', default=default('--update_proxy'), help='Local http or socks proxy, example: http://127.0.0.1:10809')
|
||||
|
||||
|
@ -24,6 +24,7 @@ class AzurLaneConfig:
|
||||
start_time = datetime.now()
|
||||
|
||||
UPDATE_CHECK = True
|
||||
UPDATE_METHOD = 'api' # web, api
|
||||
UPDATE_PROXY = ''
|
||||
GITHUB_TOKEN = ''
|
||||
SERVER = server.server
|
||||
@ -419,8 +420,9 @@ class AzurLaneConfig:
|
||||
self.DEVICE_SCREENSHOT_METHOD = option['device_screenshot_method']
|
||||
self.DEVICE_CONTROL_METHOD = option['device_control_method']
|
||||
self.COMBAT_SCREENSHOT_INTERVAL = float(option['combat_screenshot_interval'])
|
||||
#UpdateCheck
|
||||
# UpdateCheck
|
||||
self.UPDATE_CHECK = to_bool(option['enable_update_check'])
|
||||
self.UPDATE_METHOD = option['update_method']
|
||||
self.UPDATE_PROXY = option['update_proxy']
|
||||
self.GITHUB_TOKEN = option['github_token']
|
||||
|
||||
|
@ -41,6 +41,7 @@ dic_true_eng_to_eng = {
|
||||
'enable_event_ab': 'enable_event_ab',
|
||||
'github_token': 'github_token',
|
||||
'update_proxy': 'update_proxy',
|
||||
'update_method': 'update_method',
|
||||
'enable_update_check': 'enable_update_check',
|
||||
'enable_stop_condition': 'enable_stop_condition',
|
||||
'enable_exception': 'enable_exception',
|
||||
@ -236,6 +237,7 @@ dic_chi_to_eng = {
|
||||
'enable_event_ab': 'enable_event_ab',
|
||||
'github_token': 'github_token',
|
||||
'update_proxy': 'update_proxy',
|
||||
'update_method': 'update_method',
|
||||
'启用更新检查': 'enable_update_check',
|
||||
'启用停止条件': 'enable_stop_condition',
|
||||
'启用异常处理': 'enable_exception',
|
||||
|
@ -4,9 +4,11 @@ import subprocess
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
from lxml import etree
|
||||
|
||||
from module.config.config import AzurLaneConfig
|
||||
from module.logger import logger
|
||||
from module.logger import logger, pyw_name
|
||||
from module.base.decorator import Config
|
||||
|
||||
|
||||
class Update:
|
||||
@ -21,6 +23,11 @@ class Update:
|
||||
def github_api(author, token):
|
||||
return f'https://api.github.com/repos/{author}/AzurLaneAutoScript/commits?access_token={token}'
|
||||
|
||||
@staticmethod
|
||||
def github_commit(author):
|
||||
return f'https://github.com/{author}/AzurLaneAutoScript/commits/master'
|
||||
|
||||
@Config.when(UPDATE_METHOD='api')
|
||||
def get_github_commit(self, author, token=None, proxy=None):
|
||||
"""
|
||||
Args:
|
||||
@ -35,6 +42,8 @@ class Update:
|
||||
if proxy:
|
||||
proxy = {'http': proxy, 'https': proxy}
|
||||
resp = requests.get(self.github_api(author, token), proxies=proxy)
|
||||
if resp.status_code != 200:
|
||||
logger.warning(f'{resp.status_code} {self.github_commit(author)}')
|
||||
resp.encoding = 'utf-8'
|
||||
data = json.loads(resp.content)
|
||||
|
||||
@ -48,6 +57,37 @@ class Update:
|
||||
|
||||
logger.warning(f'No commit found. author={author}')
|
||||
|
||||
@Config.when(UPDATE_METHOD='web')
|
||||
def get_github_commit(self, author, token=None, proxy=None):
|
||||
"""
|
||||
Args:
|
||||
author (str):
|
||||
token (str): To generate your token visit https://github.com/settings/tokens
|
||||
proxy (str): Local http or socks proxy, example: http://127.0.0.1:10809, socks://127.0.0.1:10808
|
||||
Need to install requests[socks], if using a socks proxy.
|
||||
|
||||
Returns:
|
||||
datetime.datetime, str
|
||||
"""
|
||||
if proxy:
|
||||
proxy = {'http': proxy, 'https': proxy}
|
||||
resp = requests.get(self.github_commit(author), proxies=proxy)
|
||||
if resp.status_code != 200:
|
||||
logger.warning(f'{resp.status_code} {self.github_commit(author)}')
|
||||
resp.encoding = 'utf-8'
|
||||
|
||||
tree = etree.HTML(resp.content)
|
||||
message_list = tree.xpath('//a[contains(@class, "message")]/text()')
|
||||
date_list = tree.xpath('//relative-time/@datetime')
|
||||
pattern = re.compile('^[Mm]erge')
|
||||
for message, date in zip(message_list, date_list):
|
||||
if re.search(pattern, message):
|
||||
continue
|
||||
|
||||
date = datetime.strptime(date, '%Y-%m-%dT%H:%M:%SZ')
|
||||
return date, author
|
||||
logger.warning(f'No commit found. author={author}')
|
||||
|
||||
@staticmethod
|
||||
def get_local_commit():
|
||||
"""
|
||||
@ -75,6 +115,9 @@ class Update:
|
||||
2020-06-20_10:12:19 whoamikyo
|
||||
new: 2020-06-20_11:12:19 LmeSzinc
|
||||
"""
|
||||
if pyw_name != 'alas' or not self.config.UPDATE_CHECK:
|
||||
# Disable when using multiple Alas.
|
||||
return False
|
||||
|
||||
logger.hr('Update Check')
|
||||
commits = [
|
||||
@ -96,9 +139,3 @@ class Update:
|
||||
|
||||
if commits[-1][1] != '<local>':
|
||||
logger.warning('A new update is available')
|
||||
|
||||
|
||||
cfg = AzurLaneConfig()
|
||||
cfg.UPDATE_PROXY = ''
|
||||
update = Update(cfg)
|
||||
update.get_latest_commit()
|
||||
|
Loading…
Reference in New Issue
Block a user