Skip to content

Commit

Permalink
implement get_emails_as_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
mourginakis committed Nov 6, 2023
1 parent f5ddf0a commit bc4bdf3
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions node_monitor/node_provider_db2.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,17 @@ def _execute1(self, sql: str, params: tuple) -> List[tuple]:

def _validate_schema(self) -> bool:
"""Validate the database schema."""
# This function is still incomplete
# Get the column names, data types
# TODO: This function is still incomplete
# TODO: could we use pg_dump or generate_ddl to test this instead?
# Get the column names, data types
table_name = "subscribers"
query = f"""
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = '{table_name}'
"""
result = self._execute(query, ())
# Do something here
raise NotImplementedError
return None


Expand All @@ -137,7 +137,14 @@ def get_subscribers_as_dict(self) -> Dict[Principal, Dict[str, Any]]:

def get_emails_as_dict(self) -> Dict[Principal, List[str]]:
"""Returns the table of all emails as a dictionary"""
raise NotImplementedError
result = self._execute("SELECT * FROM email_lookup", ())
resultd = {}
# TODO: Can this be done with a higher level functions?
for d in result:
if d['node_provider_id'] not in resultd:
resultd[d['node_provider_id']] = []
resultd[d['node_provider_id']].append(d['email_address'])
return resultd


def get_slack_channels_as_dict(self) -> Dict[Principal, List[str]]:
Expand All @@ -161,9 +168,9 @@ def close(self) -> None:
from pprint import pprint
db = NodeProviderDB(c.DB_HOST, c.DB_NAME, c.DB_PORT, c.DB_USERNAME, c.DB_PASSWORD)
pprint("---------------------------------")
db._validate_schema()
result = db._execute("SELECT * FROM subscribers", ())
pprint(result)
# db._validate_schema()
# result = db._execute("SELECT * FROM subscribers", ())
# pprint(result)
pprint("---------------------------------")
result = db.get_subscribers_as_dict()
result = db.get_emails_as_dict()
pprint(result)

0 comments on commit bc4bdf3

Please sign in to comment.