43 lines
1001 B
Python
43 lines
1001 B
Python
|
from hub.imports.geometry_factory import GeometryFactory
|
||
|
from hub.helpers.dictionaries import Dictionaries
|
||
|
import os
|
||
|
import psycopg2
|
||
|
|
||
|
password = os.getenv('PGPASSWORD')
|
||
|
|
||
|
input_file = "cmm_points_function_vintage_surface.csv"
|
||
|
|
||
|
city = GeometryFactory(
|
||
|
file_type="csv",
|
||
|
path=input_file,
|
||
|
year_of_construction_field="anne_cnstr",
|
||
|
function_field="code_util",
|
||
|
function_to_hub=Dictionaries().montreal_function_to_hub_function,
|
||
|
total_floor_area_field="supfi_etag"
|
||
|
).city
|
||
|
|
||
|
|
||
|
conn_params = {
|
||
|
'host': 'localhost',
|
||
|
'port': '5432',
|
||
|
'database': 'energydemanddb',
|
||
|
'user': 'postgres',
|
||
|
'password': password
|
||
|
}
|
||
|
|
||
|
try:
|
||
|
conn = psycopg2.connect(**conn_params)
|
||
|
print("Connection established successfully.")
|
||
|
except psycopg2.Error as e:
|
||
|
print(f"An error occurred while connecting to the database: {e}")
|
||
|
|
||
|
cursor = conn.cursor()
|
||
|
cursor.execute("SELECT * FROM energy_data LIMIT 5;")
|
||
|
results = cursor.fetchall()
|
||
|
|
||
|
for row in results:
|
||
|
print(row)
|
||
|
|
||
|
cursor.close()
|
||
|
conn.close()
|