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/MongoService /Services/MongoService
|
||||||
ADD /Services/PostgresService /Services/PostgresService
|
ADD /Services/PostgresService /Services/PostgresService
|
||||||
ADD /Services/EmailService /Services/EmailService
|
ADD /Services/EmailService /Services/EmailService
|
||||||
|
ADD /BankServices/ServiceDepends/template_accounts.html /templates/template_accounts.html
|
||||||
|
|
||||||
# Set Python path to include app directory
|
# Set Python path to include app directory
|
||||||
ENV PYTHONPATH=/ PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
|
ENV PYTHONPATH=/ PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,8 @@ from Services.EmailService.provider import send_email
|
||||||
|
|
||||||
|
|
||||||
mongo_prefix = "CollectedData"
|
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"
|
send_to = "karatay@mehmetkaratay.com.tr"
|
||||||
|
delimiter = "|"
|
||||||
|
|
||||||
|
|
||||||
def check_any_written_stage_in_mongo_database(mongo_provider) -> list:
|
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
|
headers: list, rows: list, balance_error: bool, bank_balance: float
|
||||||
):
|
):
|
||||||
template_dir = os.path.join(os.path.dirname(__file__), "templates")
|
template_dir = os.path.join(os.path.dirname(__file__), "templates")
|
||||||
env = Environment(
|
# Load templates from the directory
|
||||||
loader=FileSystemLoader(template_dir)
|
env = Environment(loader=FileSystemLoader(template_dir))
|
||||||
) # Load templates from the directory
|
# Load the specific template file
|
||||||
template = env.get_template(
|
template = env.get_template("template_accounts.html")
|
||||||
"template_accounts.html"
|
|
||||||
) # Load the specific template file
|
|
||||||
# Render template with variables
|
# Render template with variables
|
||||||
return template.render(
|
return template.render(
|
||||||
headers=headers,
|
headers=headers,
|
||||||
|
|
@ -43,8 +36,7 @@ def render_email_template(
|
||||||
|
|
||||||
|
|
||||||
def send_email_to_given_address(to: str, html_template: str) -> bool:
|
def send_email_to_given_address(to: str, html_template: str) -> bool:
|
||||||
today = arrow.now()
|
subject = f"{str(arrow.now().date())} Gunes Apt. Cari DurumKaydedilen Raporu"
|
||||||
subject = f"{str(today.date())} Gunes Apt. Cari Durum Bilgilendirme Raporu"
|
|
||||||
try:
|
try:
|
||||||
send_email(subject=subject, receivers=[to], html=html_template)
|
send_email(subject=subject, receivers=[to], html=html_template)
|
||||||
print(f"Email is sent to : {send_to}. BB")
|
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:
|
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:
|
if not parsed_list:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
list_of_rows = list()
|
|
||||||
for parsed in parsed_list:
|
for parsed in parsed_list:
|
||||||
bank_date = arrow.get(str(parsed.get("bank_date")))
|
bank_date = arrow.get(str(parsed.get("bank_date")))
|
||||||
process_comment = parsed.get("process_comment")
|
process_comment = parsed.get("process_comment")
|
||||||
currency_value = f"{parsed.get('currency_value'):.4f}"
|
currency_value = f"{parsed.get('currency_value'):.4f}"
|
||||||
list_of_rows.append(
|
list_of_rows.append([bank_date, process_comment, currency_value])
|
||||||
[bank_date, process_comment, currency_value]
|
|
||||||
)
|
|
||||||
|
|
||||||
html_template = render_email_template(
|
html_template = render_email_template(
|
||||||
headers=["Ulaştığı Tarih", "Banka Transaksiyonu Ek Bilgi", "Aktarım Değeri"],
|
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)
|
results = check_any_written_stage_in_mongo_database(mongo_provider=provider)
|
||||||
for result in results:
|
for result in results:
|
||||||
send_email_and_update_mongo_database(
|
send_email_and_update_mongo_database(
|
||||||
mongo_provider=provider,
|
mongo_provider=provider, email_data=result,
|
||||||
email_data=result,
|
|
||||||
)
|
)
|
||||||
time.sleep(5)
|
time.sleep(60)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue