I’m creating a simple messaging app for entry monitoring. Whenever the user enter the premises, it will create a row and get the date and time. So I want to push the entry clockin
to the messaging app. And when it will exit the premises, it will push another message showing the clockout
time.
This is my database table entrymonitoring
.
id | clockin | clockout | date | userid |
---|---|---|---|---|
1 | 2pm | 4pm | 2024-05-02 | 1820191145 |
2 | 9am | 2024-05-03 | 1820191145 |
This is how I get the entries in database_handler.py
. I’m having hard time filtering the logged in user, so I just used specific values for the mean time.
def get_entries():
sql = "SELECT * FROM entrymonitoring WHERE student_id = (SELECT mystudent FROM parent_mystudent WHERE parent = '1' AND mystudent = '1820191145') ORDER BY `date` DESC LIMIT 6"
cursor.execute(sql)
results = cursor.fetchall()
return results
This is my PublicScreen.py
. Here the code only displays the entry. So if the clockout
is updated, I wanted to push another messsage that the user exited at 4pm for example, without removing the entry message before.
class PublicScreen(MDScreen):
def load_posts(self):
self.ids.posts.clear_widgets()
results = database_handler.get_entries()
for msg in results:
msg_card = MDCard(
orientation="vertical",
padding="20dp",
size_hint=[None, None],
size=["500dp", "120dp"],
pos_hint={"center_x": .5, "center_y": .5}
)
msg_title = MDLabel(
halign="left",
text="AMSAI",
theme_text_color="Secondary",
size_hint_y=None,
height="40dp"
)
title_separator = MDSeparator(
height="1dp"
)
msg_body = MDLabel(
halign="left",
text="User entered at " + str(msg[1]),
)
msg_timestamp = MDLabel(
text=str(msg[3]),
halign="right",
theme_text_color="Secondary",
size_hint_y=None,
height="5dp"
)
msg_card.add_widget(msg_title)
msg_card.add_widget(title_separator)
msg_card.add_widget(msg_body)
msg_card.add_widget(msg_timestamp)
self.ids.posts.add_widget(msg_card)
This is a bit complicated, I can’t even think of anything how to do it. I tried using if statement, like if the msg[2]
is empty it would push an entry message, else it would push the exit message. Which is it only updated the message before. I wanted to push another message about the exit. Can anybody help me with this? Thank you so much.
zheni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.