Skip to content

Commit

Permalink
Merge pull request #368 from EightyDollars/dev_shawn
Browse files Browse the repository at this point in the history
fix:存储路径读取方式修改
  • Loading branch information
ZhaoZuohong authored Nov 4, 2023
2 parents 5b1814b + 5da9785 commit f7f5064
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 53 deletions.
36 changes: 22 additions & 14 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,28 @@ def simulate():
set_recruit_options(base_scheduler, new_conf)
set_skland_options(base_scheduler, new_conf)

if sleep_time > 540 and base_scheduler.maa_config["maa_enable"] == 1:
subject = (
f"下次任务在{base_scheduler.tasks[0].time.strftime('%H:%M:%S')}"
)
context = f"下一次任务:{base_scheduler.tasks[0].plan}"
logger.info(context)
logger.info(subject)
body = task_template.render(
tasks=[
obj.format(timezone_offset) for obj in base_scheduler.tasks
]
)
base_scheduler.send_message(body, subject, "html")
base_scheduler.maa_plan_solver()
if sleep_time > 540:
if base_scheduler.daily_mission is False:
base_scheduler.daily_mission = base_scheduler.read_report()
base_scheduler.mail_plan_solver()
if base_scheduler.skland_config["skland_enable"] == 1:
base_scheduler.skland_plan_solover()
if base_scheduler.recruit_config['recruit_enable'] == 1:
base_scheduler.recruit_plan_solver()
if base_scheduler.maa_config["maa_enable"] == 1:
subject = (
f"下次任务在{base_scheduler.tasks[0].time.strftime('%H:%M:%S')}"
)
context = f"下一次任务:{base_scheduler.tasks[0].plan}"
logger.info(context)
logger.info(subject)
body = task_template.render(
tasks=[
obj.format(timezone_offset) for obj in base_scheduler.tasks
]
)
base_scheduler.send_message(body, subject, "html")
base_scheduler.maa_plan_solver()
elif sleep_time > 0:
subject = f"休息 {format_time(remaining_time)},到{base_scheduler.tasks[0].time.strftime('%H:%M:%S')}开始工作"
context = f"下一次任务:{base_scheduler.tasks[0].plan}"
Expand Down
2 changes: 1 addition & 1 deletion arknights_mower/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def recruit(args: list[str] = [], send_message_config={}, recruit_config={}, dev


def daily_report(device: Device = None):
ReportSolver(device).run()
return ReportSolver(device).run()


def mission(args: list[str] = [], device: Device = None):
Expand Down
31 changes: 13 additions & 18 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from email.mime.multipart import MIMEMultipart

from .skland import SKLand
from ..command import recruit, daily_report
from ..command import recruit, daily_report, mail
from ..data import agent_list, base_room_list, ocr_error
from ..utils import character_recognize, detector, segment
from ..utils.digit_reader import DigitReader
Expand Down Expand Up @@ -92,9 +92,10 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None:
self.refresh_connecting = False
self.recruit_config = {}
self.skland_config = {}
self.sk_time = None

self.recruit_time = None

self.daily_mission = False
def run(self) -> None:
"""
:param clue_collect: bool, 是否收取线索
Expand Down Expand Up @@ -2292,26 +2293,12 @@ def maa_plan_solver(self, tasks='All', one_time=False):
seconds=self.maa_config['maa_execution_gap'] * 3600) < self.maa_config['last_execution']:
logger.info("间隔未超过设定时间,不启动maa")
else:
daily_report()

"""森空岛签到"""
try:
if self.skland_config['skland_enable']:
skland = SKLand(self.skland_config['skland_info'])
skland.attendance()
except RuntimeError as e:
logger.info("森空岛签到失败:{}".format(e.__str__()))

"""测试公招用"""
if self.recruit_config['recruit_enable']:
recruit([], self.send_message_config, self.recruit_config)

self.send_message('启动MAA')
self.back_to_index()
# 任务及参数请参考 docs/集成文档.md
self.initialize_maa()
if tasks == 'All':
tasks = ['StartUp','Fight', 'Visit', 'Mall', 'Award','Depot']
tasks = ['StartUp', 'Fight', 'Visit', 'Mall', 'Award', 'Depot']
# tasks = ['StartUp', 'Fight', 'Recruit', 'Visit', 'Mall', 'Award']
for maa_task in tasks:
if maa_task == 'Recruit':
Expand Down Expand Up @@ -2466,4 +2453,12 @@ def maa_plan_solver(self, tasks='All', one_time=False):
def skland_plan_solover(self):
skland = SKLand(self.skland_config['skland_info'])
skland.attendance()
del self.tasks[0]

def recruit_plan_solver(self):
recruit([], self.send_message_config, self.recruit_config)

def read_report(self):
return daily_report()

def mail_plan_solver(self):
mail([])
25 changes: 17 additions & 8 deletions arknights_mower/solvers/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from arknights_mower.utils.scene import Scene
from arknights_mower.utils.solver import BaseSolver
from arknights_mower.data import __rootdir__
from ..utils.path import get_path


class ReportSolver(BaseSolver):
Expand All @@ -22,7 +23,7 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None:
self.high_range_blue = (100, 255, 255)
self.low_range_gray = (100, 100, 100)
self.high_range_gray = (255, 255, 255)
self.record_path = f"{__rootdir__.parent}/tmp/report.csv"
self.record_path = get_path('@app/tmp/record.csv')
# 结算数据
self.report_res = {
}
Expand All @@ -40,15 +41,21 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None:
'riic_orundum_order': "贸易站合成玉订单",
}

self.report_csv_path = f"{__rootdir__.parent}/tmp/report.csv"

def run(self) -> None:
def run(self) -> bool:
if self.is_today_recorded():
return
super().run()
return True
try:
super().run()
return self.record_report()
except TypeError:
logger.error("基报识别失败 润!")
except PermissionError:
logger.error("基报记录访问失败")
return False

def is_today_recorded(self) -> bool:
if os.path.exists(self.report_csv_path) is not True:
if os.path.exists(self.record_path) is not True:
return False
try:
now = datetime.datetime.now()
Expand Down Expand Up @@ -146,10 +153,10 @@ def read_report(self):
self.report_res[item] = res

self.report_res['riic_iron_number'] = int(int(self.report_res['riic_iron']) / 500)
self.record_report()


def record_report(self):
logger.info(f"存入数据{self.report_res}")
logger.debug(f"存入数据{self.report_res}")
write_header = True
if os.path.exists(self.record_path):
write_header = False
Expand All @@ -160,3 +167,5 @@ def record_report(self):
csv_writer.writerow(self.riic_key_str)
csv_writer.writerow(self.report_res)
file.close()
logger.info("{}的基报记录完成".format(self.report_res['riic_date']))
return True
24 changes: 14 additions & 10 deletions arknights_mower/solvers/skland.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import requests

from arknights_mower.utils.log import logger
from arknights_mower.utils.path import get_path


class SKLand:
def __init__(self, skland_info):
self.account = []
self.record_path = get_path("@app/tmp/skland.csv")
try:
for item in skland_info:
if item["isCheck"] is False:
Expand Down Expand Up @@ -46,7 +48,6 @@ def __init__(self, skland_info):
}

self.get_award = {}
self.record_path = "skland_record.csv"

def respone_to_json(self, responese):
try:
Expand Down Expand Up @@ -165,24 +166,27 @@ def attendance(self):
return self.get_award

def record_attendance(self, account, data):

data_row = [account, data, datetime.date.today()]
with open(self.record_path, 'a+') as f:
csv_write = csv.writer(f)
csv_write.writerow(data_row)
data_row = {"account": account,
"data": data,
"date": datetime.date.today().strftime("%Y-%m-%d")
}
file = open(self.record_path, 'a+', newline='')
csv_writer = csv.DictWriter(file, fieldnames=list(data_row.keys()))
csv_writer.writerow(data_row)
file.close()

def get_record(self, account):

try:
with open(self.record_path, 'r+') as f:
csv_reader = csv.reader(f)
for line in csv_reader:
if line:
if line[0] == account and line[2] == str(datetime.date.today()):
return True
except:
with open(self.record_path, 'a+') as f:
return False
except FileNotFoundError:
logger.info("森空岛记录查询失败")
except FileExistsError:
logger.info("森空岛记录查询失败")

return False

Expand Down
4 changes: 2 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ def start():

if mower_process is not None:
return "Mower is already running."

# 创建 tmp 文件夹
tmp_dir = get_path("@app/tmp")
tmp_dir.mkdir(exist_ok=True)

read, write = multiprocessing.Pipe()
mower_process = multiprocessing.Process(
target=main,
Expand Down

0 comments on commit f7f5064

Please sign in to comment.