def get(self): parser = reqparse.RequestParser() #data obtenida por get parser.add_argument('province', help='This field cannot be blank', required=True) parser.add_argument('startdate') parser.add_argument('enddate') data = parser.parse_args() prov = data['province'] startdate = data['startdate'] enddate = data['enddate'] session = Session() #consulta en bbdd tabla provincia, #filtra por fecha inicial y fecha final provData = session.query(Provincia).filter(and_( Provincia.provincia == prov, Provincia.fecha >= startdate, Provincia.fecha <= enddate )).all() session.close() return jsonify({ 'data': [result.serialized for result in provData], 'province': data['province'], 'startdate': data['startdate'], 'enddate': data['enddate'], 'disclaimer': 'Todos los datos fueron recolectados de los reportes diarios del ministerio de salud de Argentina https://www.argentina.gob.ar/coronavirus/informe-diario' })
def listaData(): session = Session() # Consult DB Argentina table and obtain all data argData = session.query(Argentina).all() session.close() data = [result.serialized for result in argData] return data
def get(self): # Open session in database session = Session() # Consult DB Argentina table and obtain all data provData = session.query(Provincia).all() session.close() # Return all data in JSON return jsonify({ 'data': [result.serialized for result in provData], 'disclaimer': 'Todos los datos fueron recolectados de los reportes diarios del ministerio de salud de Argentina https://www.argentina.gob.ar/coronavirus/informe-diario' })
def get(self): parser = reqparse.RequestParser() parser.add_argument('date', help='This field cannot be blank', required=True) session = Session() date_ = parser.parse_args() arg = session.query(Argentina).filter(Argentina.date == date_['date']) session.close() return jsonify({ 'data': [result.serialized for result in arg], 'disclaimer': 'Todos los datos fueron recolectados de los reportes diarios del ministerio de salud de Argentina https://www.argentina.gob.ar/coronavirus/informe-diario' })
def log(user, passw): session = Session() usr = session.query(User).filter(User.Name == user).first() session.close() ret = None if usr: password = usr._pass.encode('utf-8') if bcrypt.checkpw(passw, password): ret = True else: ret = False return ret
def get(self): parser = reqparse.RequestParser() parser.add_argument('province', help='This field cannot be blank', required=True) # Open session in database data = parser.parse_args() prov = data['province'] session = Session() # Consult DB Argentina table and obtain all data provData = session.query(Provincia).filter(Provincia.provincia == prov).all() session.close() # Return all data in JSON return jsonify({ 'data': [result.serialized for result in provData], 'disclaimer': 'Todos los datos fueron recolectados de los reportes diarios del ministerio de salud de Argentina https://www.argentina.gob.ar/coronavirus/informe-diario' })
def cal_min(ch, method, properties, body): print(body) info = body.decode('utf8').split(",") print("info", info) exchange = info[1] day_min = info[2] contract = info[0] date = info[3].split(" ")[0] # if exchange not in ALLOW_EXCHANGE: # return replace_info = re.findall(r'(\d+)', contract) varieties = contract.replace(replace_info[0], "") if varieties.lower() not in ALLOW_VARIETIES: return db = Session() cal_contract_vals(db, varieties, contract, date, exchange) db.close()
def get(self): # Object parser and create argument parser = reqparse.RequestParser() parser.add_argument('startdate', help='This field cannot be blank', required=True) parser.add_argument('enddate', help='This field cannot be blank', required=True) session = Session() data = parser.parse_args() startdate = data['startdate'] enddate = data['enddate'] arg = session.query(Argentina).filter(and_( Argentina.date >= startdate, Argentina.date <= enddate )).all() session.close() return jsonify({ 'data': [result.serialized for result in arg], 'disclaimer': 'Todos los datos fueron recolectados de los reportes diarios del ministerio de salud de Argentina https://www.argentina.gob.ar/coronavirus/informe-diario' })
def newdata(dic): session = Session() ndata = Argentina(date=dic['date'], cases=dic['casos'], deaths=dic['muertes'], recovered=dic['recuperados'], terapy=dic['terapia'], testsNegative=dic['testsNegatives'], tests=dic['tests'], discardedNegatives=dic['negativosDescarte'], dailyCases=dic['casosDiarios'], dailyTestNegative=dic['testNegativosDiarios'], imported=dic['casosImportados'], contactCase=dic['contactoEstrecho'], communitary_Transmission=dic['trasmisionComunitaria']) session.add(ndata) session.commit() session.flush() session.close()
def month_re_cal(): """每天重复计算一个月内的数据""" db = Session() var_obj = db.execute('select code, exchange from varieties ') var_vals = var_obj.fetchall() exchange_map = dict(var_vals) db.close() now = datetime.now() last_month = when.past(months=1) for i in range((now - last_month).days + 1): date = str(last_month + timedelta(days=i))[:10] # ctp日数据 for varieties in DAY_VARIEYIES_DICT.keys(): exchange = exchange_map.get(varieties.lower()) if not exchange: exchange = exchange_map.get(varieties.upper()) cal_day_info(varieties, date, exchange) # 总资产 update_output(date)
def __init__(self, router): self.router = router self.request = router.request token = self.router.getCookie('token') if (token != None): try: session = Session.get((Session.token == token) & (Session.status == 1)) self.Authenticated = True self.SessionObject = session self.Token = session.token except: self.Authenticated = False self.SessionObject = None self.Token = 'NONE' pass
def Login(self): self.mimetype = 'application/json' # form = self.getQueryString() username = self.Req('username') password = self.Req('password') session = None # if(form.has_key('username') and form.has_key('password')): if username != None and password != None: # username = form['username'] # passowrd = form['password'] session = Session().Login(username, password) if (session != None): self.setCookie('token', session.token) self.output = '{status:1}' else: self.output = '{status:0}'
def update_output(date): """计算总产量""" db = Session() obj = PreprocessDayDataArtificial # for varieties in DAY_VARIEYIES_DICT.keys(): for varieties in ['cu', 'al', 'pb', 'zn']: symbol = get_symbol(varieties, key='total_output') init_vals = init_output_import(db, varieties, date) res = cal_total_output(varieties, date, **init_vals) if res: logging.debug('保存(总产量), 品类: %s, 时间: %s, 值: %s ' % (varieties, date, res)) save_symbol_data(db, res, date, symbol=symbol, obj=obj) db.commit() db.close()
print(body) info = body.decode('utf8').split(",") print("info", info) exchange = info[1] day_min = info[2] contract = info[0] date = info[3].split(" ")[0] # if exchange not in ALLOW_EXCHANGE: # return replace_info = re.findall(r'(\d+)', contract) varieties = contract.replace(replace_info[0], "") if varieties.lower() not in ALLOW_VARIETIES: return db = Session() cal_contract_vals(db, varieties, contract, date, exchange) db.close() if __name__ == '__main__': # varieties, contract_n, date, exchange # for i in range(7): # print('================%s'%i) db = Session() cal_contract_vals(db, "ni", 'ni1801', '2017-08-28', 'SHFE') # cal_contract_vals("cu", '6', '2017-08-08', 'SHFE') # cal_min(None, None, None, 'al1712,SHFE,Day,2017-08-10 00:00:00,16305,16595,16100,16425,37694,3087957300,57264,0,16190,19883,17811') # b'IH1709,CFFEX,Day,2017-08-28 00:00:00,2728,2775.2,2723.4,2740.4,10330,8522320680,18208,0,2709.8,5226,5104' # info ['IH1709', 'CFFEX', 'Day', '2017-08-28 00:00:00', '2728', '2775.2', '2723.4', '2740.4', '10330', '8522320680', '18208', '0', '2709.8', '5226', '5104'] # b'zn8888,SHFE,Day,2017-08-28 00:00:00,26520,26520,26520,25735,593842,76060520650,536406,0,0,0,0' # info ['zn8888', 'SHFE', 'Day', '2017-08-28 00:00:00', '26520', '26520', '26520', '25735', '593842', '76060520650', '536406', '0', '0', '0', '0']
def ultimodato(): session = Session() udato = session.query(Argentina).order_by(Argentina.date.desc()).first() session.close() return udato
def updatedata(dic, id): session = Session() session.query(Argentina).filter(Argentina.date == id).update(dic) session.commit() session.flush() session.close()
def deleteCase(id): session = Session() session.query(Argentina).filter(Argentina.date == id).delete() session.commit() session.flush() session.close()
def edit(id): session = Session() case = session.query(Argentina).filter(Argentina.date == id).first() session.close() return case
def lista(): session = Session() cases = session.query(Argentina).all() session.close() return cases
def update_or_create_symbol(symbol, vals): from models.models import Symbol, Session """更新或删除symbol表""" db = Session() now = str(datetime.now())[:19] symbol_objs = db.query(Symbol).filter(Symbol.symbol == symbol).all() if symbol_objs: obj = symbol_objs[0] for key in vals: obj.updated_at = now setattr(obj, key, vals[key]) if len(symbol_objs) > 1: for index in range(1, len(symbol_objs)): db.delete(symbol_objs[index]) else: new_obj = Symbol(**vals) new_obj.updated_at = now db.add(new_obj) db.commit() db.close()
def postgres_demo(): """ Example use of setting and retrieving a postgres record. """ drop_tables() create_tables() # Create a database session s = Session() print('*' * 50) print('Creating departments ...') departments = (('Produce', 'Healthy stuff!'), ('Bakery', 'Breads and goodies'), ('Deli', 'Meats, cheeses, etc')) for department in departments: d = Departments(name=department[0], description=department[1]) s.add(d) s.commit() print('Added: {}'.format(department[0])) print('*' * 50) print('Creating products ...') products = ((1, 'Apple', 1.99, 'Delicious Apple'), (1, 'Banana', 3.49, 'Bunch of Bananas'), (2, 'Bread', 3.99, 'Loaf of whole wheat'), (3, 'Cheddar', 2.79, 'Sliced cheddar')) for product in products: p = Products(department_id=product[0], name=product[1], price=product[2], description=product[3]) s.add(p) s.commit() print('Added: {}'.format(product[1])) print('*' * 50) res = s.query(Products).join(Departments).all() print('Result of outer join:') for r in res: print('{} | {} | {}'.format(r.name, r.department.name, r.price))