From e0eb758c0d9584dd6ad9e2e7023e0cccccef2c7a Mon Sep 17 00:00:00 2001 From: Alexandr Pankratiew Date: Sat, 11 Aug 2018 12:55:32 +0300 Subject: [PATCH] Small changes --- .gitignore | 6 +-- bot.py | 27 ++++------ units/log.py | 4 +- voteban.log | 147 --------------------------------------------------- 4 files changed, 15 insertions(+), 169 deletions(-) delete mode 100644 voteban.log diff --git a/.gitignore b/.gitignore index e804619..14f785d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ vk_config.v2.json config.py +command.txt +*.log *.pyc *.ban PythonAntiCaptchaImages/ -__pycache__/ - -error.log \ No newline at end of file +__pycache__/ \ No newline at end of file diff --git a/bot.py b/bot.py index d3b9f37..14ea2aa 100644 --- a/bot.py +++ b/bot.py @@ -528,23 +528,16 @@ def main(): logs = log.Log(const.log_filename) # Создаем объект логов -try: - if __name__ == '__main__': - main() -except Exception as error_msg: +while True: try: - f = open('error.log', 'a') - except IOError: - f = open('error.log', 'w') - print(str(time.localtime(time.time())), file=f, end=' ') - print(error_msg, file = f, end='\n') - logs.write('ERROR!!!!!!' + error_msg) - f.close() - saveListToFile(black_list, const.file_name) - logs.write("I'm finishing my work ...") - main() # Произошло исключение - пробуем вернуться к работе -else: - saveListToFile(black_list, const.file_name) - logs.write("I'm finishing my work ...") + if __name__ == '__main__': + main() + except Exception as error_msg: + logs.write('ERROR!!!!!!' + error_msg) + saveListToFile(black_list, const.file_name) + logs.write("I'm finishing my work ...") + else: + saveListToFile(black_list, const.file_name) + logs.write("I'm finishing my work ...") print(black_list) diff --git a/units/log.py b/units/log.py index 18abf92..d2e5560 100644 --- a/units/log.py +++ b/units/log.py @@ -14,8 +14,8 @@ def __init__(self, filename): self.logfile = open(filename, 'w') def write(self, message): - currtime = str(datetime.datetime.now()) - message = '> [{0}] {1}'.format(currtime, str(message)) + currtime = str(datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S')) + message = '[{0}] {1}'.format(currtime, str(message)) print(message, end='\n', file=self.logfile) self.logfile.flush() diff --git a/voteban.log b/voteban.log deleted file mode 100644 index cf9e9a2..0000000 --- a/voteban.log +++ /dev/null @@ -1,147 +0,0 @@ -> [2018-08-10 13:04:06.990677] I'm starting my work ... -> [2018-08-10 13:05:39.890095] I'm starting my work ... -> [2018-08-10 13:05:39.890095] ERROR!!!!!! -> [2018-08-10 13:05:39.890095] I'm finishing my work ... -> [2018-08-10 13:05:39.890095] I'm starting my work ... -> [2018-08-10 13:10:28.266985] I'm starting my work ... -> [2018-08-10 13:10:29.107729] Checking friends... -> [2018-08-10 13:10:29.286147] {'count': 1, 'items': [179214239]} -> [2018-08-10 13:10:40.796253] I'm starting my work ... -> [2018-08-10 13:10:41.141385] Checking friends... -> [2018-08-10 13:10:41.522444] {'count': 0, 'items': []} -> [2018-08-10 13:11:23.331602] I'm starting my work ... -> [2018-08-10 13:11:23.693522] Checking friends... -> [2018-08-10 13:11:24.080122] {'count': 0, 'items': []} -> [2018-08-10 13:12:46.937168] I'm starting my work ... -> [2018-08-10 13:12:47.266867] Checking friends... -> [2018-08-10 13:12:47.646505] {'count': 0, 'items': []} -> [2018-08-10 13:13:07.931900] I'm starting my work ... -> [2018-08-10 13:13:08.280439] Checking friends... -> [2018-08-10 13:13:08.678733] {'count': 0, 'items': []} -> [2018-08-10 13:17:10.439233] I'm starting my work ... -> [2018-08-10 13:17:10.780500] Checking friends... -> [2018-08-10 13:17:11.172350] {'count': 0, 'items': []} -> [2018-08-10 13:17:12.579369] I'm starting my work ... -> [2018-08-10 13:17:12.945512] Checking friends... -> [2018-08-10 13:17:13.329042] {'count': 0, 'items': []} -> [2018-08-10 13:17:44.379220] New voteban: chat: 21, member: id481408597 -> [2018-08-10 13:19:37.375728] I'm starting my work ... -> [2018-08-10 13:19:37.769570] Checking friends... -> [2018-08-10 13:19:38.156565] {'count': 0, 'items': []} -> [2018-08-10 13:20:36.051563] I'm starting my work ... -> [2018-08-10 13:20:36.491794] Checking friends... -> [2018-08-10 13:20:36.880257] {'count': 0, 'items': []} -> [2018-08-10 13:21:09.347448] New voteban: chat: 21, member: id481408597 -> [2018-08-10 13:23:09.452819] Vote ended. chat: 21 -> [2018-08-10 13:23:25.093877] I'm starting my work ... -> [2018-08-10 13:23:25.509891] Checking friends... -> [2018-08-10 13:23:25.919318] {'count': 0, 'items': []} -> [2018-08-10 13:26:13.254084] New voteban: chat: 21, member: id481408597 -> [2018-08-10 13:26:43.232433] I'm starting my work ... -> [2018-08-10 13:26:43.703173] Checking friends... -> [2018-08-10 13:26:44.093046] {'count': 0, 'items': []} -> [2018-08-10 13:26:58.002978] New voteban: chat: 21, member: id481408597 -> [2018-08-10 13:27:32.312504] I'm starting my work ... -> [2018-08-10 13:27:32.671058] Checking friends... -> [2018-08-10 13:27:33.071313] {'count': 0, 'items': []} -> [2018-08-10 13:27:47.748854] New voteban: chat: 21, member: id481408597 -> [2018-08-10 13:28:23.311069] I'm starting my work ... -> [2018-08-10 13:28:23.680872] Checking friends... -> [2018-08-10 13:28:24.070950] {'count': 0, 'items': []} -> [2018-08-10 13:30:09.775863] I'm starting my work ... -> [2018-08-10 13:30:10.178587] Checking friends... -> [2018-08-10 13:30:10.563063] {'count': 0, 'items': []} -> [2018-08-10 13:32:38.962753] I'm starting my work ... -> [2018-08-10 13:32:39.322697] Checking friends... -> [2018-08-10 13:32:39.695985] {'count': 0, 'items': []} -> [2018-08-10 13:32:43.041642] I'm starting my work ... -> [2018-08-10 13:32:43.406398] Checking friends... -> [2018-08-10 13:32:43.805941] {'count': 0, 'items': []} -> [2018-08-10 13:33:59.157068] I'm starting my work ... -> [2018-08-10 13:33:59.642747] Checking friends... -> [2018-08-10 13:34:00.042586] {'count': 0, 'items': []} -> [2018-08-10 13:35:32.174336] I'm starting my work ... -> [2018-08-10 13:35:32.551009] Checking friends... -> [2018-08-10 13:35:32.953416] {'count': 0, 'items': []} -> [2018-08-10 13:37:00.959934] I'm starting my work ... -> [2018-08-10 13:37:01.348466] Checking friends... -> [2018-08-10 13:37:01.737840] {'count': 0, 'items': []} -> [2018-08-10 13:37:27.551654] I'm starting my work ... -> [2018-08-10 13:37:27.993478] Checking friends... -> [2018-08-10 13:37:28.379042] {'count': 0, 'items': []} -> [2018-08-10 13:42:27.556406] Create banlist backup.. -> [2018-08-10 13:47:27.559781] Create banlist backup.. -> [2018-08-10 13:48:03.777625] I'm starting my work ... -> [2018-08-10 13:48:04.213533] Checking friends... -> [2018-08-10 13:48:04.596340] {'count': 0, 'items': []} -> [2018-08-10 13:49:02.773184] I'm starting my work ... -> [2018-08-10 13:49:03.181968] Checking friends... -> [2018-08-10 13:49:03.573014] {'count': 0, 'items': []} -> [2018-08-10 13:50:46.278804] I'm starting my work ... -> [2018-08-10 13:50:46.996870] Checking friends... -> [2018-08-10 13:50:47.393478] {'count': 0, 'items': []} -> [2018-08-10 13:51:16.573551] I'm starting my work ... -> [2018-08-10 13:51:17.105921] Checking friends... -> [2018-08-10 13:51:17.499784] {'count': 0, 'items': []} -> [2018-08-10 13:52:18.541355] I'm starting my work ... -> [2018-08-10 13:52:18.884102] Checking friends... -> [2018-08-10 13:52:19.281453] {'count': 0, 'items': []} -> [2018-08-10 13:57:18.546863] Create banlist backup.. -> [2018-08-10 13:57:32.183494] I'm starting my work ... -> [2018-08-10 13:57:32.600507] Checking friends... -> [2018-08-10 13:57:32.993649] {'count': 0, 'items': []} -> [2018-08-10 13:58:04.458953] I'm starting my work ... -> [2018-08-10 13:58:04.838815] Checking friends... -> [2018-08-10 13:58:05.229122] {'count': 0, 'items': []} -> [2018-08-10 13:58:24.224119] I'm starting my work ... -> [2018-08-10 13:58:24.598249] Checking friends... -> [2018-08-10 13:58:24.978378] {'count': 0, 'items': []} -> [2018-08-10 13:59:02.412868] I'm starting my work ... -> [2018-08-10 13:59:02.882899] Checking friends... -> [2018-08-10 13:59:03.293287] {'count': 0, 'items': []} -> [2018-08-10 13:59:05.346990] I'm starting my work ... -> [2018-08-10 13:59:05.707743] Checking friends... -> [2018-08-10 13:59:06.088747] {'count': 0, 'items': []} -> [2018-08-10 14:03:01.475536] Clearing getChatMember cache -> [2018-08-10 14:03:16.568093] I'm starting my work ... -> [2018-08-10 14:03:17.047326] Checking friends... -> [2018-08-10 14:03:17.434602] {'count': 0, 'items': []} -> [2018-08-10 14:03:39.028694] I'm starting my work ... -> [2018-08-10 14:03:39.401883] Checking friends... -> [2018-08-10 14:03:39.794923] {'count': 0, 'items': []} -> [2018-08-10 14:04:01.036151] I'm starting my work ... -> [2018-08-10 14:04:01.486608] Checking friends... -> [2018-08-10 14:04:01.866669] {'count': 0, 'items': []} -> [2018-08-10 14:04:18.523236] I'm starting my work ... -> [2018-08-10 14:04:18.951540] Checking friends... -> [2018-08-10 14:04:19.339038] {'count': 0, 'items': []} -> [2018-08-10 14:05:14.523111] I'm starting my work ... -> [2018-08-10 14:05:15.117217] Checking friends... -> [2018-08-10 14:05:15.502477] {'count': 0, 'items': []} -> [2018-08-10 14:07:53.708203] I'm starting my work ... -> [2018-08-10 14:07:54.148442] Checking friends... -> [2018-08-10 14:07:54.533413] {'count': 0, 'items': []} -> [2018-08-10 14:08:16.574565] I'm starting my work ... -> [2018-08-10 14:08:17.036423] Checking friends... -> [2018-08-10 14:08:17.422186] {'count': 0, 'items': []} -> [2018-08-10 14:09:11.092649] I'm starting my work ... -> [2018-08-10 14:09:11.775975] Checking friends... -> [2018-08-10 14:09:12.163099] {'count': 0, 'items': []} -> [2018-08-10 14:10:25.377454] I'm starting my work ... -> [2018-08-10 14:10:25.751001] Checking friends... -> [2018-08-10 14:10:26.149585] {'count': 0, 'items': []} -> [2018-08-10 14:12:48.117443] Clearing getChatMember cache -> [2018-08-10 14:12:48.132715] User id441677847 joined at chat 2 -> [2018-08-10 14:15:25.398552] Create banlist backup.. -> [2018-08-10 14:16:37.071325] I'm starting my work ... -> [2018-08-10 14:16:37.457794] Checking friends... -> [2018-08-10 14:16:37.858207] {'count': 0, 'items': []} -> [2018-08-10 14:17:16.771188] I'm starting my work ... -> [2018-08-10 14:17:17.352761] Checking friends... -> [2018-08-10 14:17:17.744550] {'count': 0, 'items': []} -> [2018-08-10 14:17:32.757449] I'm starting my work ... -> [2018-08-10 14:17:33.205944] Checking friends... -> [2018-08-10 14:17:33.592836] {'count': 0, 'items': []} -> [2018-08-10 14:18:46.637146] I'm starting my work ... -> [2018-08-10 14:18:47.145027] Checking friends... -> [2018-08-10 14:18:47.527186] {'count': 0, 'items': []}