def db_update(all_sts_ls): """Update databse, as input take double nested list of stats""" rtn_change_id = [] logger.debug(str(len(all_sts_ls))) for country in all_sts_ls: ctry = search(country[1]) if ctry == None: logger.info("NEW COUNTRY:" + country[1]) ctry = Country(c_pos=country[0], c_name = country[1], c_name_pl=country[1], c_ill_sum = country[2], c_inf_tdy = country[3], c_dead = country[4], c_deaths_tdy = country[5], c_recover = country[6], c_curr_cases = country[7], c_crit_cases = country[8], c_case_1m = country[9], c_dead_1m = country[10]) db.session.add(ctry) else: logger.debug("%d, %s" %(ctry.c_id, ctry.c_name)) chng = ctry.update(country[0], country[2], country[3], country[4], country[5], country[6], country[8], country[9], country[10], country[11]) if chng: rtn_change_id.append(ctry.c_id) db.session.commit() return rtn_change_id