Esempio n. 1
0
 def delete_directory(directory, commit=True):
     """Deletes an existing directory record from the database
     :param directory: Directory model object to be deleted
     :param commit: Specifies whether to commit to database
     """
     DB().session.delete(directory)
     if commit:
         DB().session.commit()
def recipe_ingredient_options(value):
    if value is not None:
        db = DB()
        names = db.return_by_one_param('ingredients','category',value)
        return [{'label': i, 'value': i} for i in names]
    else:
        db = DB()
        names = db.return_all_names('ingredients')
        return [{'label': i, 'value': i} for i in names]
Esempio n. 3
0
    def create_directory(directory, commit=True):
        """Creates a new directory record in database
        :param directory: Directory model object to be inserted
        :param commit: Specifies whether to commit to database
        """
        directory_db = DB().session.add(directory)
        if commit:
            DB().session.commit()

        return directory_db
Esempio n. 4
0
    def create_session(session, commit=True):
        """Creates a new session record in database
        :param session: Session model object to be inserted
        :param commit: Specifies whether to commit to database
        """
        session_db = DB().session.add(session)
        if commit:
            DB().session.commit()

        return session_db
Esempio n. 5
0
    def delete_file(file, commit=True):
        """Deletes an existing file record from the database
        :param file: File model object to be deleted
        :param commit: Specifies whether to commit to database
        """

        FileDao.remove_data_in_file(file)
        DB().session.delete(file)
        if commit:
            DB().session.commit()
Esempio n. 6
0
    def create_file(file, commit=True):
        """Creates a new file record in the database
        :param file: File model object to be inserted
        :param commit: Specifies whether to commit to database
        """
        file_db = DB().session.add(file)
        if commit:
            DB().session.commit()

        return file_db
Esempio n. 7
0
 def get_directories_from_current_directory(current_directory):
     """Returns all directories inside a current directory
     :param current_directory: Directory model object
     specifying current directory
     """
     return DB().session.query(Directory).filter_by(
         directory_id=current_directory.id).all()
Esempio n. 8
0
 def do_scan(self, target, options="-n -sS --host-timeout 600 --open"):
     # 记录结果
     db = DB()
     nmproc = NmapProcess(target, options)
     nmproc.run_background()
     while nmproc.is_running():
         print("Nmap Scan running: ETC: {0} DONE: {1}%".format(
             nmproc.etc, nmproc.progress))
         time.sleep(2)
     print("rc: {0} output: {1}".format(nmproc.rc, nmproc.summary))
     try:
         # 创建文件名
         md5 = hashlib.md5()
         md5.update(target)
         hash = md5.hexdigest()
         # with(open("data/nmap/" + hash + ".xml", "w")) as f:
         #     f.write(nmproc.stdout)
     except NmapParserException as e:
         print("Exception raised while parsing scan: {0}".format(e.msg))
     # 扫描完成,解析结果
     print {"status": 1, "result": hash}
     db.Nmap.update_one({"target": target},
                        {"$set": {
                            "status": 1,
                            "result": hash
                        }})
Esempio n. 9
0
    def initialize(self):

        self.data = {}
        self.set_header('Content-Type', 'application/json; charset=utf-8')
        self.set_header('Access-Control-Allow-Origin', '*')
        self.set_header('Access-Control-Allow-Methods',
                        'OPTIONS,GET,POST,PUT,PATCH,DELETE')
        self.set_header(
            'Access-Control-Allow-Headers',
            'Origin, X-Requested-With, Content-Type, Accept, Authorization')
        self.Authorization = self.request.headers.get('Authorization')
        self.JwtAuth = JwtAuth()
        self.User = {}
        self.isAuth = False
        if bool(self.Authorization):
            self.JwtAuth.autorize(self.Authorization)
            self.isAuth = self.JwtAuth.Status
            self.User = self.JwtAuth.User

        self.Header = self.request.headers._dict
        self.Header['RemoteIp'] = self.request.remote_ip
        self.DB = DB(self.User)

        if bool(self.request.body):
            self.data = json.loads(self.request.body.decode('utf-8'))
