def run_data_update(): global corona_joined, county_cases, location_cube, country_location_cube, sex, age try: backend = Backend() backend.start_connection() corona_joined = backend.get_cube("corona_joined") county_cases = backend.get_cube("county_cases") location_cube = backend.get_cube(coronavirus_location.table_name) country_location_cube = country_location() sex = backend.get_cube("sex") age = backend.get_cube("age") except Exception as e: logger.error("Error fetching database: %s", e) schedule = datetime.datetime.now() while True: if datetime.datetime.now() >= schedule: logger.info("Updating database.") try: backend = Backend() backend.start_connection() backend.update_coronavirus_data() midnight_today = datetime.datetime.combine( datetime.date.today(), datetime.datetime.min.time()) schedule = midnight_today + datetime.timedelta( days=1, hours=UPDATE_TIME) corona_joined = backend.get_cube("corona_joined") county_cases = backend.get_cube("county_cases") location_cube = backend.get_cube( coronavirus_location.table_name) country_location_cube = country_location() sex = backend.get_cube("sex") age = backend.get_cube("age") logger.info("Update succeed. Scheduled for %s UTC", schedule) except Exception as e: logger.error("Error updating database: %s", e) time.sleep(3600)
from Backend import Backend import mysql_setup.coronavirus as coronavirus import mysql_setup.coronavirus_location as coronavirus_location import datetime if __name__ == "__main__": backend = Backend() backend.start_connection() # backend.update_coronavirus_data() # cube = backend.get_cube(coronavirus.table_name,1) # cube.show() # location_cube = backend.get_cube(coronavirus_location.table_name,1) # location_cube.show() # cube.push("date") # joined = cube.join(location_cube) # joined.show() # joined.show() # corona_joined = backend.get_cube("corona_joined") # corona_joined.show() # cube = cube.push("date") # cube.show() # cube = cube.push("country_region") # cube.show() # cube = cube.pull("date") # cube.show() # predicate_func = lambda x:x=="Washington" # cube = cube.restriction("province_state", predicate_func) # cube.show() # cube = cube.destroy("date") # cube.show() # cube = cube.destroy("province_state")