def view_the_log() -> 'html': with UseDatabase(app.config['dbconfig']) as cursor: _SQL = """select phrase, letters, ip, browser_string, results from log""" cursor.execute(_SQL) contents = cursor.fetchall() titles = ('Phrase', 'Letters', 'Remote_addr', 'User_agent', 'Results') return render_template('viewlog.html', the_title='View Log', the_row_titles=titles, the_data=contents,)
def log_request(req: 'Flask_Request', results: str) -> None: """Log details of the web request and the results.""" with UseDatabase(app.config['dbconfig']) as cursor: _SQL_INSERT = """insert into log_table (phrase, letters, ip, browser_string, results) values (?, ?, ?, ?, ?)""" cursor.execute(_SQL_INSERT, (req.form['phrase'], req.form['letter'], req.remote_addr, req.user_agent.browser, results,))
def log_request(request: 'flash_request', response:str) -> None: ''' Logs the changes done by the user into the db ''' with UseDatabase(app.config['dbconfig']) as cursor: _SQL = """insert into log (phrase, letters, ip, browser_string, results) values (%s, %s, %s, %s, %s)""" cursor.execute(_SQL, (request.form['phrase'], request.form['letters'], request.remote_addr, request.user_agent.browser, response, ))
def log_request(req: 'flask_request', res: str) -> None: with UseDatabase(dbconfig) as cursor: _SQL = """ INSERT INTO log (phrase, letters, ip, browser_string, results) VALUES (%s, %s, %s, %s, %s) """ cursor.execute(_SQL, ( req.form['phrase'], req.form['letters'], req.remote_addr, req.user_agent.browser, res, ))
def view_the_log() -> 'html': with UseDatabase(dbconfig) as cursor: _SQL = """ SELECT * FROM log """ cursor.execute(_SQL) res = cursor.fetchall() contents = [] for row in res: contents.append([]) for item in row: contents[-1].append(item) titles = ('Request ID', 'Date', 'Phrase', 'letters', 'Remote address', 'Browser', 'Results') return render_template( 'viewlog.html', the_title='View Log', the_row_titles=titles, the_data=contents, )
def view_the_log() -> 'html': contents = [] try: # used context manager with UseDatabase(app.config['dbconfig']) as cursor: _SQL = """select phrase, letters, ip, browser_string, results from log_table""" cursor.execute(_SQL) contents = cursor.fetchall() titles = ['Phrase', 'Letters', 'IP', 'Browser Used', 'Results'] return render_template('viewlog.html', the_title='View Log', the_row_titles=titles, the_data=contents, ) except ConnectionError as ierr: print('Is your database switched on? error: ', str(ierr)) except CredentialsError as cerr: print('User/id issues error: ', str(cerr)) except SQLError as serr: print('Is your query correct', str(serr)) except Exception as err: print('Something went wrong: ', str(err))
from DBCm import UseDatabase dbconfig = { 'host': '127.0.0.1', 'user': '******', 'password': '******', 'database': 'vsearchlogdb', } with UseDatabase(dbconfig) as cursor: _SQL = """ SELECT * FROM log""" cursor.execute(_SQL) res = cursor.fetchall() for row in res: print(row)