Esempio n. 10
0
 def get_files_from_current_directory(current_directory):
     """Return all files with in the current directory
     :param current_directory: Directory model object
     specifying current directory
     """
     return DB().session.query(File).filter_by(
         directory_id=current_directory.id).all()
Esempio n. 11
0
def main():
    """Start Finder Terminal and create connection to DB"""
    db = DB()
    db.connect(os.path.join(os.getcwd(), 'finder.db'))

    terminal = BaseTerminal(commands=DEFAULT_COMMANDS)
    terminal.run()
def recipe_ingredient_unit_options(value):
    if value is not None:
        db = DB()
        units = db.return_ingredient_units('ingredients','name',value)
        return [{'label': i, 'value': i} for i in units]
    else:
        return [{'label': '', 'value': ''}]
Esempio n. 13
0
def get_or_downlod_districts(region_code):
    db = DB()
    if db.region_has_districts(region_code):
        return db.get_all_districts_by_region(region_code)
    else:
        district_to_db(region_code)
        return db.get_all_districts_by_region(region_code)
Esempio n. 14
0
    def get_root_directory():
        """Returns root directory, creates one if it does not exist"""
        root_db = DB().session.query(Directory).filter_by(is_root=True).first()
        if root_db is None:
            root_db = DirectoryDao._create_root_directory()

        return root_db
Esempio n. 15
0
def init(args):
    tree = VPTree(distance_fn=image.distance_fn)
    files = []
    walkdir(
        args.dir, args.recursive, lambda path: init_func(
            path, tree, files, args.hash_type, args.hash_size))
    db = DB(tree, files, args.hash_type, args.hash_size)
    db.encode(args.db)
 def append_request(self, request_id):
     db = DB()
     request = db.get_request_by_id(request_id)
     if request.try_num < 3:
         logging.info('Add request to shedule id: ' + str(request_id))
         self.queue.append(request)
     else:
         db.set_not_found(request_id)
Esempio n. 17
0
    def run(self):
        if self.options[0].exists:
            directory = self.context.parse(self.arguments[0].data)

            self.recursive_remove(directory)
            DB().session.commit()
        else:
            file = self.context.parse(self.arguments[0].data, is_file=True)
            FileDao.delete_file(file)
Esempio n. 18
0
 def scan(self, request, context):
     ips = request.ips
     db = DB()
     for ip in ips:
         db.Nmap.insert({"target": ip, "status": 0})
         print(ip)
     for ip in ips:
         self.do_scan(str(ip))
     return nmap_pb2.ScanResponse(result="success")
Esempio n. 19
0
 def get_directory_from_current_directory(current_directory,
                                          directory_name):
     """Returns directory model object from current directory
     with directory_name
     :param current_directory: Current directory to search for
     :param directory_name: Directory name to search for
     """
     #
     return DB().session.query(Directory).filter_by(
         directory_id=current_directory.id, name=directory_name).first()
