diff --git a/app.py b/app.py
index dc06f38..c6ff6e5 100644
--- a/app.py
+++ b/app.py
@@ -3,7 +3,7 @@ from flask import Flask, render_template, request, redirect, url_for, session, s
from flask_caching import Cache
import requests.auth
import os
-from lib.datetime import filter_accounts_current_month, filter_accounts_expired
+from lib.datetime import filter_accounts_next_30_days, filter_accounts_expired
from lib.reqs import get_urls, get_user_accounts, add_user_account, delete_user_account, get_user_accounts_count
from flask import send_from_directory
import requests
@@ -63,7 +63,7 @@ def home():
base_url = app.config["BASE_URL"] # Access base_url from the config
all_accounts = get_user_accounts(base_url, session["auth_credentials"])
count = len(all_accounts)
- current_month_accounts = filter_accounts_current_month(all_accounts)
+ current_month_accounts = filter_accounts_next_30_days(all_accounts)
expired_accounts = filter_accounts_expired(all_accounts)
return render_template(
"home.html",
diff --git a/lib/datetime.py b/lib/datetime.py
index 2d562c1..dc85d2d 100644
--- a/lib/datetime.py
+++ b/lib/datetime.py
@@ -1,40 +1,29 @@
-from datetime import datetime
+from datetime import datetime, timedelta
from typing import List, Dict
-def filter_accounts_current_month(accounts: List[Dict[str, int]]) -> List[Dict[str, int]]:
- """Filter accounts whose expiry date falls within the current month.
+def filter_accounts_next_30_days(accounts: List[Dict[str, int]]) -> List[Dict[str, int]]:
+ """Filter accounts whose expiry date falls within the next 30 days.
Args:
accounts (List[Dict[str, int]]): A list of account dictionaries, each containing
an 'expiaryDate' key with an epoch timestamp as its value.
Returns:
- List[Dict[str, int]]: A list of accounts expiring in the current month.
+ List[Dict[str, int]]: A list of accounts expiring within the next 30 days.
"""
- # Get the start of the current month
now = datetime.now()
- start_of_month = datetime(now.year, now.month, 1)
+ thirty_days_later = now + timedelta(days=30)
- # Determine the start of the next month
- if now.month == 12:
- # If the current month is December, next month is January of the next year
- start_of_next_month = datetime(now.year + 1, 1, 1)
- else:
- # Otherwise, the next month is the following month of the same year
- start_of_next_month = datetime(now.year, now.month + 1, 1)
+ # Convert current time and 30 days later to epoch timestamps
+ now_timestamp = int(now.timestamp())
+ thirty_days_later_timestamp = int(thirty_days_later.timestamp())
- # Convert start and end of the month to epoch timestamps
- start_of_month_timestamp = int(start_of_month.timestamp())
- start_of_next_month_timestamp = int(start_of_next_month.timestamp())
-
- # Filter accounts with expiryDate in the current month
- accounts_in_current_month = [
+ # Filter accounts with expiryDate within the next 30 days
+ return [
account for account in accounts
- if start_of_month_timestamp <= account['expiaryDate'] < start_of_next_month_timestamp
+ if now_timestamp <= account['expiaryDate'] < thirty_days_later_timestamp
]
- return accounts_in_current_month
-
def filter_accounts_expired(accounts: List[Dict[str, int]]) -> List[Dict[str, int]]:
"""Filter accounts whose expiry date has passed.
diff --git a/templates/home.html b/templates/home.html
index 4e84737..a3f31ad 100644
--- a/templates/home.html
+++ b/templates/home.html
@@ -38,7 +38,7 @@
{% if current_month_accounts %}
-