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):
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")
sql = """INSERT OR IGNORE INTO
alert('conf_id', 'user_id', 'created', 'time', 'message')

View File

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

View File

@ -48,7 +48,7 @@ class MessageWorker:
except ValueError:
pass
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
except:
pass
@ -222,7 +222,8 @@ class MessageWorker:
print(e)
self.send_img(conf_id)
return True
except:
except Exception as e:
print('ERROR: %s' % e)
return False
try:
text = msg['message']['text']