def run(self, results, objfile): """Writes report. @param results: analysis results dictionary. @param objfile: file object """ database = Database() # Count query using URL hash and file hash count = database.countRagpickerDB(results["Info"]["file"]["md5"], results["Info"]["url"]["md5"]) # If report available for the file and url -> not insert if count == 0: # Create a copy of the dictionary. This is done in order to not modify # the original dictionary and possibly compromise the following # reporting modules. report = dict(results) # Store the report database.insertRagpickerDB(report) count = database.countFamilyDB(objfile.family.parentObjectSHA256) if count == 0: if objfile.family.unpackedObjectSHA256 != "" or len( objfile.family.siblingObjectsSHA256) > 0: log.info(objfile.family) report = dict(objfile.family.__dict__) database.insertFamily(report)
def manage_index(self, dbname): if not self._db_exist(dbname): redirect("/") db = Database(dbname) data = db.list_sites() template = self.env.get_template('manage.html') return template.render(data=data)
def hola(self): clean_console() self.database = Database("facturas") bill1 = self.database.get_data_in_database() loop = True v = True while loop: try: iden = int(input("Digite el número de factura: ")) print() for i in bill1: if i["No. Factura"] == iden: keys = i.keys() for j in keys: print(str(j) + ": " + str(i[j])) print() v = True loop = False break else: v = False if v == False: print("No existe una factura registrada a este número") except: print("Vuelva a digitar el número de factura")
def deleteAll(self): """Deletes all reports. """ count = Database().deleteCodeDB() print "*** MongoDB (CodeDB)***" print "deleted documents:" + str(count) print ""
def main(): #fntdb = Database() currentBlockNum = Database().getBlockNumber() print('getBlockNumber:', currentBlockNum) if currentBlockNum == 0: genesisBlock = Genesis.genesis() Database().createBlock(genesisBlock) else: while True: #for j in range(3): time.sleep(2) newBlock = Block.block() transactions = [] for i in range(5): pendingTran = Database().getPendingTransaction() print(pendingTran) if pendingTran == {}: print('There is no pending transaction now.') continue else: if not Transaction.verifyTransaction(pendingTran): continue #balance verify and nonce if not Database().verifyBalanceAndNonce(pendingTran): print("verify balance and nonce error") continue if not Database().updateBalanceAndNonce(pendingTran): print("update error") continue newBlock = Block.pushTransactionToArray( newBlock, pendingTran) transactions.append(pendingTran) #print("newBlock:", newBlock) parentBlock = Database().getBlockByID(currentBlockNum - 1) key = '97ddae0f3a25b92268175400149d65d6887b9cefaf28ea2c078e05cdc15a3c0a' #print('parent', parentBlock) newBlock = Block.newBlock_POA(newBlock, parentBlock, key) try: Database().createBlock(newBlock) except: print('Error occurs when saving block into db.') continue #fntdb.updateDBAccountStatus(newBlock) #transactions = newBlock['transaction'] if len(transactions) == 0: continue for transaction in transactions: try: Database().createTransaction(transaction) except: print("Error occurs when saving transaction into db.") continue
def create_tables(self): self.db = Database() for f in self.structure_dir: # TODO check sql_path = os.path.join(self.structure_dir, f) sql = open(sql_path, 'r').read() result = self.db.query(sql) if not result: return False return True
def serv(self, client): self.database = Database("service") self.get_all() bucle = True while bucle: service1 = int(input("Digite el codigo del servicio que desea: ")) vehicles_service = self.database.get_multi_by_property("numero", service1) if type(vehicles_service) == list and len(vehicles_service) > 0: client[0].update(vehicles_service[0]) bucle = False else: print() print("No existe un servicio asociado a este codigo. ") print() del client[0]["uid"] self.database = Database("service_asked") self.save(client[0]) self.get_bills(client)
def __init__(self): # Datenbank self.__database = Database() # Kofiguration aus der reporting.conf holen self.__cfgReporting = Config( os.path.join(RAGPICKER_ROOT, 'config', 'reporting.conf')) self.__vxcageEnabled = self.__cfgReporting.getOption( "vxcage", "enabled") self.__vxcageHost = self.__cfgReporting.getOption("vxcage", "host") self.__vxcagePort = self.__cfgReporting.getOption("vxcage", "port")
def get_bills(self,client): self.database = Database("facturas") BD = self.database._count_database() if BD == False: BD = 0 dic = {"No. Factura" : BD} dic.update(client[0]) self.save(dic) print() print("Factura No " + str(BD) + " generada") print()
def __init__(self, config): super(Yueri, self).__init__() self.config = config self.log = Logger(config['Logging']) self._logger = self.log.get_logger('Client') self._logger.info('Starting up') self.prefix = config['Client']['prefix'] self.db = Database(self) self.plugin_manager = PluginManager(self) self.influx = Influx(self)
def create_database(self, name): if name in self.__database_names: ## todo log return None self.__database_names.append(name) db = Database(name) self.__database_objs[name] = db ##todo just for test here self.__current_db = db return db
def deleteAll(self): """Deletes all reports. """ # Alle Ragpicker-Daten aus der MongoDB loeschen count = Database().deleteRagpickerDB() print "*** MongoDB (Ragpicker)***" print "deleted documents:" + str(count) print "" count = Database().deleteFamilyDB() print "*** MongoDB (Family)***" print "deleted documents:" + str(count) print "" count = Database().deleteSandboxTaskQueueDB() print "*** MongoDB (SandboxTaskQueue)***" print "deleted documents:" + str(count) print ""
def main(): db_file = os.getenv("db_file") database = Database(db_file) items = Items(database) clients = Clients(database) purchases = Purchases(database) create_tables(database) while True: client_barcodes = [] barcode = input().strip().upper() while barcode_enum(barcode) is BarcodeType.Client: client_barcodes.append(barcode) barcode = input().strip().upper() client_list = [] for client_barcode in client_barcodes: client = clients.get_by_barcode(client_barcode) client_list.append(client) if client else None if not len(client_list): continue print("Clients: {}".format(", ".join( [str(client) for client in client_list]))) product = items.get_by_barcode(barcode) print("Scanned product: {}".format(str(product))) if product: price_per_person = product.price if len(client_list) > 1: price_per_person = ceil( product.price * 20 / len(client_list)) / 20 # ceil with 2 decimals print("Price paid per person: {}".format(str(price_per_person))) for client in client_list: purchase = Purchase.create(product, client, price_per_person) purchases.persist(purchase) client.balance += price_per_person clients.persist(client) print(purchase) product.stock -= 1 items.persist(product) print("Purchase registered") else: print("No item scanned")
def __init__(self): self.totalScore = 0 # sum of scores self.numberScores = 0 # number of scores entered self.processName = multiprocessing.current_process().name self.task = dict() self.cfgPreProcessing = Config( os.path.join(RAGPICKER_ROOT, 'config', 'preProcessing.conf')) self.cfgProcessing = Config( os.path.join(RAGPICKER_ROOT, 'config', 'processing.conf')) self.cfgReporting = Config( os.path.join(RAGPICKER_ROOT, 'config', 'reporting.conf')) self.cfgCrawler = Config( os.path.join(RAGPICKER_ROOT, 'config', 'crawler.conf')) self.database = Database() log.info("INIT " + self.processName)
def export_data(metadata: list, tasks: list, config: LightWeightMethodConfig): if config.recursive: config.dest_path.mkdir(exist_ok=True) move_output_files(config) database = Database() for task in tasks: metadata[task['id']][3] = task['success'] metadata[task['id']][4] = task['err_msg'] paper = metadata[task['id']] try: database.update_query(paper[0], paper[3], paper[4]) except Exception as e: continue save_metadata(metadata, str(config.dest_path / "stats.csv"))
def placa(self, client): self.database = Database("vehicles") self.get_all() print() bucle = True while bucle: plate = input("Digite la placa del vehiculo que desea realizar el servicio: ") customer_vehicles = self.database.get_multi_by_property("placa", plate) if type(customer_vehicles) == list and len(customer_vehicles) > 0: client[0].update(customer_vehicles[0]) bucle = False else: print() print("No existe un vehiculo asociado a esta placa. ") print()
def _saveReportInMongoDB(self, sha256): database = Database() count = database.countCodeDB(sha256) # If report available for the file and url -> not insert if count == 0: # GetReport from CodeDB by HTTPS report = self._getCodeDBReport(sha256) # Create a copy of the dictionary. This is done in order to not modify # the original dictionary and possibly compromise the following # reporting modules. report = dict(report) # Store the report and retrieve its object id. database.insertCodeDB(report) log.info("Saved CodeDB-Report %s" % sha256)
def database(self, action): if action == "create": name = request.forms.get("dbname").replace(" ", "_") if name.endswith(".db"): name = name.replace(".db", "") name = "".join([ letter for letter in name if letter.isalnum() or letter == "_" ]) name = name + ".db" name = name.upper() db = Database(database=name) db.create_base() elif action == "delete": file = request.forms.get("dbtodel") if self._db_exist(file): os.remove(str(os.getcwd()) + "/data/" + file) redirect("/")
def main(): fntdb = Database() currentBlockNum = fntdb.getBlockNumber() print('getBlockNumber:', currentBlockNum) if currentBlockNum == 0: genesisBlock = Genesis.genesis() fntdb.createBlock(genesisBlock) else: #while True: for j in range(1): time.sleep(2) newBlock = Block.block() for i in range(5): pendingTran = fntdb.getPendingTransaction() print(pendingTran) if pendingTran == {}: print('There is no pending transaction now.') continue else: if not Transaction.verifyTransaction(pendingTran): continue #balance verify and nonce if not fntdb.verifyBalanceAndNonce(pendingTran): print("verify balance and nonce error") continue if not fntdb.updateBalanceAndNonce(pendingTran): print("update error") return False newBlock = Block.pushTransactionToArray(newBlock, pendingTran) #print("newBlock:", newBlock) parentBlock = fntdb.getBlockByID(currentBlockNum - 1) key = '8c1eba13a46fd0e18ee22e5e3da7cf139977090040622a83' #print('parent', parentBlock) newBlock = Block.newBlock_POA(newBlock, parentBlock, key) try: fntdb.createBlock(newBlock) except: print('Error occurs when saving block into db.') continue #fntdb.updateDBAccountStatus(newBlock) """
def test_creating_table(self): db = Database("db") age = Field("age") name = Field("name") field_name_map = {"age": age, "name": name} table = db.create_table("customer", field_name_map) self.assertEqual(table != None, True) table.add_field("age", age) table.insert({"age": 12}) data = table.search(["age"]) right_data = [[12]] self.assertEqual( all(data[i][j] == right_data[i][j] for i in range(len(right_data)) for j in range(len(right_data[0]))), True)
def relation(self): bucle = True self.database = Database("clients") while bucle: print("Digite s en cualquier momento para salir.") client1 = str( input("Digite el numero de identificación del cliente: ")) if client1.lower() != "s": client = int(client1) client4 = self.database.get_multi_by_property("No ID", client) if type(client4) == list and len(client4) > 0: self.placa(client4) self.serv(client4) self.ciclo(client4) print("Transacción confirmada") bucle = False else: print() print("No existe un cliente asociado a este numero de identificación.") print() else: bucle = False
def __init__(self): self.name = "main" self.prompt_session = PromptSession( 'IoTMap > ', auto_suggest=AutoSuggestFromHistory(), enable_history_search=True, complete_in_thread=True, complete_while_typing=True) self.dc = DBController() self.options = self.get_options() self.contexts = [ Sniffing(self.prompt_session, self.dc, self.options['sniffing']), Database(self.prompt_session, self.dc), Modelling(self.prompt_session, self.dc, self.options['modelling']), ] self.prompt_session.completer = WordCompleter( [ctx.name for ctx in self.contexts] + ['exit', 'help'], ignore_case=True) self.prompt_session.contexts = self.contexts self.prompt_session.path_completer = PathCompleter() self.current_context = self
def __init__(self): load_dotenv() Database().connect()
import graphene from graphene import resolve_only_args from core.database import Database from core.schemas.encounter import Encounter from core.schemas.facility import Facility from core.schemas.obs import Obs from core.schemas.patient_identifier import PatientIdentifier from core.schemas.person_address import PersonAddress from core.schemas.person_attribute import PersonAttribute from core.schemas.person_name import PersonName db = Database() class Patient(graphene.ObjectType): def __init__(self, **entries): self.__dict__.update(entries) id = graphene.ID() gender = graphene.String() birthdate = graphene.String() birthdate_estimated = graphene.String() dead = graphene.String() death_date = graphene.String() cause_of_death = graphene.String() creator = graphene.String() date_created = graphene.String() changed_by = graphene.String() date_changed = graphene.String()
def __init__(self, bot): super().__init__(bot) db_user = getenv('DB_USER') db_passwd = getenv('DB_PASSWORD') self.db = Database(db_user, db_passwd) self.db.cur.execute("USE nextbot;")
from datetime import datetime from random import choice from core.ffmpeg import vidmark, take_screen_shot from core.clean import delete_all, delete_trash from pyrogram import Client, filters from configs import Config from core.database import Database from core.display_progress import progress_for_pyrogram, humanbytes from humanfriendly import format_timespan from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery from pyrogram.errors import InputUserDeactivated, UserIsBlocked from pyrogram.errors.exceptions.flood_420 import FloodWait from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant, UsernameNotOccupied, ChatAdminRequired, PeerIdInvalid, MessageNotModified AHBot = Client(Config.BOT_USERNAME, bot_token=Config.BOT_TOKEN, api_id=Config.API_ID, api_hash=Config.API_HASH) db = Database(Config.DATABASE_URL, Config.BOT_USERNAME) broadcast_ids = {} async def send_msg(user_id, message): try: await message.forward(chat_id=user_id) return 200, None except FloodWait as e: await asyncio.sleep(e.x) return send_msg(user_id, message) except InputUserDeactivated: return 400, f"{user_id} : deactivated\n" except UserIsBlocked: return 400, f"{user_id} : blocked the bot\n" except PeerIdInvalid: return 400, f"{user_id} : user id invalid\n"
def __init__(self): self.database = Database()
def run(self, objfile): self.key = "BlueCoatMAA" self.score = -1 host = self.options.get("host") port = self.options.get("port") timeout = self.options.get("timeout", 120) apikey = self.options.get("apikey") owner = self.options.get("user") https = self.options.get("https") database = Database() returnValue = {} if not host or not port or not apikey or not owner: raise Exception("BlueCoatMAA is not configured correctly") try: fileName = objfile.file.get_fileSha256() file_data = objfile.file.file_data message = MultiPartForm() message.add_file_data('unused', filename=fileName, file_data=file_data, mimetype='application/octet-stream') message.add_field('owner', owner) headers = {'Content-type': message.get_content_type()} h = httplib2.Http() protocol = "http" if https: protocol = "https" h = httplib2.Http(".cache", disable_ssl_certificate_validation=True) response, content = h.request( '%s://%s:%s/rapi/samples/basic?token=%s' % (protocol, host, port, apikey), "PUT", body=message.toBlueCoatString(), headers=headers) if not "'status': '200'" in str(response): log.error(str(content)) raise Exception(str(content)) data = json.loads(content) sample_id = data['results'][0]['samples_sample_id'] log.info("%s upload as new sample_id %d" % (fileName, sample_id)) headers = {'Content-Type': 'application/x-www-form-urlencoded'} parameters = {} parameters["sample_id"] = sample_id parameters["env"] = 'ivm' parameters["log_task"] = 1 parameters["tp_IVM.TIMEOUT"] = timeout response, content = h.request('%s://%s:%s/rapi/tasks?token=%s' % (protocol, host, port, apikey), 'PUT', body=urllib.urlencode(parameters), headers=headers) if not "'status': '200'" in str(response): log.error(str(content)) raise Exception(str(content)) data = json.loads(content) task_id = data['results'][0]['tasks_task_id'] log.info("new task_id %d" % task_id) returnValue = {"sample_id": sample_id, "task_id": task_id} #Insert Task-State-Report database.insertSandboxTaskStatus( sandboxName=MAA_SANDBOX_NAME, sha256=objfile.file.get_fileSha256(), taskID=task_id, sampleID=sample_id, taskState=MAA_TASK_STATE_START) except Exception as e: raise Exception("Failed to send the file to the BlueCoatMAA: %s" % e) return returnValue
## --- Logger --- ## logging.basicConfig(level=logging.INFO) ## --- Bot --- ## TGraph = Client( Credentials.SESSION_NAME, bot_token=Credentials.BOT_TOKEN, api_id=Credentials.API_ID, api_hash=Credentials.API_HASH, ) ## --- Sub Configs --- ## db = Database(Credentials.MONGODB_URI, Credentials.SESSION_NAME) broadcast_ids = {} home_text = None if Credentials.HOME_MSG: home_text = Credentials.HOME_MSG else: home_text = """ Hi, [{}](tg://user?id={}) I am Telegram to telegra.ph Image Uploader Bot. Send me any Image I will upload to telegra.ph and give you link. """ about_text = None if Credentials.ABOUT_MSG: about_text = Credentials.ABOUT_MSG else:
from lib.logging import Logging from lib.hashing import Hashing from core.database import Database console = Logging.console database = Database() while 1: try: console.clear() Logging.print_banner() Logging.print_info( f'enter a query to search into Stranger Things IoT\n[green underline]total database rows count:[/green underline] [white]{database.get_rows_count()}[/white]' ) query = console.input(' [red][[white]%[/white]][/red][white] ') if len(query) <= 2: Logging.print_failed( 'query must be longer than 2 chars, press "enter" to continue...' ) console.input() continue results = database.search_query( query) # search the query into the sqlite database if not len(results): Logging.print_failed(