parent
7b8652c02c
commit
ab848035fc
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (monitor)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (adbMonitor)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (adbMonitor)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
|
|
@ -4,3 +4,41 @@
|
|||
2023-08-05 16:35:21
|
||||
2023-08-05 16:51:34
|
||||
2023-08-05 17:03:17
|
||||
2023-08-05 17:22:21
|
||||
2023-08-05 17:27:49
|
||||
2023-08-05 17:33:23
|
||||
2023-08-05 17:41:28
|
||||
2023-08-05 17:45:57
|
||||
2023-08-05 17:50:16
|
||||
2023-08-05 17:57:55
|
||||
2023-08-05 18:03:01
|
||||
2023-08-07 12:06:32
|
||||
2023-08-07 12:54:44
|
||||
2023-08-07 13:08:40
|
||||
2023-08-07 13:13:34
|
||||
2023-08-07 13:22:38
|
||||
2023-08-07 13:33:59
|
||||
2023-08-07 13:44:37
|
||||
2023-08-07 13:51:41
|
||||
2023-08-07 13:58:42
|
||||
2023-08-07 14:06:02
|
||||
2023-08-07 14:36:10
|
||||
2023-08-07 07:45:09
|
||||
2023-08-07 08:19:47
|
||||
2023-08-07 08:25:04
|
||||
2023-08-07 08:38:54
|
||||
2023-08-07 08:45:01
|
||||
2023-08-07 08:49:49
|
||||
2023-08-07 08:55:08
|
||||
2023-08-07 09:00:53
|
||||
2023-08-07 09:05:36
|
||||
2023-08-07 09:10:41
|
||||
2023-08-07 09:18:31
|
||||
2023-08-07 09:26:42
|
||||
2023-08-07 09:35:38
|
||||
2023-08-07 09:40:33
|
||||
2023-08-07 09:52:47
|
||||
2023-08-07 09:59:44
|
||||
2023-08-07 10:07:50
|
||||
2023-08-07 10:14:39
|
||||
2023-08-07 10:20:43
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
[Cache]
|
||||
cache_file_path = cache/record.txt
|
||||
|
||||
|
||||
|
||||
[General]
|
||||
#timedifference成功拿取任务和现在的时间差,大于此时间差重启ProxyMe
|
||||
time_difference = 1800
|
||||
|
||||
[Database]
|
||||
host = 192.168.2.20
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
8AGX0SMQF
|
||||
8AGX0SMQF
|
||||
8AGX0SMQF
|
||||
8AGX0SMQF
|
||||
8AGX0SMQF
|
||||
2
main.py
2
main.py
|
|
@ -44,6 +44,6 @@ if __name__ == '__main__':
|
|||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
||||
#
|
||||
# if __name__ == '__main__':
|
||||
# main()
|
||||
Binary file not shown.
|
|
@ -11,12 +11,12 @@ def run_adb_command(command_list):
|
|||
|
||||
def get_now_time(device):
|
||||
# adb shell date +%s
|
||||
output, status_code, error = run_adb_command(['adb', '-s', device, 'shell', 'date', '+%s'])
|
||||
output, status_code, error = run_adb_command(['adb', '-s', device, 'shell', 'date',"'+%Y-%m-%d %H:%M:%S'"])
|
||||
if status_code == 0:
|
||||
print(f"get_now_time output: {output}")
|
||||
logging.info(f"get now time output: {output}")
|
||||
now_timestamp = int(output)
|
||||
return now_timestamp
|
||||
now_time = output
|
||||
return now_time
|
||||
else:
|
||||
print(error)
|
||||
logging.error(f"get now time error: {error}")
|
||||
|
|
@ -101,3 +101,4 @@ def restart_ProxyMe(device):
|
|||
else:
|
||||
print(f"stop autojs failed")
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -16,3 +16,9 @@ def read_config_ini():
|
|||
# return cache_file_path,database_config
|
||||
return cache_file_path
|
||||
|
||||
def read_time_difference():
|
||||
file_path = './config.ini'
|
||||
config = configparser.ConfigParser()
|
||||
config.read(file_path)
|
||||
time_difference = config.get("General","time_difference")
|
||||
return time_difference
|
||||
27
monitor.py
27
monitor.py
|
|
@ -1,9 +1,10 @@
|
|||
import logging
|
||||
|
||||
import pytz
|
||||
import modules.fileRW
|
||||
from datetime import datetime
|
||||
import modules.device
|
||||
import modules.command
|
||||
import modules.read_config
|
||||
def convert_to_timestamp(string_time):
|
||||
# 定义日期时间格式
|
||||
date_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
|
@ -39,10 +40,23 @@ def get_last_time():
|
|||
return None
|
||||
|
||||
|
||||
def str_to_timestamp(time_str):
|
||||
format_str = "%Y-%m-%d %H:%M:%S"
|
||||
try:
|
||||
dt_object = datetime.strptime(time_str,format_str)
|
||||
timestamp = dt_object.timestamp()
|
||||
return timestamp
|
||||
except ValueError as e:
|
||||
logging.error(f"str_to_timestamp error: {e}")
|
||||
print("Error:", e)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def adb_get_now_time(device):
|
||||
now_timestamp = modules.command.get_now_time(device)
|
||||
if now_timestamp != None:
|
||||
convert_timestamp(now_timestamp)
|
||||
now_time = modules.command.get_now_time(device)
|
||||
if now_time != None:
|
||||
now_timestamp = str_to_timestamp(now_time)
|
||||
return now_timestamp
|
||||
else:
|
||||
return None
|
||||
|
|
@ -56,14 +70,15 @@ def monitor(device):
|
|||
diff_timestamp = now_timestamp - last_line_timestamp
|
||||
print(f"diff_timestamp: {diff_timestamp},与上次成功获取任务时间差{int(diff_timestamp/60)}分钟")
|
||||
logging.info(f"{device}与上次成功获取任务时间差{int(diff_timestamp/60)}分钟")
|
||||
if diff_timestamp >= 1800:
|
||||
time_difference = modules.read_config.read_time_difference()
|
||||
if diff_timestamp >= time_difference:
|
||||
success = modules.command.restart_ProxyMe(device)
|
||||
if success:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
print(f"时间差小于40分钟,不执行重启ProxyMe")
|
||||
print(f"时间差小于{time_difference}分钟,不执行重启ProxyMe")
|
||||
return True
|
||||
else:
|
||||
print(f"get now timestamp: failed")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
from datetime import datetime
|
||||
|
||||
|
||||
def format_time_string(input_time_str):
|
||||
try:
|
||||
# 解析时区时间字符串为datetime对象
|
||||
dt_object = datetime.strptime(input_time_str, "%a %b %d %H:%M:%S %Z %Y")
|
||||
|
||||
# 将datetime对象重新格式化为所需的字符串格式
|
||||
formatted_time_str = dt_object.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
return formatted_time_str
|
||||
except ValueError as e:
|
||||
print("Error: Invalid time format.")
|
||||
return None
|
||||
|
||||
|
||||
# 测试函数
|
||||
input_time_str = "Mon Aug 7 09:33:39 BST 2023"
|
||||
formatted_time = format_time_string(input_time_str)
|
||||
if formatted_time is not None:
|
||||
print(formatted_time)
|
||||
Reference in New Issue