def db_to_ingredient_callback(value):
    if value is not None:
        db = DB() 
        ingredient = db.query_by_one_param('ingredients','name',value)[0]
        name = ingredient['name']
        category = ingredient['category']
        serving_gram = ingredient['serving_gram']
        serving_tbsp = ingredient['serving_tbsp']
        serving_oz = ingredient['serving_oz']
        serving_lbs = ingredient['serving_lbs']
        serving_piece = ingredient['serving_piece']
        serving_ml = ingredient['serving_ml']
        serving_cup = ingredient['serving_cup']
        brand = ingredient['preferred_brand']
        store = json.loads(ingredient['suggested_store'])
        calories = ingredient['calories']
        protein = ingredient['protein']
        fat = ingredient['fat']
        carbs = ingredient['carbs']
        fiber = ingredient['fiber']
        sugar = ingredient['sugar']
        sat = ingredient['saturated_fat']
        mono = ingredient['monounsaturated_fat']
        poly = ingredient['polyunsaturated_fat']
        omega3 = ingredient['omega_3_fat']
        omega6 = ingredient['omega_6_fat']
        vitamin_a = ingredient['vitamin_a']
        vitamin_c = ingredient['vitamin_c']
        vitamin_d = ingredient['vitamin_d']
        vitamin_e = ingredient['vitamin_e']
        vitamin_k = ingredient['vitamin_k']
        vitamin_b6 = ingredient['vitamin_b6']
        vitamin_b12 = ingredient['vitamin_b12']
        thiamin = ingredient['thiamin']
        riboflavin = ingredient['riboflavin']
        niacin = ingredient['niacin']
        folate = ingredient['folate']
        pantothenic_acid = ingredient['pantothenic_acid']
        calcium = ingredient['calcium']
        iron = ingredient['iron']
        magnesium = ingredient['magnesium']
        phosphorus = ingredient['phosphorus']
        potassium = ingredient['potassium']
        zinc = ingredient['zinc']
        return name,category,serving_gram,serving_tbsp,serving_oz,\
                serving_lbs,serving_piece,serving_ml,serving_cup,\
                brand,store,calories,protein,fat,carbs,fiber,sugar,\
                sat,mono,poly,omega3,omega6,vitamin_a,vitamin_c,\
                vitamin_d,vitamin_e,vitamin_k,thiamin,\
                riboflavin,niacin,vitamin_b6,folate,\
                vitamin_b12,pantothenic_acid,calcium,\
                iron,magnesium,phosphorus,potassium ,zinc
    else:
        return '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''
Esempio n. 21
0
 def __init__(self):
     self.session = requests.session()
     self.session.headers.update(headers)
     self.db = DB()
     self.crawl_timestamp = int()
     self.url = "https://3g.dxy.cn/newh5/view/pneumonia"
     self.rumor_url = "https://file1.dxycdn.com/2020/0127/797/3393185293879908067-115.json"
     self.overall_count = 0
     self.province_count = 0
     self.area_count = 0
     self.news_count = 0
     self.rumor_count = 0
Esempio n. 22
0
 def generate_essay(self, vk, unprocessed_essay,
                    is_test):  # run only through Pool starmap/map
     new_db_session = DB()
     unprocessed_essay = new_db_session.session.query(Essay).get(
         unprocessed_essay.id)
     unprocessed_essay.processed_text = self.get_essay(
         unprocessed_essay.text)
     if not is_test:
         vk.send(
             unprocessed_essay.user_id,
             f'я закончил читать, вот что я могу сказать:\n{unprocessed_essay.processed_text}',
             forward_messages=unprocessed_essay.message_id)
     new_db_session.session.commit()
     del new_db_session
Esempio n. 23
0
 def remove_data_in_file(file, commit=True):
     """Removes the data in the sectors of the file
     :param file: File model object whose data is
     to be removed
     :param commit: Specifies whether to commit
     to database
     """
     with Monitor(file.id):
         for sector in file.sectors:
             sector.data = None
             sector.order = 0
             sector.file_id = None
         if commit:
             DB().session.commit()
Esempio n. 24
0
 def getTaskStatus(self, request, context):
     db = DB()
     scanning = db.Nmap.count({"status": 0})
     finishing = db.Nmap.count({"status": 1})
     if scanning == 0 and finishing == 0:
         # 如果没有结果的话或者结果为2,表示需要扫描
         return nmap_pb2.StatusResponse(status=nmap_pb2.StatusResponse.INIT)
     if scanning != 0:
         # 如果status为1,说明正在执行
         return nmap_pb2.StatusResponse(
             status=nmap_pb2.StatusResponse.RUNNING)
     if finishing != 0:
         # 如果status为2,说明还没有返回结果
         return nmap_pb2.StatusResponse(
             status=nmap_pb2.StatusResponse.ENDING)
