def search(self, command): LP = Query() return self.db.search(LP.alias == command)
def get(self, command): LP = Query() return self.db.get(LP.alias == command)
import os import json from tinydb import TinyDB, Query from ..server_config import USER_DB_PATH db = TinyDB(os.path.join(os.path.dirname(__file__), '..', USER_DB_PATH)) User = Query() def choose_identifier(original): def wrapper(**kwargs): if kwargs.get('slack_id'): kwargs['id_key'] = 'slack_id' kwargs['id_value'] = kwargs.get('slack_id') del kwargs['slack_id'] elif kwargs.get('username'): kwargs['id_key'] = 'username' kwargs['id_value'] = kwargs.get('username') del kwargs['username'] elif kwargs.get('email'): kwargs['id_key'] = 'email' kwargs['id_value'] = kwargs.get('email') del kwargs['email'] else: return 'Please specify email, username or id' return original(**kwargs) return wrapper
def search_in_database(self, current_program, database, suchbegriffe): table = 'table_' + current_program table_lama = database.table(table) _file_ = Query() string_in_list_af = lambda s: True if (s in suchbegriffe['af'] or is_empty( suchbegriffe['af'])) else False string_in_list_klasse = lambda s: True if (s in suchbegriffe[ 'klasse'] or is_empty(suchbegriffe['klasse'])) else False string_in_list_info = lambda s: True if (s in suchbegriffe[ 'info'] or is_empty(suchbegriffe['info'])) else False lineedit_in_erweitert = lambda s: True if (r"{}".format(suchbegriffe[ 'erweiterte_suche'].lower()) in s.lower() or is_empty(suchbegriffe[ 'erweiterte_suche'])) else False search_True = lambda s: True def include_drafts(value): if value == False: return True else: if self.cb_drafts.isChecked(): return True else: return False def lineedit_in_bilder(value): for bilder in value: if suchbegriffe['erweiterte_suche'].lower() in bilder: return True return False def lineedit_in_name(value): simplified_search = shorten_gk( suchbegriffe['erweiterte_suche'].lower()) simplified_value = shorten_gk(value) # print(short_gk)# _list = simplified_search.split("-") gk_search = _list[0] num_search = _list[-1] _list = simplified_value.split("-") gk_value = _list[0] num_value = _list[-1] if "*" in gk_search: gk_search = gk_search.replace("*", ".*") x = re.fullmatch("{}".format(gk_search), gk_value) if x == None: return False elif gk_search != gk_value: return False if "*" in num_search: num_search = num_search.replace("*", ".*") x = re.fullmatch("{}".format(num_search), num_value) if x == None: return False elif num_search != num_value: return False return True if suchbegriffe['erweiterte_suche'] == "": erweiterte_suche = eval("_file_.titel.test(search_True)") elif self.comboBox_suchbegriffe.currentText() == "Titel": erweiterte_suche = eval("_file_.titel.test(lineedit_in_erweitert)") elif self.comboBox_suchbegriffe.currentText() == "Inhalt": erweiterte_suche = eval("_file_.content.test(lineedit_in_erweitert)") elif self.comboBox_suchbegriffe.currentText() == "Quelle": erweiterte_suche = eval("_file_.quelle.test(lineedit_in_erweitert)") elif self.comboBox_suchbegriffe.currentText() == "Bilder": erweiterte_suche = _file_.bilder.test(lineedit_in_bilder) elif self.comboBox_suchbegriffe.currentText() == "Aufgaben-ID": erweiterte_suche = _file_.name.test(lineedit_in_name) gesammeltedateien = [] if current_program == 'lama_1' or ( current_program == 'cria' and self.combobox_searchtype.currentIndex() == 0): if suchbegriffe['themen'] != []: gesammeltedateien = table_lama.search( (_file_.themen.any(suchbegriffe['themen'])) & (_file_.af.test(string_in_list_af)) & (_file_.klasse.test(string_in_list_klasse)) & (_file_.info.test(string_in_list_info)) & (erweiterte_suche) & (_file_.draft.test(include_drafts))) else: gesammeltedateien = table_lama.search( (_file_.af.test(string_in_list_af)) & # (_file_.klasse.test(string_in_list_klasse)) & (_file_.info.test(string_in_list_info)) & (erweiterte_suche) & (_file_.draft.test(include_drafts))) elif current_program == 'cria' and self.combobox_searchtype.currentIndex( ) == 1: def themen_included(value): for all in suchbegriffe['themen']: if all not in value: return False return True # if suchbegriffe['themen'] != []: gesammeltedateien = table_lama.search( (_file_.themen.test(themen_included)) & (_file_.af.test(string_in_list_af)) & (_file_.klasse.test(string_in_list_klasse)) & (_file_.info.test(string_in_list_info)) & (erweiterte_suche) & (_file_.draft.test(include_drafts))) else: gesammeltedateien = table_lama.search( (_file_.af.test(string_in_list_af)) & # (_file_.klasse.test(string_in_list_klasse)) & (_file_.info.test(string_in_list_info)) & (erweiterte_suche) & (_file_.draft.test(include_drafts))) elif current_program == 'lama_2': def gk_in_list(value): for all in value: if all not in suchbegriffe['themen']: return False return True if suchbegriffe['themen'] == []: gesammeltedateien = table_lama.search( (_file_.klasse.test(string_in_list_klasse)) & (_file_.info.test(string_in_list_info)) & (erweiterte_suche) & (_file_.draft.test(include_drafts))) elif self.combobox_searchtype.currentIndex() == 0: gesammeltedateien = table_lama.search( (_file_.themen.any(suchbegriffe['themen'])) & (_file_.klasse.test(string_in_list_klasse)) & (_file_.info.test(string_in_list_info)) & (erweiterte_suche) & (_file_.draft.test(include_drafts))) elif self.combobox_searchtype.currentIndex() == 1: gesammeltedateien = table_lama.search( (_file_.themen.test(gk_in_list)) & (_file_.klasse.test(string_in_list_klasse)) & (_file_.info.test(string_in_list_info)) & (erweiterte_suche) & (_file_.draft.test(include_drafts))) return gesammeltedateien
from tinydb.operations import delete from tinydb_appengine.storages import EphemeralJSONStorage from cachetools import cached, TTLCache from coderbot import CoderBot from program import ProgramEngine, Program from config import Config BUTTON_PIN = 16 bot_config = Config.get() bot = CoderBot.get_instance( motor_trim_factor=float(bot_config.get("move_motor_trim", 1.0)), encoder=bool(bot_config.get("encoder")) ) query = Query() def get_serial(): """ Extract serial from cpuinfo file """ cpuserial = "0000000000000000" try: f = open('/proc/cpuinfo', 'r') for line in f: if line[0:6] == 'Serial': cpuserial = line[10:26] f.close() except Exception: cpuserial = "ERROR000000000"
import sys import getopt from xml.etree import ElementTree #Open the config.yml file to retreive configuration details with open("config.yml", 'r') as stream: try: config = yaml.load(stream) except yaml.YAMLError as exc: print(exc) #Initialize databases for storing data locally hosts_db = TinyDB('hosts_db.json') threats_db = TinyDB('threats_db.json') domains_db = TinyDB('domains_db.json') querydb = Query() def main(argv): #Sets if automatic quarantine is enabled. Use command-line option --quarantine quarantine = 0 print('Starting headless, will query for IOCs every hour.') try: opts, args = getopt.getopt(argv, "hi:o:", ["quarantine"]) except getopt.GetoptError: print('headless.py --quarantine') sys.exit(2) for opt, arg in opts: if opt == '-h':