def _check_if_account_exists(self, user): # searching for a username-password match sql_username = "******" sql_password = "******" values = (user.get_username(), user.get_password()) db = Database() results_u = db.fetchall_results(sql_username, (values[0], )) results_p = db.fetchall_results(sql_password, (values[1], )) db.close() # bug: ignoring the letter case with this list comprehension match = [(a, b) for (a, b) in results_u for (c, d) in results_p if (a == c) and (b == d)] if len(results_u) == 0: # username doesn't exists return False elif len(match) == 1: # username - password match return True elif len( match ) == 0: # username-password mis-match: password either doesn't exist in db while len(match) == 0: # or it doesn't match the entered username print("Password incorrect. Try again.") user.input_password() pw_value = user.get_password() db = Database() results_p = db.fetchall_results(sql_password, (pw_value, )) match = [(a, b) for (a, b) in results_u for (c, d) in results_p if (a == c) and (b == d)] if len(match) == 1: return True
def show_upcoming_tasks_for_user(user_id): sql = "SELECT task_description, due_date, due_time, time_created " \ "FROM tasks " \ "JOIN users " \ "ON tasks.user_id = users.user_id " \ "WHERE tasks.user_id = %s AND tasks.due_date > NOW()" db = Database() tasks = db.fetchall_results(sql, (user_id, )) db.close() if len(tasks) == 0: return input( "You don't have any upcoming tasks. Would you like to create one now?\n" "yes\nno\n") else: count = 1 for task in tasks: print("------------------------------------") print("TASK #", count) print("task description:", task[0]) print("due date:", calendar.day_name[task[1].weekday()], task[1]) print("due_time:", task[2]) # print("time until:", ... - datetime.now()) # TODO feature... coming up in next sprint! :) print("task created on:", task[3]) count += 1
def __init__(self, session): if not isinstance(session, AnnotationSession): raise AssertionError( 'Use the DatabaseConstructor to build params for annotation') self.dbHelper = Database(session.dbName) self.session = session
def main(): database = Database(db_session) timetable = Timetable(database) t1 = Thread(target=threaded_fun, args=(timetable, )) t1.start() rest_engine = RESTEngine(database, timetable) rest_engine.run()
def _insert_new_user_to_db(self, user): sql = "INSERT INTO users(username, password) VALUES(%s, %s)" values = (user.get_username(), user.get_password()) db = Database() db.commit_to_db(sql, values) print("You account is successfully registered, " + user.get_username().title() + "!") return self._get_user_id_from_db(user)
def __init__(self): self.bash_proj_dir = "bash" self.default_dir_name = "wallpaper" self.bash_file_name = "changeWall.sh" self.bat_file_name = "changeWall.bat" self.vbs_file_name = "changeWall.vbs" self.setup_files() self.all_pages = [] self.spaceManager = SpaceManager() self.db = Database().get_instance() self.pictureManager = PictureManager()
def create_new_task(self, user_id): sql = "INSERT INTO tasks(user_id, task_description, due_date, due_time) " \ "VALUES(%s, %s, %s, %s)" print( "To save a new task, you will have to enter its description and date and time when the task is due." ) self._task.set_description() self._task.set_due_date() self._task.set_due_time() db = Database() values = (user_id, self._task.get_description(), self._task.get_due_date(), self._task.get_due_time()) db.commit_to_db(sql, values) print("Task successfully saved.\n")
import json from db.Database import Database from model.Cars import Cars from model.Rentals import Rentals data = Database() # List of Objects rentals = Rentals.get_all(data) # cars = Cars.get_all(data) file_path = './data/output.json' def generate_output(file_path): rentals_output = {"rentals": []} for i in rentals: rentals_output["rentals"].append(i.get_final_output(data)) with open(file_path, 'w') as json_file: json.dump(rentals_output, json_file, indent=4) generate_output(file_path)
def _get_all_usernames_from_db(): sql = "SELECT username FROM users" db = Database() list_of_tuples = db.query_db(sql, ) return ["".join(i) for i in list_of_tuples]
def __init__(self): self._dbconn = Database()
def cli(): cfg = APPConfig() Database(cfg.read("database"))
from db.Database import Database from static.config import credentials WCA_Database = Database(credentials['db'], credentials['host'], credentials['user'], credentials['passwd'], socket=credentials.get('socket', None), port=credentials.get('port', 3306))
def __init__(self): self.db = Database(config.mongodb_uri, config.database_name) self.db.set_collection("credential")
from api.app import StandaloneApplication from api.routes.dataset_key_route import DatasetKeyRoute from api.routes.dataset_route import DatasetRoute import falcon import multiprocessing from api.routes.kpi_definition_route import KpiDefinitionRoute from api.routes.operator_route import OperatorRoute from api.routes.outlier_route import OutlierRoute from config.APPConfig import APPConfig from db.Database import Database # TODO cfg = APPConfig() Database(cfg.read("database")) api = application = falcon.API() api.add_route('/dataset_keys', DatasetKeyRoute()) api.add_route('/datasets', DatasetRoute()) api.add_route('/operators', OperatorRoute()) api.add_route('/kpi_definitions', KpiDefinitionRoute()) api.add_route('/outliers', OutlierRoute()) # TODO Database connection freezes when using code below via cli def number_of_workers(): return (multiprocessing.cpu_count() * 2) + 1
def __init__(self): self.db = Database(config.mongodb_uri, config.database_name) self.db.set_collection("Cryptography") self.secret = self.__get_secret()
from AuthenticationMenu import UserAuthenticated from db.Database import Database db = Database() # new = Authentication() # new.register_user(db) # print(new.get_user_id()) l = UserAuthenticated() l.login_user(db) print(l.get_user_id()) # hey = Authentication() # user_id = hey._get_user_id_from_db(db, values=('kokica', 'kokica')) # print(user_id) # user = User() # l1 = Authentication() # result = l1._check_if_account_exists(db, user) # print(result) ''' # username exists, correct password # "nairobi", "vrlotajnalozinka" user1 = Authentication() account_exists = user1.login_user(cursor) print("Account exists:", account_exists) print("Expected: correct user id") #username doesn't exist, password exists # "denver", "vrlotajnalozinka" user2 = Authentication()
def _get_user_id_from_db(user): sql = "SELECT user_id FROM users WHERE username = %s AND password = %s" values = (user.get_username(), user.get_password()) db = Database() results = db.fetchone_result(sql, values) return results[0]
def __init__(self): self.space_limit = 2048 # 2 gigabyte(2048 MB), change it to mange space limit self.db = Database().get_instance()
def __init__(self): self.db = Database(config.mongodb_uri, config.database_name) self.db.set_collection("resource")