Improve logging.

This commit is contained in:
Alexandr
2019-05-17 14:21:38 +03:00
parent a6d7903c57
commit a80b915d10
4 changed files with 9 additions and 4 deletions

View File

@ -1 +1 @@
openssl req -newkey rsa:2048 -sha256 -nodes -keyout cert.key -x509 -days 365 -out cert.pem -subj /C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=hexor.ru openssl req -newkey rsa:2048 -sha256 -nodes -keyout cert.key -x509 -days 3650 -out cert.pem -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=hexor.ru"

View File

@ -109,7 +109,8 @@ class DataBase:
def add_alert(self, user_id, conf_id, alert_time, message): def add_alert(self, user_id, conf_id, alert_time, message):
date = int(dt.datetime.now().strftime("%s")) date = int(dt.datetime.now().strftime("%s"))
if len(alert_time) < 4: print(alert_time)
if alert_time[0] == '+':
alert_time = (dt.datetime.now() + dt.timedelta(minutes=int(alert_time[1:]))).strftime("%H%M") alert_time = (dt.datetime.now() + dt.timedelta(minutes=int(alert_time[1:]))).strftime("%H%M")
sql = """INSERT OR IGNORE INTO sql = """INSERT OR IGNORE INTO
alert('conf_id', 'user_id', 'created', 'time', 'message') alert('conf_id', 'user_id', 'created', 'time', 'message')

View File

@ -30,6 +30,7 @@ class RequestHandler(SimpleHTTPRequestHandler):
length = self.headers.get('content-length') length = self.headers.get('content-length')
post_body = self.rfile.read(int(length)) post_body = self.rfile.read(int(length))
print(post_body)
msg = json.loads(post_body.decode("utf-8")) msg = json.loads(post_body.decode("utf-8"))
self.worker.handleUpdate(msg) self.worker.handleUpdate(msg)
@ -56,6 +57,8 @@ class WebHook:
self.httpd.serve_forever() self.httpd.serve_forever()
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
except Exception as e:
print("ERROR: %s" % e)
finally: finally:
# Clean-up server (close socket, etc.) # Clean-up server (close socket, etc.)
self.httpd.server_close() self.httpd.server_close()

View File

@ -48,7 +48,7 @@ class MessageWorker:
except ValueError: except ValueError:
pass pass
try: try:
if (int(string[1:]) > 0) and (string[0] == '+') and (len(string[1:]) < 3): if (int(string[1:]) > 0) and (string[0] == '+') and (len(string[1:]) < 4):
return string return string
except: except:
pass pass
@ -222,7 +222,8 @@ class MessageWorker:
print(e) print(e)
self.send_img(conf_id) self.send_img(conf_id)
return True return True
except: except Exception as e:
print('ERROR: %s' % e)
return False return False
try: try:
text = msg['message']['text'] text = msg['message']['text']