def setAtts(self, domain, att_dict, keepOld=False): # str below simulates: "'{domain}', '{attribute}', '{value}', {keepOld}"... # which is based on query_insert_atts # insertVals() returns a tuple of 8 values # this is a list comprehension valuesList = ["'{0[0]}', '{0[1]}', '{0[2]}', {0[3]}, {0[4]}, {0[5]}, {0[6]}, '{0[7]}'".format(insertVals(k, t, domain, keepOld)) for k, t in att_dict.items()] insert_vals = '), ('.join(valuesList) # make vals str from list insert_vals = query_insert_atts.format(insert_vals) # print('------') # print(insert_vals) # print('------') sqlExec(insert_vals) # insert into temp table testMode = 0 # set to 16 if you want the sproc to return test results # setting to 32 could potentially delete ALL your data results = call('storeAtts', (self['id'], self['company_id'], len(valuesList), 1, 1, 1, testMode)) # begin test code if testMode == 16: for row in results: for col in row: print(col + ' = ' + str(row.get(col) or 'none')) print('') print('Next Set:') # end test code return results
def loadAllAtts(instance, att_names='all'): # , *argsAsSequ entVals = instance['_entity'] attList = call('loadAtts', (entVals['ent_id'], entVals['ent_ety_id'], entVals['ent_com_id'], '', 0, 0) ); if not attList: print('no att vals found') attList = tuple() instance['_atts_count'] = len(attList[0]) instance['_all_atts_loaded'] = True cacheAtts(instance, attList) return len(attList) # instance['atts']
def fetch(self, domain_name, att_names_values): # if att_names_values is not formated (ie a dict), i need to make it look like: # name:dewey gaedcke,age:39,dob:11081963,sex:m,' # CALL searchForEntity('user', 'attribute', 'name:dewey gaedcke,age:39,dob:11081963,sex:m,', 4, 3, 0); # att_names_values, value_count = strFromParam(att_names_values) value_count = 4 ent_list = call('searchForEntity', (self.type, domain_name, att_names_values, value_count, self.company_id, 0)) return ent_list # contains list of user ID's who have exact match for att:val in att_names_values
def loadEntity(instance, xxx_id): results = call('att.loadEntity', (instance['type'], xxx_id, instance['company_id'], 0))[0] # get 1st row of result tuple instance['_entity'] = results instance['_all_atts_loaded'] = False # print(instance['_entity']) instance['id'] = results['ent_id'] instance['ety_id'] = results['ent_ety_id'] if instance['id'] is None or instance['id'] <= 0: raise ValueError return instance
def getAtts(self, domain = '', att_list = []): # empty list means all """retrieve atts for an entity you can pass simply a comma delim att_name list, or a list of: domain:att_name,domain:att_name, getAtts(domain, att_dict = {'attribute': 'dob', 'attribute': 'facebookHandle', 'preference': 'uiSetting'}) returns a dictionary of lists (domain_name, attribute_name, value, datatype, mod_dttm, att_id) empty or "all" in domain (P1) means: get atts for all domains empty dict (P2) means all atts for the specified domains """ if domain in ('all','','ALL'): domain = '' fld_delim = ':' row_delim = ',' att_names = '' att_param_count = 0 # if not gettina all atts (or all in a given domain), we need to make P4 look like: # domain:att_name,domain:att_name, if att_list and domain: # both not empty param2_type = type(att_list) # DictType, StringType, ListType, TupleType if param2_type == ListType or param2_type == TupleType: # sp_param_type = 'list' att_param_count = len(att_list) padStr = row_delim + domain + fld_delim att_names = padStr.join(att_list) att_names = domain + fld_delim + att_names + row_delim # print('when att_list is list/tuple, params=' + att_names) elif param2_type == DictType: # sp_param_type = 'dict' att_param_count = len(att_list) for dom, att in att_list.items(): att_names = att_names + dom + fld_delim + att + row_delim # print('when att_list is dict, params=' + att_names) elif param2_type == StringType: # sp_param_type = 'string' if att_list.find(fld_delim) == -1: # there is only ONE field (att_name) in this string # need to add the domain for att in att_list.split(row_delim): att_param_count = att_param_count + 1 att_names = att_names + domain + fld_delim + att + row_delim # print('when att_list is string, params=' + att_names) # P4 should either be a domain name, or a list of domain:att_name, vals domain = att_names # end of if stmt # call loadAtts(p_ent_id, p_ent_ety_id, p_ent_com_id, p_att_list, p_att_count, p_encode); attList = call('loadAtts', (self['id'], self['ety_id'], self['company_id'], domain, att_param_count, 0)) # print(attList) cacheAtts(self, attList) return attList
def search(): api_param = request.args value = get(api_param, 'value', '') commad = f"select * from data where text like '%{value}%'" data = call(commad) res = [] for item in data: d = { "id": item[0], 'path': item[1], "title": item[3], "cover": item[4], "description": item[5], "url": item[6], } res.append(d) return {"list": res}
import os import requests import shutil from pydash import get from flask_cors import CORS from copy_factory import CopyFactory from db import create_table, insert_data, call, del_data, search_data from tools import replace_fo, extract_html_text, md5, request_get from flask import Flask, redirect, abort, make_response, jsonify, send_file, request, render_template, send_from_directory create_table('data', 'id-id,path,text,title,cover,description,url') # 创建一张表 call('ALTER TABLE data ADD url TEXT') app = Flask(__name__, template_folder='template', static_folder='/dist') CORS(app, supports_credentials=True) CORS(app, resources=r'/*') root = os.path.join(os.path.dirname(os.path.abspath(__file__)), "dist") # html是个文件夹 def init_folder(href): """ 初始化文件夹,如果不存在,则递归创建 """ name = md5(href) p = './dist/{}'.format(name) try: os.makedirs(p) except BaseException as e: print('异常', e) return p
def test_call_no_args(self): assert db.call("always1") == 1