Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 36 #49

Closed
wants to merge 14 commits into from
4 changes: 3 additions & 1 deletion tmessage/cli.py
Expand Up @@ -4,7 +4,7 @@
import paho.mqtt.client as mqtt
from colorama import init, deinit, Fore, Back, Style
import tmessage.auth as auth # auth.py
from tmessage.db import store_messages # db.py
from tmessage.db import grab_messages, store_messages # db.py"""


# Initialize colorama
Expand Down Expand Up @@ -80,6 +80,8 @@ def main():
pub_msg = f'[{user_name}] {displayed_name}: {raw_msg}'
if raw_msg != '':
MQTT_CLIENT.publish(MQTT_TOPIC, pub_msg)
if raw_msg == "grab":
grab_messages(CURRENT_USER)
if IS_STORE:
store_messages(CURRENT_USER, raw_msg)
else:
Expand Down
9 changes: 7 additions & 2 deletions tmessage/db.py
Expand Up @@ -16,12 +16,17 @@ class Message(Model):
class Meta: # pylint: disable=missing-class-docstring,too-few-public-methods
database = MESSAGES_DB


@MESSAGES_DB
Grommers00 marked this conversation as resolved.
Show resolved Hide resolved
Grommers00 marked this conversation as resolved.
Show resolved Hide resolved
def grab_messages(user):
"""Grab messages from the user"""
cursor = MESSAGES_DB.execute_sql("SELECT sender, message FROM message where sender LIKE \'" + user +'\'')
Grommers00 marked this conversation as resolved.
Show resolved Hide resolved
for row in cursor.fetchall():
print(row[0] + " : " + row[1])
Grommers00 marked this conversation as resolved.
Show resolved Hide resolved

Grommers00 marked this conversation as resolved.
Show resolved Hide resolved
@MESSAGES_DB
def store_messages(user, raw_msg):
"""Store a message sent by the indicated user in the database"""
time = datetime.now()

Message.create(sender=user, message=raw_msg, timestamp=time)


Expand Down