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): 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 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 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()
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 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 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 lista(): session = Session() cases = session.query(Argentina).all() session.close() return cases
def edit(id): session = Session() case = session.query(Argentina).filter(Argentina.date == id).first() session.close() return case
def deleteCase(id): session = Session() session.query(Argentina).filter(Argentina.date == id).delete() session.commit() session.flush() session.close()