Skip to content

PR to solve the issue of messages mixing#53

Open
HashirGJ8842 wants to merge 43 commits intoHaider8:masterfrom
HashirGJ8842:master
Open

PR to solve the issue of messages mixing#53
HashirGJ8842 wants to merge 43 commits intoHaider8:masterfrom
HashirGJ8842:master

Conversation

@HashirGJ8842
Copy link

@HashirGJ8842 HashirGJ8842 commented Oct 27, 2019

In this, I have done some changes to create a system of databases, with each user having their own
database.

In this edit, we can now create new databases for the users who have recently registered, and the messages sent by the users will be stored in their respective databases. I have used SQLAlchemy instead of peewee.
Just added a variable 'new' in line 65 and line 78. And a new argument named 'new'.
@pep8speaks
Copy link

pep8speaks commented Oct 27, 2019

Hello @HashirGJ8842! Thanks for updating this PR.

Line 8:33: E261 at least two spaces before inline comment

Line 9:47: E261 at least two spaces before inline comment
Line 12:5: E303 too many blank lines (2)
Line 22:5: E303 too many blank lines (2)
Line 22:12: E712 comparison to True should be 'if cond is True:' or 'if cond:'
Line 22:20: E261 at least two spaces before inline comment

Comment last updated at 2019-10-29 07:48:29 UTC

tmessage/db.py Outdated

User = ''
class MessageDatabase(db.Model):
__bind_key__ = User
Copy link

Choose a reason for hiding this comment

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

trailing whitespace

tmessage/db.py Outdated
db = SQLAlchemy(app)

User = ''
class MessageDatabase(db.Model):
Copy link

Choose a reason for hiding this comment

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

expected 2 blank lines, found 0

tmessage/db.py Outdated
from peewee import CharField, DateTimeField, Model, SqliteDatabase
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///main.db'
app.config['SQLALCHEMY_BINDS'] = { 'we' : 'sqlite:///we.db'}
Copy link

Choose a reason for hiding this comment

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

whitespace after '{'
whitespace before ':'

tmessage/db.py Outdated
pip install flask-sqlalchemy
from datetime import datetime
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
Copy link

Choose a reason for hiding this comment

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

module level import not at top of file

tmessage/db.py Outdated
pip install flask
pip install flask-sqlalchemy
from datetime import datetime
from flask import Flask
Copy link

Choose a reason for hiding this comment

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

module level import not at top of file

tmessage/db.py Outdated
@@ -1,28 +1,34 @@
"""Handles the connection to the SQLite database as well as DB interaction"""
pip install flask
Copy link

Choose a reason for hiding this comment

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

SyntaxError: invalid syntax

tmessage/db.py Outdated
from flask_sqlalchemy import SQLAlchemy

from peewee import CharField, DateTimeField, Model, SqliteDatabase
app = Flask(__name__)
Copy link
Owner

Choose a reason for hiding this comment

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

There's no need for flask in tmessage because we are not making a webserver here. Let us know on which issue are you working on or try opening a new issue if you want to work on some other issues.

Thanks for the PR though :)

Copy link
Author

Choose a reason for hiding this comment

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

I haven't used flask to make a webserver. I have used it so that I could use SqlAlchemy explicitly to work on this issue, and just because i was comfortable with SqlAlchemy ORM.

Copy link
Owner

Choose a reason for hiding this comment

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

You don't need flask to use sqlalchemy and secondly, we are using peewee as an ORM

tmessage/db.py Outdated

class Message(DB.Model):
def fun(user):
__bind_key__ = user
Copy link

Choose a reason for hiding this comment

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

local variable 'bind_key' is assigned to but never used

tmessage/db.py Outdated
def new_database(user):
APP.config['SQLALCHEMY_BINDS'][user] = f'sqlite:///{user}.db'


Copy link

Choose a reason for hiding this comment

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

blank line contains whitespace

tmessage/db.py Outdated
@MESSAGES_DB
def new_database(user):
APP.config['SQLALCHEMY_BINDS'][user] = f'sqlite:///{user}.db'

Copy link

Choose a reason for hiding this comment

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

blank line contains whitespace

tmessage/db.py Outdated
timestamp = DateTimeField()
def add(self):
return 1+1
def __repr__(self):
Copy link

Choose a reason for hiding this comment

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

expected 1 blank line, found 0

tmessage/db.py Outdated
def add(self):
""" To few methods"""
print(self.sender)

Copy link

Choose a reason for hiding this comment

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

blank line contains whitespace

tmessage/db.py Outdated
timestamp = DB.Column(DB.DateTime)


def __repr__(self):
Copy link

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)

tmessage/db.py Outdated
sender = DB.Column(DB.String(120), primary_key=True, nullable=False)
message = DB.Column(DB.String(120), nullable=False)
timestamp = DB.Column(DB.DateTime)

Copy link

Choose a reason for hiding this comment

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

blank line contains whitespace

tmessage/db.py Outdated
@MESSAGES_DB
def store_messages(user, raw_msg):
"""Store a message sent by the indicated user in the database"""
if new == True:
Copy link

Choose a reason for hiding this comment

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

comparison to True should be 'if cond is True:' or 'if cond:'
too many blank lines (2)

sender = CharField()
message = CharField()
timestamp = DateTimeField()
class Message(Model):
Copy link

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)

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

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

tmessage/db.py Outdated
@MESSAGES_DB
def store_messages(user, raw_msg):
"""Store a message sent by the indicated user in the database"""
if new = True:
Copy link

Choose a reason for hiding this comment

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

SyntaxError: invalid syntax
too many blank lines (2)

tmessage/db.py Outdated
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
Copy link

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

@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

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants