Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix bandit and mypy Warnings #6

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions ch8/cache_aside/cache_aside.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sqlite3
import sys
from pathlib import Path

import redis
Expand All @@ -19,7 +18,7 @@ def get_quote(quote_id: str) -> str:
with sqlite3.connect(DB_PATH) as db:
cursor = db.cursor()
res = cursor.execute(
f"SELECT text FROM quotes WHERE id = {quote_id}"
f"SELECT text FROM quotes WHERE id = {quote_id}" # nosec
).fetchone()
if not res:
return "There was no quote stored matching that id!"
Expand All @@ -31,13 +30,15 @@ def get_quote(quote_id: str) -> str:

# Add to the cache
key = f"{CACHE_KEY_PREFIX}.{quote_id}"
cache.set(key, quote, ex=60)
cache.set(key, quote, ex=60) # type: ignore
out.append(f"Added TO CACHE, with key '{key}'")
else:
out.append(f"Got '{quote}' FROM CACHE")

if out:
return " - ".join(out)
else:
return ""


def main():
Expand Down
7 changes: 3 additions & 4 deletions ch8/cache_aside/populate_db.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# pip install redis
# pip install faker
# pip3 install redis
# pip3 install faker

import sqlite3
import sys
from pathlib import Path
from random import randint

Expand Down Expand Up @@ -38,7 +37,7 @@ def add_quotes(quotes_list):
cursor = db.cursor()

for quote_text in quotes_list:
quote_id = randint(1, 100)
quote_id = randint(1, 100) # nosec
quote = (quote_id, quote_text)

cursor.execute(
Expand Down