'Refactored by Sourcery'

pull/359/head
Sourcery AI 1 year ago
parent e6b1d2755f
commit 51ccb0f692
  1. 2
      flask-redis/app.py
  2. 24
      nginx-flask-mysql/backend/hello.py

@ -8,7 +8,7 @@ redis = Redis(host='redis', port=6379)
def hello():
redis.incr('hits')
counter = str(redis.get('hits'),'utf-8')
return "This webpage has been viewed "+counter+" time(s)"
return f"This webpage has been viewed {counter} time(s)"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True)

@ -5,15 +5,14 @@ import mysql.connector
class DBManager:
def __init__(self, database='example', host="db", user="root", password_file=None):
pf = open(password_file, 'r')
self.connection = mysql.connector.connect(
user=user,
password=pf.read(),
host=host, # name of the mysql service as set in the docker compose file
database=database,
auth_plugin='mysql_native_password'
)
pf.close()
with open(password_file, 'r') as pf:
self.connection = mysql.connector.connect(
user=user,
password=pf.read(),
host=host, # name of the mysql service as set in the docker compose file
database=database,
auth_plugin='mysql_native_password'
)
self.cursor = self.connection.cursor()
def populate_db(self):
@ -24,10 +23,7 @@ class DBManager:
def query_titles(self):
self.cursor.execute('SELECT title FROM blog')
rec = []
for c in self.cursor:
rec.append(c[0])
return rec
return [c[0] for c in self.cursor]
server = Flask(__name__)
@ -43,7 +39,7 @@ def listBlog():
response = ''
for c in rec:
response = response + '<div> Hello ' + c + '</div>'
response = f'{response}<div> Hello {c}</div>'
return response

Loading…
Cancel
Save