from sqlalchemy import Column, Integer, String, create_engine from sqlalchemy.ext.declarative import declarative_base import json from os.path import exists Base = declarative_base() class covidData(Base): __tablename__ = 'data' selection = Column(String(32), primary_key=True) total_cases = Column(Integer) new_cases = Column(Integer) total_deaths = Column(Integer) new_deaths = Column(Integer) total_recovered = Column(Integer) active_cases = Column(Integer) serious_critical = Column(Integer) total_cases_per_one_mil = Column(String(32)) path = 'config/config.json' if(exists(path)): try: with open(path) as config_file: config_data = json.load(config_file) except Exception as e: print(f'There was some issue opening and loading the config.\n{e}') # exit(1) else: print('Didn\'t find the config file.') # exit(1) try: with open(config_data['postgres_pass']) as pgdb_pass: engine = create_engine( f"postgresql+psycopg2://{config_data['postgres_user']}:{pgdb_pass.readline().strip()}@{config_data['postgres_host']}:{config_data['postgres_port']}/{config_data['postgres_db']}") Base.metadata.create_all(engine) except Exception as e: print( f'There was an issue opening the config file for the postgres password.\n{e}')