Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/hacklabkyiv/prismo into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaStelmashchuk committed Nov 21, 2023
2 parents c1fbbd8 + e5e9f4a commit 8cb2385
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
63 changes: 39 additions & 24 deletions app/features/readers/reader_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,43 @@ def send_message_of_locking(device_id):
cursor.execute(
"SELECT slack_channel_id, name FROM devices WHERE id=?", (device_id,)
)
slack_channel_id, device_name, = cursor.fetchall()[0]
if slack_channel_id is None:
raise Exception("No slack channel id for device " + device_id)
try:
slack_channel_id, device_name, = cursor.fetchall()[0]
if slack_channel_id is None:
raise Exception("No slack channel id for device " + device_id)

message = f"The {device_name} is free now"
message = f"The {device_name} is free now"

send_channel_message(slack_channel_id, message)
send_channel_message(slack_channel_id, message)
except Exception as err:
print("Cannot send slack message.")
print(f"Unexpected {err=}, {type(err)=}")
# raise


def send_message_of_unlocking(device_id, user_key):
cursor = get_db_connection().cursor()
cursor.execute(
"SELECT slack_channel_id, name FROM devices WHERE id=?", (device_id,)
)
slack_channel_id, device_name, = cursor.fetchall()[0]
if slack_channel_id is None:
raise Exception("No slack channel id for device " + device_id)
try:
slack_channel_id, device_name, = cursor.fetchall()[0]
if slack_channel_id is None:
raise Exception("No slack channel id for device " + device_id)

user_cursor = get_db_connection().cursor()
user_cursor.execute("SELECT slack_id, name FROM users WHERE key=?", (user_key,))
slack_id, user_name = user_cursor.fetchall()[0]
if slack_id is None:
message = f"{user_name} start using the {device_name}"
else:
message = f"<@{slack_id}> start using the {device_name}"
user_cursor = get_db_connection().cursor()
user_cursor.execute("SELECT slack_id, name FROM users WHERE key=?", (user_key,))
slack_id, user_name = user_cursor.fetchall()[0]
if slack_id is None:
message = f"{user_name} start using the {device_name}"
else:
message = f"<@{slack_id}> start using the {device_name}"

send_channel_message(slack_channel_id, message)
send_channel_message(slack_channel_id, message)
except Exception as err:
print("Cannot send slack message.")
print(f"Unexpected {err=}, {type(err)=}")
# raise


def send_log_of_last_usage(device_id, user_key):
Expand All @@ -100,11 +110,16 @@ def send_log_of_last_usage(device_id, user_key):
)
rows = cursor.fetchall()
message = "The last 3 people who unlocked the door were: \n"
for row in rows:
slack_id, name, operation_time = row
if slack_id is None:
message += f"{name} at {operation_time}\n"
else:
message += f"<@{slack_id}> at {operation_time}\n"

send_dm_message(user_key, message)
try:
for row in rows:
slack_id, name, operation_time = row
if slack_id is None:
message += f"{name} at {operation_time}\n"
else:
message += f"<@{slack_id}> at {operation_time}\n"

send_dm_message(user_key, message)
except Exception as err:
print("Cannot send slack message.")
print(f"Unexpected {err=}, {type(err)=}")
# raise
4 changes: 2 additions & 2 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/intro.js/2.7.0/intro.js"></script>
<script src="static/js/rfid.js"></script>
<script src="static/js/application.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected].0-alpha1/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/intro.js/2.7.0/introjs.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/css/select2.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.13.1/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.13.1/datatables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

Expand Down

0 comments on commit 8cb2385

Please sign in to comment.