updated Sender Service
This commit is contained in:
parent
77893e1d95
commit
92942af6f3
|
|
@ -23,6 +23,7 @@ ADD /Commons /Commons
|
|||
ADD /Services/MongoService /Services/MongoService
|
||||
ADD /Services/PostgresService /Services/PostgresService
|
||||
ADD /Services/EmailService /Services/EmailService
|
||||
ADD /BankServices/ServiceDepends/template_accounts.html /templates/template_accounts.html
|
||||
|
||||
# Set Python path to include app directory
|
||||
ENV PYTHONPATH=/ PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
|
||||
|
|
|
|||
|
|
@ -9,13 +9,8 @@ from Services.EmailService.provider import send_email
|
|||
|
||||
|
||||
mongo_prefix = "CollectedData"
|
||||
delimiter = "|"
|
||||
|
||||
|
||||
# todo Check if postgres is_email_send === False then send email
|
||||
# todo Trigger @mongo email_send = False then send email
|
||||
|
||||
send_to = "karatay@mehmetkaratay.com.tr"
|
||||
delimiter = "|"
|
||||
|
||||
|
||||
def check_any_written_stage_in_mongo_database(mongo_provider) -> list:
|
||||
|
|
@ -26,12 +21,10 @@ def render_email_template(
|
|||
headers: list, rows: list, balance_error: bool, bank_balance: float
|
||||
):
|
||||
template_dir = os.path.join(os.path.dirname(__file__), "templates")
|
||||
env = Environment(
|
||||
loader=FileSystemLoader(template_dir)
|
||||
) # Load templates from the directory
|
||||
template = env.get_template(
|
||||
"template_accounts.html"
|
||||
) # Load the specific template file
|
||||
# Load templates from the directory
|
||||
env = Environment(loader=FileSystemLoader(template_dir))
|
||||
# Load the specific template file
|
||||
template = env.get_template("template_accounts.html")
|
||||
# Render template with variables
|
||||
return template.render(
|
||||
headers=headers,
|
||||
|
|
@ -43,8 +36,7 @@ def render_email_template(
|
|||
|
||||
|
||||
def send_email_to_given_address(to: str, html_template: str) -> bool:
|
||||
today = arrow.now()
|
||||
subject = f"{str(today.date())} Gunes Apt. Cari Durum Bilgilendirme Raporu"
|
||||
subject = f"{str(arrow.now().date())} Gunes Apt. Cari DurumKaydedilen Raporu"
|
||||
try:
|
||||
send_email(subject=subject, receivers=[to], html=html_template)
|
||||
print(f"Email is sent to : {send_to}. BB")
|
||||
|
|
@ -56,18 +48,15 @@ def send_email_to_given_address(to: str, html_template: str) -> bool:
|
|||
|
||||
|
||||
def send_email_and_update_mongo_database(mongo_provider, email_data) -> bool:
|
||||
parsed_list = email_data.get("parsed")
|
||||
parsed_list, list_of_rows = email_data.get("parsed"), list()
|
||||
if not parsed_list:
|
||||
return False
|
||||
|
||||
list_of_rows = list()
|
||||
for parsed in parsed_list:
|
||||
bank_date = arrow.get(str(parsed.get("bank_date")))
|
||||
process_comment = parsed.get("process_comment")
|
||||
currency_value = f"{parsed.get('currency_value'):.4f}"
|
||||
list_of_rows.append(
|
||||
[bank_date, process_comment, currency_value]
|
||||
)
|
||||
list_of_rows.append([bank_date, process_comment, currency_value])
|
||||
|
||||
html_template = render_email_template(
|
||||
headers=["Ulaştığı Tarih", "Banka Transaksiyonu Ek Bilgi", "Aktarım Değeri"],
|
||||
|
|
@ -97,7 +86,6 @@ if __name__ == "__main__":
|
|||
results = check_any_written_stage_in_mongo_database(mongo_provider=provider)
|
||||
for result in results:
|
||||
send_email_and_update_mongo_database(
|
||||
mongo_provider=provider,
|
||||
email_data=result,
|
||||
mongo_provider=provider, email_data=result,
|
||||
)
|
||||
time.sleep(5)
|
||||
time.sleep(60)
|
||||
|
|
|
|||
Loading…
Reference in New Issue