43 lines
1010 B
Python
43 lines
1010 B
Python
import requests
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
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"
|
|
}
|
|
|
|
response = requests.post(f"{base_url}/auth/login",json=payload,headers=headers)
|
|
|
|
data = response.json()['data']
|
|
jwt = data["token"]
|
|
return jwt
|
|
|
|
def project_proccess(jwt):
|
|
headers = {
|
|
"Authorization": f"Bearer {jwt}",
|
|
"Content-Type": "application/json"
|
|
}
|
|
response = requests.get(f"{base_url}/report/project-statistics", headers=headers)
|
|
return response
|
|
|
|
try:
|
|
jwt = login()
|
|
response = project_proccess(jwt) # Call your function
|
|
|
|
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}")
|
|
|