From ab848035fc71ee4d65876f9d3bb700bb62cc19d5 Mon Sep 17 00:00:00 2001
From: wangsiyuan <2392948297@qq.com>
Date: Tue, 8 Aug 2023 22:26:44 +0800
Subject: [PATCH] 1
1
---
.idea/misc.xml | 2 +-
.idea/monitor.iml | 2 +-
__pycache__/monitor.cpython-39.pyc | Bin 2203 -> 2567 bytes
cache/record.txt | 40 ++++++++++++++++++++-
config.ini | 5 +--
error_devices.txt | 6 ++++
main.py | 2 +-
modules/__pycache__/command.cpython-39.pyc | Bin 3139 -> 3145 bytes
modules/command.py | 9 ++---
modules/read_config.py | 6 ++++
monitor.py | 27 ++++++++++----
test.py | 22 ++++++++++++
12 files changed, 105 insertions(+), 16 deletions(-)
create mode 100644 test.py
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 985be2b..f715034 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/.idea/monitor.iml b/.idea/monitor.iml
index 74d515a..95c5a10 100644
--- a/.idea/monitor.iml
+++ b/.idea/monitor.iml
@@ -4,7 +4,7 @@
-
+
\ No newline at end of file
diff --git a/__pycache__/monitor.cpython-39.pyc b/__pycache__/monitor.cpython-39.pyc
index ba3f0ba5298c75e784a6dd5865f66e7ae73c49ea..5ee189cdcb5aab520027c6bfa80aa9f692aa3f4b 100644
GIT binary patch
delta 756
zcmZ8fL5tHs6rMMkB-6C1UDv8xs}>4kR?%Hl1TP-Mi(n6~Sd6eC_GQ;%YS(F2+0xpB
zg6AbCDMEYkEcW2v*sJ*mdh;LnCS3%bFyHshd-G=Adz0zP$5Z9dbsa|I>h~l3QaUWx
zCogD)3?XLzlEH_3&3%KI$D${E0ZX5m+aR`x4HO@kZ=;D8u|yjsaRCeH5Ib1J5^)h-
zEEAUywwQO~r@p-9K_)RwqNLk9{PYzz(+5x&AwGY&*oD^sS^9%NgVn_?<0VXL6wm=3
zc05dCUBf+^10+Bg!?2dH8I0Hn=6uXYe8%T&Y>bRH+hT$x#=$nQF;y|VoQRo;d?cpq
zGoJ&n#6n{v-g97W_LQm|i+2JkYN<9RY=b1FE?UZ<%Z6tMi3*Z_K)FYQB<$@qBBlE3
zPGe}@&xL0zP8*fbU=d`_lQ7!AiqG5Zy`Abdxm2)+$<4=t)S$3fi+5FP=Q;L0Q34GEs_2L$_5yyeW7t3nKU#
zy?W7$H$NbsAbx;HXWP!O^Jd=6&c1!Fy;aIR-**{VXZaiVy-7K^IHL*~Lc+uxK^RmU
ziJ6+hggIx;I7kYFCR$HS*jPZDu!u$Egd81o2_5vXMCc-%u+X2pen49Z2q2x_!w^8I
zU*jCA(?jzbs_XQ21X|C+3{|jO2f!ZaGP3yz;V86ZjVAJ9l%;8JfTDC2kGq5Ht~>6h
zv8+-rG;$l`+kO=1J~dQk)zyn#S!q#kH2X4?fRkH>Y)s$n9|-hHS*IXey-vnaCQ)il
zvY|ftmbanPH5~%=$2+jAww=93lZeohK0#hiGrURSQTwu=#K)(yrXHQ0C9P+%M`um-
Rg#|
diff --git a/cache/record.txt b/cache/record.txt
index 8d9edee..2255a1e 100644
--- a/cache/record.txt
+++ b/cache/record.txt
@@ -3,4 +3,42 @@
2023-08-05 16:18:39
2023-08-05 16:35:21
2023-08-05 16:51:34
-2023-08-05 17:03:17
\ No newline at end of file
+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
\ No newline at end of file
diff --git a/config.ini b/config.ini
index 3c9edae..503bbda 100644
--- a/config.ini
+++ b/config.ini
@@ -1,8 +1,9 @@
[Cache]
cache_file_path = cache/record.txt
-
-
+[General]
+#timedifference成功拿取任务和现在的时间差,大于此时间差重启ProxyMe
+time_difference = 1800
[Database]
host = 192.168.2.20
diff --git a/error_devices.txt b/error_devices.txt
index e69de29..947e8b4 100644
--- a/error_devices.txt
+++ b/error_devices.txt
@@ -0,0 +1,6 @@
+
+8AGX0SMQF
+8AGX0SMQF
+8AGX0SMQF
+8AGX0SMQF
+8AGX0SMQF
\ No newline at end of file
diff --git a/main.py b/main.py
index 8ac1cd7..916369e 100644
--- a/main.py
+++ b/main.py
@@ -44,6 +44,6 @@ if __name__ == '__main__':
except KeyboardInterrupt:
pass
-
+#
# if __name__ == '__main__':
# main()
\ No newline at end of file
diff --git a/modules/__pycache__/command.cpython-39.pyc b/modules/__pycache__/command.cpython-39.pyc
index ce71cd23d65d99002cd727625ef0069e4280fd92..663e04bddd24311b97aa625fa335aa99478ed966 100644
GIT binary patch
delta 356
zcmX>saZ-Xek(ZZ?0SKzLUr2G=$lJxpXgPTXqYO)8N|Nv7t&DMO89>PrhRF+<6(?IU
z$%@o4*0R*F1T&N{)-X3SGBT7fEnu0P&!i_RqOPqPsjHf+tD2&q>S3koYo!{jK6xRN
z7bENBH%!u#d6?xnIr8$$<4ZDgQzu(88*s5OvM_Nl3NRMQY%XS&Wn`3^JdwqdQGWAn
z76V2`xycJyL?$b+sW2){zRl7-`2t%dnX@OWmAVLO2$b$$}!y%^VOlIY=0|2s&PjmnP
delta 326
zcmX>paae*kk(ZZ?0SG<_oJ(=s$lJxpXf}BUqYPv2!Q
zGRjXDVzXdW2Fi9%zQ$I`rUZ0fk^JOPb_+&Tke11d*yk}SPIlxdhDq(>uw+yROL1^M
z2I_yqY0jv*S%piNky{z0SrtU6PmbZ1=G6o-#esw-W0Caa7H(fFT@Z)6hy^4e0V1?P
Ygb;|31rZ7$0?8N<7i@~|WNsci03zr~F8}}l
diff --git a/modules/command.py b/modules/command.py
index 8561d57..0d52aa1 100644
--- a/modules/command.py
+++ b/modules/command.py
@@ -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}")
@@ -100,4 +100,5 @@ def restart_ProxyMe(device):
return False
else:
print(f"stop autojs failed")
- return False
\ No newline at end of file
+ return False
+
diff --git a/modules/read_config.py b/modules/read_config.py
index d4534e9..8ad5c05 100644
--- a/modules/read_config.py
+++ b/modules/read_config.py
@@ -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
\ No newline at end of file
diff --git a/monitor.py b/monitor.py
index 818996b..f017f99 100644
--- a/monitor.py
+++ b/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")
diff --git a/test.py b/test.py
new file mode 100644
index 0000000..71314e4
--- /dev/null
+++ b/test.py
@@ -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)