Create different DBs for each table
This commit is contained in:
parent
cbc1c08350
commit
6ef88e9b23
|
@ -1,3 +1,4 @@
|
|||
DB_NAME = "igdb"
|
||||
DB_USER = "igdb"
|
||||
DB_PW = "agentorange"
|
||||
ADMIN_PW = "fuckmonsanto"
|
||||
|
|
|
@ -76,10 +76,14 @@ class Annual_Change(db.Model):
|
|||
class User(db.Model):
|
||||
uid = db.Column(db.Integer, primary_key=True)
|
||||
registration_date = db.Column(db.DateTime, nullable=False)
|
||||
username = db.Column(db.String(20), nullable=False, unique=True)
|
||||
password = db.Column(db.String(60))
|
||||
|
||||
def __init__(self, uid):
|
||||
def __init__(self, uid, username, password):
|
||||
self.uid = uid
|
||||
self.registration_date = datetime.today()
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
||||
|
||||
def create_tables():
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from iso3166 import countries as co
|
||||
from pandas import DataFrame, concat, read_csv
|
||||
from csv import QUOTE_NONNUMERIC
|
||||
from constants import ADMIN_PW
|
||||
|
||||
|
||||
def country_conversion(political_unit) -> str:
|
||||
|
@ -12,6 +13,7 @@ def select_columns() -> DataFrame:
|
|||
min_year = 2010
|
||||
fields = [
|
||||
"POLITICAL_UNIT",
|
||||
"NAME",
|
||||
"WGMS_ID",
|
||||
"YEAR",
|
||||
"AREA_SURVEY_YEAR",
|
||||
|
@ -31,10 +33,29 @@ def select_columns() -> DataFrame:
|
|||
return data
|
||||
|
||||
|
||||
def create_databases(df):
|
||||
users = {"UID": [7843], "USERNAME": ["admin"], "PASSWORD": [ADMIN_PW]}
|
||||
files = {
|
||||
"glacier": "../data/glacier.csv",
|
||||
"annual_data": "../data/annual_data.csv",
|
||||
"annual_change": "../data/annual_change.csv",
|
||||
"users": "../data/users.csv",
|
||||
}
|
||||
dataframes = {
|
||||
"glacier": df[["POLITICAL_UNIT", "NAME", "WGMS_ID"]].drop_duplicates(),
|
||||
"annual_data": df[["WGMS_ID", "YEAR", "AREA_SURVEY_YEAR"]],
|
||||
"annual_change": df[
|
||||
["WGMS_ID", "YEAR", "AREA_CHANGE", "THICKNESS_CHG", "VOLUME_CHANGE"]
|
||||
],
|
||||
"users": DataFrame(users),
|
||||
}
|
||||
for key, val in dataframes.items():
|
||||
val.to_csv(files[key], index=False, quoting=QUOTE_NONNUMERIC)
|
||||
|
||||
|
||||
def main():
|
||||
df = select_columns()
|
||||
database = "../data/igdb.csv"
|
||||
df.to_csv(database, index=False, quoting=QUOTE_NONNUMERIC)
|
||||
create_databases(df)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
from db_setup import create_connection
|
||||
from pandas import DataFrame, read_csv, to_sql
|
||||
|
||||
|
||||
def create_dataframe() -> DataFrame:
|
||||
csv_file = "../data/igdb.csv"
|
||||
df = read_csv(csv_file)
|
||||
return df
|
||||
|
||||
|
||||
def insert_data(df, conn):
|
||||
df.to_sql("glacier", con=conn, if_exists="replace", index=False)
|
||||
|
||||
|
||||
def main():
|
||||
conn = create_connection()
|
||||
df = create_dataframe()
|
||||
insert_data(df, conn)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,2 @@
|
|||
"UID","USERNAME","PASSWORD"
|
||||
7843,"admin","fuckmonsanto"
|
|
|
@ -39,6 +39,8 @@ datos relevantes para estudios acerca del cambio climático, y acotando éstos a
|
|||
4. *RD4*: Datos del administrador
|
||||
- ID - /Entero de 4 dígitos/
|
||||
- Fecha de alta - /Fecha en formato dd-mm-yyyy/
|
||||
- Nombre de usuario - /Cadena de 20 caracteres máximo/
|
||||
- Contraseña - /Cadena de 60 caracteres máximo/
|
||||
|
||||
*** Funcionales
|
||||
|
||||
|
|
Loading…
Reference in New Issue