From 648af3a5c7a2a48975cadd7617c4c2bc71ebb749 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Sat, 31 May 2025 16:44:19 +0530 Subject: [PATCH] Updated project report API in three of the scripts --- mailling/localhost/{local.env => config.env} | 0 .../localhost/localhost_project_report.py | 32 +++++------------- mailling/prod/{production.env => config.env} | 0 mailling/prod/prod_project_report.py | 32 +++++------------- mailling/stage/{stage.env => config.env} | 0 mailling/stage/stage_project_report.py | 33 +++++-------------- 6 files changed, 27 insertions(+), 70 deletions(-) rename mailling/localhost/{local.env => config.env} (100%) rename mailling/prod/{production.env => config.env} (100%) rename mailling/stage/{stage.env => config.env} (100%) diff --git a/mailling/localhost/local.env b/mailling/localhost/config.env similarity index 100% rename from mailling/localhost/local.env rename to mailling/localhost/config.env diff --git a/mailling/localhost/localhost_project_report.py b/mailling/localhost/localhost_project_report.py index b6cbe1a..934310c 100644 --- a/mailling/localhost/localhost_project_report.py +++ b/mailling/localhost/localhost_project_report.py @@ -1,28 +1,16 @@ -import sys import requests -from datetime import date, timedelta from dotenv import load_dotenv import os -load_dotenv(dotenv_path="local.env") - -project_ids_str = os.getenv("PROJECT_IDS") -project_ids = [pid.strip() for pid in project_ids_str.split(",")] if project_ids_str else [] - - -if len(sys.argv) > 1: - date = sys.argv[1] -else: - date = date.today() - timedelta(days=1) +load_dotenv(dotenv_path="config.env", override=True) base_url = os.getenv("BASE_URL") - def login(): payload = { "username": os.getenv("USERNAME"), "password": os.getenv("PASSWORD") } - + headers = { "Content-Type": "application/json" } @@ -33,24 +21,22 @@ def login(): jwt = data["token"] return jwt -def project_proccess(jwt,project_id,date): +def project_proccess(jwt): headers = { "Authorization": f"Bearer {jwt}", "Content-Type": "application/json" } - response = requests.get(f"{base_url}/report/project-statistics/{project_id}?date={date}", headers=headers) + response = requests.get(f"{base_url}/report/project-statistics", headers=headers) return response try: jwt = login() - for project_id in project_ids: - print(project_id) - response = project_proccess(jwt, project_id, date) # Call your function + response = project_proccess(jwt) # Call your function - if response.status_code == 200: - print("Email sent") - else: - print(f"Failed with response: {response}") + if response.status_code == 200: + print("Email sent") + else: + print(f"Failed with response: {response}") except Exception as e: print(f"An error occurred: {e}") diff --git a/mailling/prod/production.env b/mailling/prod/config.env similarity index 100% rename from mailling/prod/production.env rename to mailling/prod/config.env diff --git a/mailling/prod/prod_project_report.py b/mailling/prod/prod_project_report.py index d823423..934310c 100644 --- a/mailling/prod/prod_project_report.py +++ b/mailling/prod/prod_project_report.py @@ -1,28 +1,16 @@ -import sys import requests -from datetime import date, timedelta from dotenv import load_dotenv import os -load_dotenv(dotenv_path="production.env") - -project_ids_str = os.getenv("PROJECT_IDS") -project_ids = [pid.strip() for pid in project_ids_str.split(",")] if project_ids_str else [] - - -if len(sys.argv) > 1: - date = sys.argv[1] -else: - date = date.today() - timedelta(days=1) +load_dotenv(dotenv_path="config.env", override=True) base_url = os.getenv("BASE_URL") - def login(): payload = { "username": os.getenv("USERNAME"), "password": os.getenv("PASSWORD") } - + headers = { "Content-Type": "application/json" } @@ -33,24 +21,22 @@ def login(): jwt = data["token"] return jwt -def project_proccess(jwt,project_id,date): +def project_proccess(jwt): headers = { "Authorization": f"Bearer {jwt}", "Content-Type": "application/json" } - response = requests.get(f"{base_url}/report/project-statistics/{project_id}?date={date}", headers=headers) + response = requests.get(f"{base_url}/report/project-statistics", headers=headers) return response try: jwt = login() - for project_id in project_ids: - print(project_id) - response = project_proccess(jwt, project_id, date) # Call your function + response = project_proccess(jwt) # Call your function - if response.status_code == 200: - print("Email sent") - else: - print(f"Failed with response: {response}") + if response.status_code == 200: + print("Email sent") + else: + print(f"Failed with response: {response}") except Exception as e: print(f"An error occurred: {e}") diff --git a/mailling/stage/stage.env b/mailling/stage/config.env similarity index 100% rename from mailling/stage/stage.env rename to mailling/stage/config.env diff --git a/mailling/stage/stage_project_report.py b/mailling/stage/stage_project_report.py index 66bf593..934310c 100644 --- a/mailling/stage/stage_project_report.py +++ b/mailling/stage/stage_project_report.py @@ -1,29 +1,16 @@ -import sys import requests -from datetime import date, timedelta from dotenv import load_dotenv import os -import json -load_dotenv(dotenv_path="stage.env") - -project_ids_str = os.getenv("PROJECT_IDS") -project_ids = [pid.strip() for pid in project_ids_str.split(",")] if project_ids_str else [] - - -if len(sys.argv) > 1: - date = sys.argv[1] -else: - date = date.today() - timedelta(days=1) +load_dotenv(dotenv_path="config.env", override=True) base_url = os.getenv("BASE_URL") - def login(): payload = { "username": os.getenv("USERNAME"), "password": os.getenv("PASSWORD") } - + headers = { "Content-Type": "application/json" } @@ -34,24 +21,22 @@ def login(): jwt = data["token"] return jwt -def project_proccess(jwt,project_id,date): +def project_proccess(jwt): headers = { "Authorization": f"Bearer {jwt}", "Content-Type": "application/json" } - response = requests.get(f"{base_url}/report/project-statistics/{project_id}?date={date}", headers=headers) + response = requests.get(f"{base_url}/report/project-statistics", headers=headers) return response try: jwt = login() - for project_id in project_ids: - print(project_id) - response = project_proccess(jwt, project_id, date) # Call your function + response = project_proccess(jwt) # Call your function - if response.status_code == 200: - print("Email sent") - else: - print(f"Failed with response: {response}") + if response.status_code == 200: + print("Email sent") + else: + print(f"Failed with response: {response}") except Exception as e: print(f"An error occurred: {e}")