Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ecf0b84
Update db.py
HashirGJ8842 Oct 27, 2019
2b4fc33
Update db.py
HashirGJ8842 Oct 27, 2019
c01ddfe
'new' variable to create databases for new users
HashirGJ8842 Oct 27, 2019
65b1fc6
Update db.py
HashirGJ8842 Oct 27, 2019
7f2e80b
Update db.py
HashirGJ8842 Oct 27, 2019
e486493
Update db.py
HashirGJ8842 Oct 27, 2019
909f3a5
Update requirements.txt
HashirGJ8842 Oct 27, 2019
68f1dd5
Update db.py
HashirGJ8842 Oct 27, 2019
98e7b29
Update db.py
HashirGJ8842 Oct 27, 2019
40528e1
Update cli.py
HashirGJ8842 Oct 27, 2019
33dc6e2
Update db.py
HashirGJ8842 Oct 27, 2019
65a4a1e
Update cli.py
HashirGJ8842 Oct 27, 2019
cf9cbed
Update requirements.txt
HashirGJ8842 Oct 27, 2019
0c9c00c
Update db.py
HashirGJ8842 Oct 27, 2019
009cf89
Update db.py
HashirGJ8842 Oct 27, 2019
e67459b
Update requirements.txt
HashirGJ8842 Oct 27, 2019
0166b7c
Update requirements.txt
HashirGJ8842 Oct 27, 2019
7c468e9
Update requirements.txt
HashirGJ8842 Oct 27, 2019
c39ab5c
Update .travis.yml
HashirGJ8842 Oct 27, 2019
b901b95
Update .travis.yml
HashirGJ8842 Oct 27, 2019
3e0abc6
Update .travis.yml
HashirGJ8842 Oct 27, 2019
72b58f6
Update .travis.yml
HashirGJ8842 Oct 27, 2019
92efb10
Update .travis.yml
HashirGJ8842 Oct 27, 2019
cc36051
Update .travis.yml
HashirGJ8842 Oct 27, 2019
b884ce8
Update .travis.yml
HashirGJ8842 Oct 27, 2019
6931784
Update requirements.txt
HashirGJ8842 Oct 27, 2019
b7311b9
Update requirements.txt
HashirGJ8842 Oct 27, 2019
ce5bea9
Update .travis.yml
HashirGJ8842 Oct 27, 2019
5616731
Update .travis.yml
HashirGJ8842 Oct 27, 2019
2f55181
Update db.py
HashirGJ8842 Oct 27, 2019
4406ae4
Update auth.py
HashirGJ8842 Oct 27, 2019
b1bc6a1
Update .travis.yml
HashirGJ8842 Oct 27, 2019
d622585
Update db.py
HashirGJ8842 Oct 27, 2019
0701dfb
Update requirements.txt
HashirGJ8842 Oct 27, 2019
366b3e1
Update db.py
HashirGJ8842 Oct 27, 2019
8935f70
Update requirements.txt
HashirGJ8842 Oct 27, 2019
14c401c
Update requirements.txt
HashirGJ8842 Oct 28, 2019
8393997
Update db.py
HashirGJ8842 Oct 28, 2019
badbe2a
Update cli.py
HashirGJ8842 Oct 28, 2019
e113d4e
Update db.py
HashirGJ8842 Oct 28, 2019
4686635
Update db.py
HashirGJ8842 Oct 28, 2019
9b3692d
Update db.py
HashirGJ8842 Oct 28, 2019
30960f9
Update cli.py
HashirGJ8842 Oct 29, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ python:
- "3.7"
install: "pip install -r requirements.txt"
# command to run tests
script: pylint **/*.py
script: pylint **/*.py
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

colorama==0.4.1
paho-mqtt==1.4.0
requests==2.22.0
Expand All @@ -7,3 +8,4 @@ python-dotenv==0.10.3
pylint==2.4.2
simple-chalk==0.1.0
pre-commit==1.18.3

4 changes: 3 additions & 1 deletion tmessage/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import dotenv as env
env.load_dotenv()

API_BASE_URL = os.environ.get("TMESSAGE_API_URL") or "https://peaceful-waters-15584.herokuapp.com"
API_BASE_URL_A = os.environ.get("TMESSAGE_API_URL")
API_BASE_URL_B = "https://peaceful-waters-15584.herokuapp.com"
API_BASE_URL = API_BASE_URL_B or API_BASE_URL_A
API_USER_URL = f'{API_BASE_URL}/api/user'


Expand Down
8 changes: 5 additions & 3 deletions tmessage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from colorama import init, deinit, Fore, Back, Style
from simple_chalk import chalk
import tmessage.auth as auth # auth.py
from tmessage.db import store_messages # db.py
from tmessage.db import database # db.py
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least two spaces before inline comment

from tmessage.utils import get_formatted_message

# Initialize colorama
Expand Down Expand Up @@ -53,7 +53,7 @@ def on_message(client, userdata, message):
print(user_details, msg)
_, _, message = current_msg.partition("] ")
if IS_STORE:
store_messages(user, message)
database(user, message, False)


def main():
Expand All @@ -62,6 +62,7 @@ def main():
if auth.check_existed(CURRENT_USER):
password = getpass(f"User {CURRENT_USER} found\nEnter password: ")
payload = auth.authenticate(CURRENT_USER, password)
new = False
else:
print(f"Welcome {CURRENT_USER} to tmessage!\nPlease register...")
displayed_name = input("Enter your name used for display: ")
Expand All @@ -74,6 +75,7 @@ def main():
payload = auth.register(
CURRENT_USER, displayed_name, password, password_confirm
)
new = True
print("User Authorized")
user_name = payload["user_name"]
displayed_name = payload["displayed_name"]
Expand All @@ -89,7 +91,7 @@ def main():
if raw_msg != "":
MQTT_CLIENT.publish(MQTT_TOPIC, pub_msg)
if IS_STORE:
store_messages(CURRENT_USER, formatted_msg)
database(CURRENT_USER, formatted_msg, new)
else:
print(Back.WHITE + Fore.RED + "Can't send empty message", end="\n")
except KeyboardInterrupt:
Expand Down
27 changes: 12 additions & 15 deletions tmessage/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@
from peewee import CharField, DateTimeField, Model, SqliteDatabase


MESSAGES_DB = SqliteDatabase('message_store.sqlite')
def database(user, raw_msg, new):
"""user for sender, raw_msg for message, new if the user is new"""
MESSAGES_DB = SqliteDatabase(f'{user}.db')# pylint: disable=invalid-name


class Message(Model):
"""Message table - keeps track of message sent and received"""
sender = CharField()
message = CharField()
timestamp = DateTimeField()
class Message(Model):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many blank lines (2)

"""Message table - keeps track of message sent and received"""
sender = CharField()
message = CharField()
timestamp = DateTimeField()

class Meta: # pylint: disable=missing-class-docstring,too-few-public-methods
database = MESSAGES_DB
class Meta: # pylint: disable=missing-class-docstring,too-few-public-methods
database = MESSAGES_DB


@MESSAGES_DB
def store_messages(user, raw_msg):
"""Store a message sent by the indicated user in the database"""
if new == True: # pylint: disable=singleton-comparison
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least two spaces before inline comment
comparison to True should be 'if cond is True:' or 'if cond:'
too many blank lines (2)

MESSAGES_DB.create_tables([Message])
time = datetime.now()

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


MESSAGES_DB.create_tables([Message])