def regions_to_db():
    fields = {'method': 'getRegionsList'}
    payload = utils.create_form_data(fields)
    res = requests.post('https://extra.egrp365.ru/api/extra/index.php',
                        data=payload,
                        headers=utils.HEADERS)
    try:
        json_data = json.loads(res.text)
        if json_data['success']:
            db = DB()
            for x in json_data['data']:
                region = Region(value=x['value'], name=x['name'])
                db.insert(region, 'region_code')
    except Exception as e:
        logging.error('Region loading error. Response text: ' + res.text)
        raise e
Esempio n. 26
0
 def __init__(self):
     self.vk = Vk(Config.token)
     self.db = DB(run_seeders=True)
     controller_essay = ControllerEssay()
     self.handlers = [
         *ControllerBaseRules().handlers, *ControllerStatistics().handlers,
         *ControllerActionWithUser().handlers, *ControllerJokes().handlers,
         *ControllerSettings().handlers, *ControllerCallAdmin().handlers,
         *ControllerRandomPost().handlers, *controller_essay.handlers,
         *ControllerLowPriority().handlers
     ]
     self.special_handlers = [
         handler for handler in self.handlers if handler.get('special')
     ]
     p = Process(target=controller_essay.proceed_essays, args=(self.vk, ))
     p.start()
Esempio n. 27
0
def main(argv):
    logging.basicConfig(
        format=
        u'%(filename)s[LINE:%(lineno)d]# %(levelname)-8s [%(asctime)s]  %(message)s',
        level=logging.DEBUG)
    db = DB()
    if db.table_is_empty('request'):
        logging.info('Table request is empty. Filling...')
        xslx_to_db()
    if db.table_is_empty('region_code'):
        logging.info('Table region_code is empty. Filling...')
        regions_to_db()
    search_all()
    insert_listner = Insertlistner(search_by_id)
    insert_listner.start()
    insert_listner.join()
def add_ingredient_to_recipe(n_clicks,rows,name,quantity,unit):
    if n_clicks > 0 and n_clicks is not None:
        db = DB()
        ingredient = db.query_by_one_param('ingredients','name',name)[0]
        for i in ingredient.keys():
            if i.find(unit) != -1:
                db_quantity = float(ingredient[i])
        rows.append({
            'ingredient': name,
            'quantity': quantity,
            'unit': unit,
            'calories': round(((float(quantity)/db_quantity)*float(ingredient['calories'])),2),
            'protein': round(((float(quantity)/db_quantity)*float(ingredient['protein'])),2),
            'fat': round(((float(quantity)/db_quantity)*float(ingredient['fat'])),2),
            'carbs': round(((float(quantity)/db_quantity)*float(ingredient['carbs'])),2),
        })
    return rows
Esempio n. 29
0
 def getResult(self, request, context):
     db = DB()
     nmap_results = []
     statuses = db.Nmap.find({})
     for status in statuses:
         # 做更多的事情
         filename = "data/nmap/" + status['result'] + ".xml"
         print("[+] parse file: " + filename)
         with open(filename) as f:
             # 文件切片
             while True:
                 report = f.read(1000)
                 if not report:
                     break
                 yield nmap_pb2.NmapResult(target=status['result'],
                                           report=report)
         db.Nmap.remove({"target": status['target']})
Esempio n. 30
0
def search(request):
    db = DB()
    db.increase_try_num(request.id)
    regions = db.get_all_regions()
    cur_region = request.region
    dists = []
    for r in regions:
        dist = lv.distance(cur_region, r.name)
        dists.append((dist, r.value, r.name))
    s = min(dists, key=lambda p: p[0])
    logging.info('Found match for "{}" is "{}" with dist = {}'.format(
        cur_region, s[2], s[0]))
    cur_region_code = s[1]
    if ' г' in cur_region:
        search_in_city(request, cur_region_code)
    else:
        search_in_region(request, cur_region_code)