Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Pre-commit issues
Browse files Browse the repository at this point in the history
  • Loading branch information
edujosemena committed Jul 21, 2023
1 parent eb48247 commit aceaaed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
15 changes: 7 additions & 8 deletions src/pe_reports/data/db_query.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""Query the PE PostgreSQL database."""

# Standard Python Libraries
import json
import logging
import re
import sys

# Third-Party Libraries
import requests
import json
import numpy as np
import pandas as pd
import psycopg2
from psycopg2 import OperationalError
from psycopg2.extensions import AsIs
import requests

from .config import config

Expand All @@ -22,8 +22,9 @@
LOGGER = logging.getLogger(__name__)

CONN_PARAMS_DIC = config()
PE_API_KEY = config(section='peapi').get('api_key')
PE_API_URL = config(section='peapi').get('api_url')
PE_API_KEY = config(section="peapi").get("api_key")
PE_API_URL = config(section="peapi").get("api_url")


def sanitize_string(string):
"""Remove special characters from string."""
Expand All @@ -35,9 +36,6 @@ def sanitize_uid(string):
return re.sub(r"[^a-zA-Z0-9\-\s]", "", string)





def show_psycopg2_exception(err):
"""Handle errors for PostgreSQL issues."""
err_type, err_obj, traceback = sys.exc_info()
Expand All @@ -62,11 +60,12 @@ def close(conn):
conn.close()
return


def get_orgs():
"""Query organizations table."""
headers = {
"Content-Type": "application/json",
"access_token": f'{PE_API_KEY}',
"access_token": f"{PE_API_KEY}",
}
try:
response = requests.post(PE_API_URL, headers=headers).json()
Expand Down
11 changes: 5 additions & 6 deletions src/pe_source/data/pe_db/db_query_source.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
"""Query the PE PostgreSQL database."""

# Standard Python Libraries
from datetime import datetime
import json
import re
import requests
import sys
import json
import time

# Third-Party Libraries
import pandas as pd
import psycopg2
from psycopg2 import OperationalError
import psycopg2.extras as extras
import requests

# cisagov Libraries
from pe_reports import app
Expand Down Expand Up @@ -64,7 +63,7 @@ def get_orgs():
"access_token": f"{PE_API_KEY}",
}
try:
response = requests.post(PE_API_URL + "get_orgs/", headers=headers).json()
response = requests.post(PE_API_URL + "get_orgs/", headers=headers).json()
return response
except requests.exceptions.HTTPError as errh:
print(errh)
Expand Down Expand Up @@ -93,7 +92,7 @@ def get_ips(org_uid):


def get_data_source_uid(source):
"""Query organizations table."""
"""Query data_source table and update the last viewed time."""
urlOrgs = PE_API_URL
headers = {
"Content-Type": "application/json",
Expand All @@ -105,7 +104,7 @@ def get_data_source_uid(source):
).json()
# Change last viewed
uid = response[0]["data_source_uid"]
r = requests.put(urlOrgs + "update_last_viewed/" + uid, headers=headers)
requests.put(urlOrgs + "update_last_viewed/" + uid, headers=headers)
LOGGER.info("Updated last viewed for %s", source)
return response
except requests.exceptions.HTTPError as errh:
Expand Down

0 comments on commit aceaaed

Please sign in to comment.