7

You have eight conditions to match for every UPDATE. A typical solution would store timestamps using a DATETIME or TIMESTAMP column, so that there is only one value to match. For reasonable performance, ensure that the timestamp field is indexed.


5

Document with docstrings. Your functions and ORM models are currently not providing any useful documentation regarding their respective function within your program. Don't initialize the database on module level: You should put that into a function: Base.metadata.create_all(engine) Base.metadata.bind = engine Session = (sessionmaker(bind=engine)) #...


5

First of all, to me this code looks clean, easy to read, so overall, nicely done! Avoid repeated queries This piece of code runs the exact same query twice: queried_titles = [ast.literal_eval(item.title) for item in trends.query.all()] queried_time = [item.time for item in trends.query.all()] It would be better to run the query once and iterate over its ...


5

Looks like you got a good start, but there's plenty left to improve. Considering you're doing this as a one-man project, I imagine there will always be minor issues. First of all, initial set-up. On a fresh, barebones Python installation your program will miss a lot of dependencies. It looks like some of those will be hauled in during the installation, but ...


3

This is an expansion of @Mast's great answer. sqlalchemy typing-extensions pygments colorama commonmark pprintpp psycopg2 were still missing after the set-up as well. Whilst when I installed it just now, I got most of these packages I didn't have psycop2. This is coming from an improperly configured setuptools package. We can see neither setup.py or ...


3

In get_option, you have a while loop: while True: option = input(prompt) if not option: print("Please enter an option.") continue if option not in options: valid_options = ", ".join(options) print(f"Invalid option. Valid options: {valid_options}") continue return option I think this would make more ...


3

Encryption is not enough In addition to your eventual encryption, you need to take measures to protect your data at the operating system level. At the least, make sure that the permissions are restrictive - this is possible on Windows, MacOS and Linux using various methods. Sets VALID_MASTER_PASS_ANSWERS and VALID_ACTIONS should be sets. Also, just store ...


3

Everything is good by this point but I'd change the relation between posts and tags from one-to-many to many-to-many. You can do this with this code: tags_to_posts = db.Table( "tags_and_posts", db.Column( "post_id", db.Integer, db.ForeignKey( "posts.id" ) ), db.Column( "tag_id", db.Integer, db.ForeignKey( "tags.id" ) ) ) class Post(db.Model): ...


2

Some comments: Instead of using print statements, the logging module could be used The return value of get_google_content should be a boolean value (True on success, False on failure) Regarding ways to make the refresh_content method a little bit more pythonic, I would probably use a for loop and the all built-in function to make sure that all the calls to ...


2

Your basic problem is you want to combine...erm, join... similar data from your database. There are a couple different angles we can take to solve this problem: We could do as you are, but a more simple way. We can let the database do the work. The second way is the preferred solution. Databases are designed to solve this problem and they solve them very ...


2

The only thing I can think of that might make it more Pythonic would be to wrap the body of deleteUser() in a try and catch and handle the OperationalError rather than checking user and email for None before making the attempt.


2

I would re-structure code to improve on readability and avoiding code duplication while decreasing the nestedness depth level - remember that "Flat is better than nested". I would probably first fail fast if date value is given and has an invalid format. Then, I would define a queryset variable which will help us keep the common parts of the query while ...


2

You should take advantage of what is already available. For example, the json module. Instead of putting the string together manually, use json.dumps. Python doesn't have a SQLAlchemy library built-in, but you can get one on PyPI, just pip install SQLAlchemy. Using this, you can browse https://stackoverflow.com/q/5022066/5827958 to see some simple ways of ...


2

Your database management is kind of a mess: SQLAlchemy recommend to keep your sessions scope the same than your requests scope; Having a single, global, session and closing it after a request mean that you can only ever make a single request for the whole lifetime of your application (which is not very useful); (I suspect that because of that) You mix using ...


2

In addition to @janos’s point about exception handling: Don’t handle exceptions if there is nothing you can do about them. fetch_xml() catches the ConnectionError, prints a message, and then ...? Does nothing! The end of the function is reached without returning anything, so None is returned to the caller. trends_retriever() gets the None value, and ...


2

I think this should work: extras = ('country_code', 'price_type') for field in extras: if filters[field] is None: filters.pop(field) if any(field in filters for field in extras): items = Price.query.filter_by(**filters) else: items = Price.query The key is realizing that if there are any filters defined, you have to .filter_by() them. ...


2

Could benefit from PEP484 type hints, e.g. process_claim(claim: Dict[str, Any], session: Session) -> Claim: Is strptime(claim["claimDate"][:-10], '%Y-%m-%d') correct? You're saying that you're taking the whole string from the beginning up to ten characters before the end. Instead, wildly guessing, you either want the first ten characters or the ...


1

If you are concerned about data integrity, that's what transactions are for. I don't really see the point of nested try/catch blocks. A single block for the whole procedure would be sufficient. So, at the start of your try block, you start an explicit transaction using session.begin(), you do your stuff and finally you commit at the end, or rollback in case ...


1

You should avoid doing [0] after your query. Instead, add a .limit(1) at the end of your select. SQA supports named column references on individual result tuples. So in addition to supporting [5], which is (as you've identified) a bad idea - it should just support .time assuming that's what your column name is. However, even better is - rather than selecting ...


1

At the end of the day I used pandas. df = pandas.read_sql_query("""My join query""") This all just solved my problem.


1

BUG Your code doesn't execute right now, I'm guessing because you recently moved source code: ModuleNotFoundError: No module named 'config'. (Works again if you move config.py to backend/.) Your questions Is there a better way to restructure this project? Are the project files named correctly? I would move: the entry file (main.py; which you either could ...


1

Saw your post on indiehackers. I don't know this orm, but generally speaking, I see you have two options. Decide to preload/precache the data when your app starts and refresh it occasionally, if you insist on having all records available. But some good advice I've read is : never do in real time what you can do in advance. So... Why not even build some "...


1

I wouldn't bother making a separate table for timezones. That just makes you do joins unnecessarily. Just put the timezone name directly as an attribute of the UserTimezone table.


1

Without changing the rest of the data structure, your try clause can be shortened: try: q = session.query(Rate).filter(Rate.hotel==hotel['object'], Rate.arrive==rate.arrive).first() if govt is True: sector = "govt" else: sector = "commercial" if q: if 'govt_rate' in item: ...


1

The code in the post seems fine. I think it would be easier to read if you kept the lines to 79 columns or less, put each conditional in its own statement, and made the field names match the query parameter names, like this: query = """ SELECT AVG(stock_date - order_date) AS c, product_category FROM data_table_data WHERE stock_date BETWEEN :...


1

literal_column("'DIVISION_ABC_REQUEST'").concat... (note the double quotes, since you want an SQL string expression). literal_column() essentially means "I hand you this string which is a valid SQL expression and can be used in any column expression-ish context".


1

OOP It seems you're accustomed to organizing your code into functions, and you're new to organizing into classes. When creating a class, the most important question to ask is what Abstract Data Type (ADT) are you trying to represent. Loosely defined, an abstract data type is a collection of data and functions that work with that data. Here are some key ...


1

MainError can be simplified as follows, class MainError: def __init__(self, code, message, errorsList): self.resp=jsonify(dict(errorCode=code, message=message, errorList=[error.serialize() for error in errorsList], success=False)) self.resp.status_code = ...


Only top voted, non community-wiki answers of a minimum length are eligible