-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into snyk-upgrade-4b667552b73f225de251706f4b390969
- Loading branch information
Showing
19 changed files
with
1,742 additions
and
1,484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
required: true | ||
|
||
env: | ||
POETRY_VERSION: "1.7.1" | ||
POETRY_VERSION: "2.0.0" | ||
|
||
jobs: | ||
deploy-staging: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ on: | |
required: true | ||
|
||
env: | ||
POETRY_VERSION: "1.7.1" | ||
POETRY_VERSION: "2.0.0" | ||
|
||
jobs: | ||
publish: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.10.0 | ||
3.13.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,11 @@ | |
|
||
sys.path.insert(1, "/".join(os.path.realpath(__file__).split("/")[0:-2])) | ||
|
||
from harvester import SMTP_CONFIG | ||
import smtplib | ||
from email.mime.text import MIMEText | ||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
|
||
from harvester import HarvesterDBInterface, db_interface | ||
from harvester import SMTP_CONFIG, HarvesterDBInterface, db_interface | ||
from harvester.exceptions import ( | ||
CompareException, | ||
DCATUSToCKANException, | ||
|
@@ -73,7 +72,7 @@ class HarvestSource: | |
"schema_type", | ||
"source_type", | ||
"id", # db guuid | ||
"notification_emails" | ||
"notification_emails", | ||
], | ||
repr=False, | ||
) | ||
|
@@ -162,7 +161,6 @@ def internal_records_to_id_hash(self, records: list[dict]) -> None: | |
) | ||
|
||
def get_record_identifier(self, record: dict) -> str: | ||
|
||
record_id = "identifier" if self.schema_type.startswith("dcatus") else "url" | ||
|
||
if record_id not in record: | ||
|
@@ -181,7 +179,6 @@ def external_records_to_id_hash(self, records: list[dict]) -> None: | |
logger.info("converting harvest records to id: hash") | ||
for record in records: | ||
try: | ||
|
||
identifier = self.get_record_identifier(record) | ||
|
||
if self.source_type == "document": | ||
|
@@ -196,7 +193,7 @@ def external_records_to_id_hash(self, records: list[dict]) -> None: | |
except Exception as e: | ||
# TODO: do something with 'e' | ||
raise ExtractExternalException( | ||
f"{self.title} {self.url} failed to convert to id:hash", | ||
f"{self.name} {self.url} failed to convert to id:hash", | ||
self.job_id, | ||
) | ||
|
||
|
@@ -248,7 +245,7 @@ def compare(self) -> None: | |
except Exception as e: | ||
# TODO: do something with 'e' | ||
raise CompareException( | ||
f"{self.title} {self.url} failed to run compare. exiting.", | ||
f"{self.name} {self.url} failed to run compare. exiting.", | ||
self.job_id, | ||
) | ||
|
||
|
@@ -402,45 +399,45 @@ def report(self) -> None: | |
self.send_notification_emails(actual_results_action) | ||
|
||
def send_notification_emails(self, results: dict) -> None: | ||
try: | ||
job_url = f'{SMTP_CONFIG["base_url"]}/harvest_job/{self.job_id}' | ||
|
||
subject = "Harvest Job Completed" | ||
body = ( | ||
f"The harvest job ({self.job_id}) has been successfully completed.\n" | ||
f"You can view the details here: {job_url}\n\n" | ||
"Summary of the job:\n" | ||
f"- Records Added: {results['create']}\n" | ||
f"- Records Updated: {results['update']}\n" | ||
f"- Records Deleted: {results['delete']}\n" | ||
f"- Records Ignored: {results[None]}\n\n" | ||
"====\n" | ||
"You received this email because you subscribed to harvester updates.\n" | ||
"Please do not reply to this email, as it is not monitored." | ||
) | ||
support_recipient = SMTP_CONFIG.get("recipient") | ||
user_recipients = self.notification_emails | ||
all_recipients = [support_recipient] + user_recipients | ||
job_url = f'{SMTP_CONFIG["base_url"]}/harvest_job/{self.job_id}' | ||
|
||
subject = "Harvest Job Completed" | ||
body = ( | ||
f"The harvest job ({self.job_id}) has been successfully completed.\n" | ||
f"You can view the details here: {job_url}\n\n" | ||
"Summary of the job:\n" | ||
f"- Records Added: {results['create']}\n" | ||
f"- Records Updated: {results['update']}\n" | ||
f"- Records Deleted: {results['delete']}\n" | ||
f"- Records Ignored: {results[None]}\n\n" | ||
"====\n" | ||
"You received this email because you subscribed to harvester updates.\n" | ||
"Please do not reply to this email, as it is not monitored." | ||
) | ||
support_recipient = SMTP_CONFIG.get("recipient") | ||
user_recipients = self.notification_emails | ||
all_recipients = [support_recipient] + user_recipients | ||
|
||
msg = MIMEMultipart() | ||
msg["From"] = SMTP_CONFIG["default_sender"] | ||
msg["Reply-To"] = "[email protected]" | ||
msg["Subject"] = subject | ||
msg.attach(MIMEText(body, "plain")) | ||
|
||
try: | ||
with smtplib.SMTP(SMTP_CONFIG["server"], SMTP_CONFIG["port"]) as server: | ||
if SMTP_CONFIG["use_tls"]: | ||
server.starttls() | ||
server.login(SMTP_CONFIG["username"], SMTP_CONFIG["password"]) | ||
|
||
for recipient in all_recipients: | ||
msg = MIMEMultipart() | ||
msg["From"] = SMTP_CONFIG["default_sender"] | ||
msg["To"] = recipient | ||
msg["Reply-To"] = "[email protected]" | ||
msg["Subject"] = subject | ||
msg.attach(MIMEText(body, "plain")) | ||
|
||
server.sendmail(SMTP_CONFIG["default_sender"], [recipient], | ||
msg.as_string()) | ||
server.sendmail( | ||
SMTP_CONFIG["default_sender"], [recipient], msg.as_string() | ||
) | ||
logger.info(f"Notification email sent to: {recipient}") | ||
|
||
except Exception as e: | ||
logger.error(f"Error preparing or sending notification emails: {e}") | ||
logger.error(f"Failed to send notification email: {e}") | ||
|
||
|
||
@dataclass | ||
|
@@ -565,7 +562,6 @@ def status(self, value) -> None: | |
self._status = value | ||
|
||
def transform(self) -> None: | ||
|
||
data = { | ||
"file": self.metadata["content"], | ||
"reader": self.reader_map[self.harvest_source.schema_type], | ||
|
@@ -584,7 +580,11 @@ def transform(self) -> None: | |
self.harvest_source.internal_records_lookup_table[self.identifier], | ||
) | ||
|
||
record_id = self.harvest_source.internal_records_lookup_table[self.identifier] | ||
if 200 <= resp.status_code < 300: | ||
logger.info( | ||
f"successfully transformed record: {self.identifier} db id: {record_id}" | ||
) | ||
self.transformed_data = json.loads(data["writerOutput"]) | ||
|
||
def validate(self) -> None: | ||
|
Oops, something went wrong.
55405c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.