-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathio.py
More file actions
31 lines (26 loc) · 1.18 KB
/
io.py
File metadata and controls
31 lines (26 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from sqlalchemy import create_engine
from egoio.tools.db import connection
import getpass
import sys
def oedb_session(section='oep'):
"""Get SQLAlchemy session object with valid connection to OEDB"""
# get session object by oemof.db tools (requires ~/.egoio/config.ini)
try:
conn = connection(section=section)
except:
print('Please provide connection parameters to database:\n' +
'Hit [Enter] to take defaults')
host = input('host (default 141.44.24.88): ') or 'oe.iws.cs.ovgu.de'
port = input('port (default 5432): ') or '5432'
database = input("database name (default 'oep'): ") or 'oep'
user = input('user (default postgres): ')
# password = input('password: ')
password = getpass.getpass(prompt='password: ',
stream=sys.stderr)
conn = create_engine(
'postgresql://' + '%s:%s@%s:%s/%s' % (user,
password,
host,
port,
database)).connect()
return conn