def recipe_id(id): delete = delete_form() delete.id.label = id # Get all ingredients form = add_to_recipe_form() form.select.choices = [ ( 0, '- Select Ingredient -' ) ] \ + Database().get_all_ingredient_names() if form.validate_on_submit(): Database().add_recipe_item(id, int(form.data['select']), form.data['quantity'], form.data['unit']) return redirect('/recipe/id={}'.format(id)) # Get ingredients for the recipe ingredients = Database().get_ingredients_for_recipe(id) title = Database().get_recipe_name(id) return render_template('recipe.html', title=title, ingredients=ingredients, new_ingredient=form, delete=delete)
def main(): QtCore.QCoreApplication.setApplicationName('pntest') app = QtWidgets.QApplication(sys.argv) app_path = get_app_path() src_path = os.path.join(app_path, 'src') data_path = get_resource_path(app_path, 'include') tmp_db_path = get_resource_path(app_path, 'pntest-tmp.db') style_dir_path = get_resource_path(app_path, 'style') print(f'[Gui] App path: {app_path}') print(f'[Gui] Data path: {data_path}') print(f'[Gui] DB path: {tmp_db_path}') print(f'[Gui] style dir path: {style_dir_path}') # Load DB from the CLI if argument given try: tmp_db_path = sys.argv[1] print(f'[Frontend] Overridding DB path from CLI: {tmp_db_path}') database = Database(tmp_db_path) database.load_or_create() except IndexError: database = Database(tmp_db_path) database.delete_existing_db() database.load_or_create() process_manager = ProcessManager(src_path) main_window = MainWindow() main_window.set_process_manager(process_manager) main_window.show() app.aboutToQuit.connect(main_window.about_to_quit) # type: ignore # Style: app.setStyle('Fusion') style_loader = StyleheetLoader(style_dir_path) stylesheet = style_loader.load_theme(THEME) if stylesheet is not None: app.setStyleSheet(stylesheet) # Icon: app.setWindowIcon( QtGui.QIcon(QtGui.QPixmap('/home/evan/Code/pntest/pntest-icon32.ico'))) main_window.setWindowIcon( QtGui.QIcon(QtGui.QPixmap('/home/evan/Code/pntest/pntest-icon32.ico'))) sys.exit(app.exec_())
def make_chunks(physiological_file_id, config_file, verbose): """ Call the function create_chunks_for_visualization of the Physiology class on the PhysiologicalFileID provided as argument to this function. :param physiological_file_id: PhysiologicalFileID of the file to chunk :type physiological_file_id: int :param config_file: path to the config file with database connection information :type config_file: str :param verbose : flag for more printing if set :type verbose : bool """ # database connection db = Database(config_file.mysql, verbose) db.connect() # grep config settings from the Config module data_dir = db.get_config('dataDirBasepath') # making sure that there is a final / in data_dir data_dir = data_dir if data_dir.endswith('/') else data_dir + "/" # load the Physiological object physiological = Physiological(db, verbose) # create the chunked dataset if physiological.grep_file_path_from_file_id(physiological_file_id): print('Chunking physiological file ID ' + str(physiological_file_id)) physiological.create_chunks_for_visualization(physiological_file_id, data_dir)
def get_database_connection(): database = Database( app_config["DATABASE"]["host"], app_config["DATABASE"]["username"], app_config["DATABASE"]["password"], app_config["DATABASE"]["dbname"]) return database
def main(): """ Main execution flow. """ try: args = process_arguments() config = utilities.read(args.config_file) manifest = utilities.read(args.manifest_file) # TODO: Refactor core.config = config utilities.TOKENIZER = core.Tokenizer() database = Database(config['options']['datasource']) globaloptions = { 'today': config['options']['today'], 'timeout': config['options']['timeout'] } attributes = Attributes(manifest['attributes'], database, args.cleanup, args.key_string, **globaloptions) if not os.path.exists(args.repositories_root): os.makedirs(args.repositories_root, exist_ok=True) table = 'reaper_results' if args.goldenset: table = 'reaper_goldenset' _run = run.Run(args.repositories_root, attributes, database, config['options']['threshold'], args.num_processes) _run.run([int(line) for line in args.repositories_sample], table) except Exception as e: extype, exvalue, extrace = sys.exc_info() traceback.print_exception(extype, exvalue, extrace)
def reinitialize(self): self.database = Database(self) self._pid = 0 self._package = None self._process = None self._script = None self._spawned = False self._resumed = False self.java_available = False # frida device self._device = None # process self._process = None self._script = None # hooks self.hooks = {} self.native_on_loads = {} self.java_on_loads = {} self.java_hooks = {} self.temporary_input = '' self.native_pending_args = None self.java_pending_args = None self.context_tid = 0
def title_scan(domain, ret, now_time): ret = list(ret) database = Database( os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'srcscan.db')) database.connect() database.init() logger.sysinfo('Checking %d subdomains of %s.' % (len(ret), domain)) loop = asyncio.get_event_loop() thread_num = int(conf['config']['basic']['thread_num']) thread_num = thread_num if len(ret) > thread_num else thread_num tasks = [] for i in range(0, thread_num): tasks.append( asyncio.ensure_future( get_title([ret[x] for x in range(0 + i, len(ret), thread_num)]))) loop.run_until_complete(asyncio.wait(tasks)) for task in tasks: for subdomain, url, title, status, content_length in task.result(): database.update_subdomain_status(subdomain, url, title, status, content_length, now_time) database.disconnect() logger.sysinfo("Checked subdomains' status of %s." % domain)
def subdomain_scan(domain, ret, now_time): database = Database( os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'srcscan.db')) database.connect() database.init() logger.sysinfo("Scanning domain %s." % domain) _engines = [_(domain) for _ in engines.values()] loop = asyncio.get_event_loop() if debug: loop.set_debug(True) for task in [asyncio.ensure_future(_engine.run()) for _engine in _engines]: loop.run_until_complete(task) # loop.close() for _engine in _engines: logger.sysinfo("{engine} Found {num} sites".format( engine=_engine.engine_name, num=len(_engine.results['subdomain']))) ret.update(_engine.results['subdomain']) logger.sysinfo("Found %d subdomains of %s." % (len(ret), domain)) for subdomain in ret: database.insert_subdomain(subdomain, None, None, 0, 0, now_time, domain) database.disconnect() return ret
def vul_scan(domain, now_time): datas = [] database = Database( os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'srcscan.db')) database.connect() database.init() logger.sysinfo("Scaning vul for: %s " % (domain)) for _row in database.select_mondomain(domain): data = { "subdomain": _row[0], "url": _row[1], "title": _row[2], "status": _row[3], "len": _row[4], "update_time": _row[5], "domain": _row[6] } datas.append(data) for data in datas: if data['status'] != 0: logger.sysinfo("Scaning vul for %s." % (data['url'])) crawlergo_scan(data['url'], data['domain'], now_time, database) logger.sysinfo("Scaned vul for: %s " % (domain)) database.disconnect()
def save_into_db(data): # create an an sqlite_advisory object db = Database("countries.sqlite") db.drop_table("US") db.add_table("US", country_iso="text", name="text", advisory_text="text", visa_info="text") LOGGER.info('Saving United State table into the database') try: for country in data: iso = data[country].get('country-iso') name = data[country].get('name') advisory = data[country].get('advisory-text') visa = data[country].get('visa-info') LOGGER.info(f"Saving {name} into the US table") db.insert("US", iso, name, advisory, visa) LOGGER.info( f"{name} was succesfully saved into the US table with the following information: {visa}. {advisory}" ) LOGGER.success('US table has been successfully saved into the databse') except Exception as error_msg: LOGGER.error( f'Error has occured while saving the countries into the US table because of the following error: {error_msg}' ) db.close_connection() #save_to_united_states()
def __init__(self) -> None: super().__init__( command_prefix=commands.when_mentioned_or( environ.get('PREFIX', 'aria ')), help_command=None, ) self.db = Database(self)
def recipes(): new_recipe = add_recipe_form() if new_recipe.validate_on_submit(): Database().add_recipe(new_recipe.data['name']) redirect('/recipes') delete = delete_form() recipes = Database().get_all_recipes() return render_template('recipe_list.html', title='Recipes', recipes=recipes, new_recipe=new_recipe, delete=delete)
def run(): vast = Vast(username=settings.VAST_USERNAME, password=settings.VAST_PASSWORD) account = vast.get_account() machine = vast.get_machine(id=settings.VAST_MACHINE_ID) machine.instances = vast.get_instances(machine_id=settings.VAST_MACHINE_ID) db = Database() _time = int(time.time()) db.insert_machine( _time, { "account_credit": account.current['total'], "reliability": machine.reliability2, "rentals_stored": machine.current_rentals_resident, "rentals_on_demand": machine.current_rentals_running_on_demand, "rentals_bid": machine.current_rentals_running - machine.current_rentals_running_on_demand }) for key, instance in enumerate(machine.instances): db.insert_instance( _time, { "instance_id": key, "earning": 0 if instance.next_state == "running" else instance.min_bid, })
def test_run_timeout(self): with tempfile.TemporaryDirectory() as directory: # Arrange project_id = 10868464 repository_path = directory rawattributes = copy.deepcopy(self.rawattributes) for attribute in rawattributes: if 'architecture' in attribute['name']: attribute['options']['timeout'] = '1S' # Sabotage expected = (0, {'architecture': None}) # Act attributes = Attributes( rawattributes, database=Database(self.rawsettings), keystring='a', goptions=self.rawgoptions ) try: attributes.database.connect() actual = attributes.run(project_id, repository_path) # Assert self.assertEqual(expected, actual) finally: attributes.database.disconnect()
def save_to_canada(): db = Database("countries.sqlite") db.drop_table("CA") db.add_table("CA", country_iso="text", name="text", advisory_text="text", visa_info="text") LOGGER.info('Saving CA table into the databse') #getting the data from all countries all_countries = get_all_countries() countries_data = advisory_canada(all_countries) #saving the data in db try: for country in countries_data: iso = countries_data[country].get('country-iso') name = countries_data[country].get('name') advisory = countries_data[country].get('advisory-text') visa = countries_data[country].get('visa-info') LOGGER.info(f'Saving {name} into the CA table') db.insert("CA", iso, name, advisory, visa) LOGGER.success( f'{name} was successfully saved into the CA table with the following table: {advisory}. {visa}' ) LOGGER.success('CA table was successfully saved into the database') except Exception as error_msg: LOGGER.error( f'An error has occurred while saving the countries into the CA table because of the following error: {error_msg}' ) db.close_connection()
def save_into_db(data): # create an an sqlite_advisory object db = Database("countries.sqlite") db.drop_table("IE") db.add_table("IE", country_iso="text", name="text", advisory_text="text", visa_info="text") try: for country in data: iso = data[country].get('country-iso') name = data[country].get('name') advisory = data[country].get('advisory-text').replace('"', '') LOGGER.info(f'Saving {name} into the IE table') visa = data[country].get('visa-info') db.insert("IE", iso, name, advisory, visa) LOGGER.success( f"{name} was saved into the IE table with the following information: {visa}. {advisory}" ) LOGGER.info('IE table successfully saved to the database') except Exception as error_msg: LOGGER.error( f'An error has occured while saving {name} into the IE table because of the following error: {error_msg}' ) db.close_connection()
def test_init_repository(self): with tempfile.TemporaryDirectory() as directory: # Arrange project_id = 10868464 repository_path = os.path.join(directory, str(project_id)) expected = os.path.join( directory, str(project_id), 'squib' ) # Act attributes = Attributes( self.rawattributes, database=Database(self.rawsettings), goptions=self.rawgoptions ) try: attributes.database.connect() actual = attributes._init_repository( project_id, repository_path ) # Assert self.assertTrue(len(os.listdir(repository_path)) > 0) self.assertTrue(expected in actual) finally: attributes.database.disconnect()
def save_drug_law(): marijuana = get_countries_canabaislaw() cocaine = get_countries_cocainelaw() methaphetamine = get_countries_methaphetaminelaw() DB = Database(sqlite_db) DB.drop_table('drugs') DB.add_table('drugs', country_iso='text', name="text", methaphetamine_possession='text', methaphetamine_sale='text', methaphetamine_transport='text', methaphetamine_cultivation='text', cocaine_possession='text', cocaine_sale='text', cocaine_transport='text', cocaine_cultivation='text', canabais_recreational='text', canabais_medical='text') drug_info = combine_dictionaries(marijuana,cocaine, methaphetamine) for iso in drug_info: country_iso = drug_info[iso].get("iso") country_name = drug_info[iso].get("name") methaphetamine_possession = drug_info[iso].get("methaphetamine_possession") methaphetamine_sale = drug_info[iso].get("methaphetamine_sale") methaphetamine_transport = drug_info[iso].get("methaphetamine_transport") methaphetamine_cultivation = drug_info[iso].get("methaphetamine_cultivation") cocaine_possession = drug_info[iso].get("cocaine_possession") cocaine_sale = drug_info[iso].get("cocaine_sale") cocaine_transport = drug_info[iso].get("cocaine_transport") cocaine_cultivation = drug_info[iso].get("cocaine_cultivation") canabais_recreational = drug_info[iso].get("canabais_recreational") canabais_medical = drug_info[iso].get("canabais_medical") LOGGER.info(f"Parsing {country_name} to insert into drug table with the following information: {canabais_recreational}. {canabais_medical}.{cocaine_possession}.{methaphetamine_possession}") DB.insert('drugs', country_iso, country_name, methaphetamine_possession, methaphetamine_sale, methaphetamine_transport, methaphetamine_cultivation, cocaine_possession, cocaine_sale, cocaine_transport, cocaine_cultivation, canabais_recreational, canabais_medical)
def save_cities_timezones(): LOGGER.info("Retreiving timezones information for all countries...") data = adding_lat_and_lng(get_cities_info()) # geolocator = Nominatim(user_agent="travelingstrategy") #con = sqlite3.connect('../countries.sqlite') #cur = con.cursor() # should not create the table every time # change in the future #cur.execute('DROP TABLE IF EXISTS timezones') #con.commit() #cur.execute('CREATE TABLE timezones (city VARCHAR, country_name VARCHAR, country_iso VARCHAR, timezone VARCHAR, lat REAL, lng REAL, utc_offset int)') #SScon.commit() db = Database("countries.sqlite") db.drop_table("timezones") db.add_table("timezones", city="VARCHAR", country_name="VARCHAR", country_iso="VARCHAR", timezone="VARCHAR", la="REAL", lng="REAL",utc_offset = "int") for city_info in data: city = city_info["city"] country_name = city_info["country_name"] country_iso = city_info["country_iso"] timezone = city_info["timezone"] lat = city_info["lat"] lng = city_info["lng"] utc_offset = city_info["utc_offset"] LOGGER.success(f"{country_name} was sucefuly save into the timezone table with the following information: {country_iso} and {timezone}") db.insert("timezones",city, country_name, country_iso, timezone, lat, lng, utc_offset) LOGGER.success{f'{country_name} successfully saved to the database.'} db.close_connection()
def save_to_MU(): LOGGER.info(f'Saving and parsing Mauritius into the databse') driver = create_driver() LOGGER.info('Begin parsing for Mauritius advisory') try: wiki_visa_url = wiki_visa_url_MU wiki_visa_ob = wiki_visa_parser(wiki_visa_url, driver) visas = wiki_visa_ob.visa_parser_table() LOGGER.success( 'Parsing for Mauritius advisory has been successfully completed') except Exception as error_msg: LOGGER.error( f'Error has occured while parsing for Mauritius advisory because of the following error: {error_msg}' ) info = {} array_info = [] # create an an sqlite_advisory object db = Database("countries.sqlite") db.drop_table("MU") db.add_table("MU", country_iso="text", name="text", advisory_text="text", visa_info="text") LOGGER.info('Saving Mauritius table into the database') try: for country in visas: iso = find_iso_of_country(country) if (iso != ""): name = country LOGGER.info(f'Saving {name}') visa = visas[country].get( 'visa') #dictionary for visa info is country{visa:text} advisory = "Not available yet" info = { "country_iso": iso, "name": name, "advisory": advisory, "visa_info": visa } array_info.append(info) print(name, " ", visa, " ", advisory) db.insert("MU", iso, name, advisory, visa) LOGGER.success( f'{name} was sucessfully saved to the database with the following information: {visa}. {advisory}.' ) LOGGER.success( 'Mauritius table successfully saved to the database') except Exception as error_msg: LOGGER.error( f'An error has occured while saving Mauritius table to the database because of the following error: {error_msg}' ) db.close_connection() quit_driver(driver) with open('./advisory-mu.json', 'w') as outfile: json.dump(array_info, outfile)
def ingredients(): form = ingredient_form() delete = delete_form() if form.validate_on_submit(): Database().add_ingredient(form.data['name'], form.data['search'], form.data['quantity'], form.data['unit']) return redirect('/ingredients') ingredients = Database().get_all_ingredients() return render_template('ingredient_list.html', title='Ingredients', ingredients=ingredients, form=form, delete=delete)
def index(request): if request.method == "POST": dn_ip = request.POST.get("dn_ip") date = datetime.date.today() port = force_int(request.POST.get("port")) source = request.POST.get("source") note = source_parse(request.POST.get("note")) db = Database() msg = "" if dn_ip and source: if check_ip(dn_ip): if not port and note: msg = db.insert_malicious_ip_record(ip=dn_ip, date=date, source=source, note=note) elif port and not note: msg = db.insert_malicious_ip_record(ip=dn_ip, date=date, source=source, port=port) else: msg = db.insert_malicious_ip_record(ip=dn_ip, date=date, source=source) else: if not port and note: msg = db.insert_malicious_dn_record(dn=dn_ip, date=date, source=source, note=note) elif port and not note: msg = db.insert_malicious_dn_record(dn=dn_ip, date=date, source=source, port=port) else: msg = db.insert_malicious_dn_record(dn=dn_ip, date=date, source=source) else: return render_to_response("add/index.html", context_instance=RequestContext(request)) else: return render_to_response("add/index.html", context_instance=RequestContext(request)) if msg: return render_to_response("error.html", {"error": str(msg)}, context_instance=RequestContext(request)) else: return render_to_response( "sucess.html", {"message": "Add {} to DB sucessfully".format(dn_ip)}, context_instance=RequestContext(request))
def __test(): db = Database() db.db_init() dbsession = db.db_session() testCVE = Spider(dbsession) result, e = testCVE.get_vulns() if not result: print(e)
def index(request): db = Database() report = dict(total_dn=db.count_dn(), total_alive_dn=db.count_alive_dn(), last_dn=db.last_added_dn(), top_mapping_ip=db.top_mapping_ip(), top10_country_amount=db.top10_country_amount()) return render_to_response("dashboard/index.html", {"report": report}, context_instance=RequestContext(request))
def handle(self): self.database = getattr(self, 'database', Database()) # Read line from socket. Each line is an event. self.data = self.rfile.readline().strip() # Get event from data self.parsed = self.event_parsing(self.data) # Save event in database self.database.save_event(EVENT_POOL_NAME, self.parsed)
def __init__(self): super().__init__( command_prefix=commands.when_mentioned_or( environ.get('PREFIX', '/')), help_command=None, ) self.db = Database(self) # self.qt = Question(self) with open("json/question.json", mode="r", encoding='utf-8') as f: self.qu = json.load(f) f.close()
def create(): db = Database() weapon = Weapon() weapon.weapon_name = read_input(text="Weapon Name (str): ") weapon.variant_id = read_input(text="Variant ID (int): ", data_type=lambda x: int(x)) weapon.wear_from = read_input(text="Wear from (int) [0]: ", default=0, data_type=lambda x: int(x)) weapon.wear_to = read_input(text="Wear to (int) [100]: ", default=100, data_type=lambda x: int(x)) weapon.stat_track = read_input(text="Stat-Track (int) [0]: ", default=100, data_type=lambda x: bool(x)) db.save_weapon(weapon)
def __init__(self): try: self.db = Database( None) #reading all connection data from config.ini logging.debug('Database connected...') except: #if DB server is not accessible should wrap up an close connection here logging.debug( 'Connection to DB failed, try running admin first...') self.form = cgi.FieldStorage() self.user = EditorialUser(self.form, self.db) self.content = EditorialContent(self.form, self.user, self.db)
def __init__(self): super().__init__( command_prefix=commands.when_mentioned_or(environ.get('PREFIX', './')), help_command=None, ) self.db = Database(self) self.system = System() self.slash = SlashCommand(self, sync_commands=True) # self.qt = Question(self) with open("json/qu.json", mode="r", encoding='utf-8') as f: self.qu = json.load(f) f.close()
def save_to_UK(): LOGGER.info("Begin parsing and saving for United Kingdom table...") driver = create_driver() LOGGER.info('Parsing the visa requirements of all countries for United Kingdom advisory') try: wiki_visa_url ="https://en.wikipedia.org/wiki/Visa_requirements_for_British_citizens" wiki_visa_ob = wiki_visa_parser(wiki_visa_url,driver) visas = wiki_visa_ob.visa_parser_table() data = parse_all_countries_advisory() LOGGER.success('Successfully parsed the visa requirements of all countries for United Kingdom advisory') except Exception as error_msg: LOGGER.error(f'An error has occured while retrieving the visa reuirements of all countries for United Kingdom advisory because of the following error: {error_msg}') info = {} array_info = [] # create an an sqlite_advisory object] db = Database("countries.sqlite") db.drop_table("GB") db.add_table("GB", country_iso="text", name="text", advisory_text="text", visa_info="text") LOGGER.info('Saving countries informations into the UK table') try: for country in visas: iso = find_iso_of_country(country) if(iso != ""): try: name = country advisory = data[iso].get('advisory') #dictionary for the travel advisory is iso{advisory:text} visa_info = visas[country].get('visa') #dictionary for visa info is country{visa:text} info = { "country_iso" : iso, "name": name, "advisory": advisory, "visa_info": visa_info } array_info.append(info) LOGGER.success(f"Saving {name} into the UK table with the following information: {visa_info}. {advisory}") db.insert("GB",iso,name,advisory,visa_info) LOGGER.success(f'{name} sucesfully saved to the database.') except KeyError: LOGGER.warning(f'This country doesn\'t have advisory info: {country}') print("This country doesn't have advisory info: ",country) LOGGER.info(f'Its ISO is {iso}') print("Its ISO is: ",iso) LOGGER.success('All countries have been succesfully saved into the UK table') except Exception as error_msg: LOGGER.error(f'An error has occured while saving countries into the UK table because of the following: {error_msg}') db.close_connection() with open('./advisory-uk.json', 'w') as outfile: json.dump(array_info, outfile)