show days in red
This commit is contained in:
parent
9425fde4b8
commit
0eb79c3775
@ -3,34 +3,34 @@ from typing import List, Dict
|
||||
|
||||
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 within the next 30 days.
|
||||
"""
|
||||
now = datetime.now()
|
||||
thirty_days_later = now + timedelta(days=30)
|
||||
|
||||
# Convert current time and 30 days later to epoch timestamps
|
||||
now_timestamp = int(now.timestamp())
|
||||
thirty_days_later_timestamp = int(thirty_days_later.timestamp())
|
||||
|
||||
# Filter accounts with expiryDate within the next 30 days
|
||||
return [
|
||||
account for account in accounts
|
||||
if now_timestamp <= account['expiaryDate'] < thirty_days_later_timestamp
|
||||
]
|
||||
result = []
|
||||
today = now.date()
|
||||
|
||||
for account in accounts:
|
||||
if now_timestamp <= account['expiaryDate'] < thirty_days_later_timestamp:
|
||||
expiry_date = datetime.fromtimestamp(account['expiaryDate'])
|
||||
account['expiaryDate_rendered'] = expiry_date.strftime('%d-%m-%Y')
|
||||
expiry_date_date = expiry_date.date()
|
||||
account['days_to_expiry'] = (expiry_date_date - today).days
|
||||
result.append(account)
|
||||
return result
|
||||
|
||||
def filter_accounts_expired(accounts: List[Dict[str, int]]) -> List[Dict[str, int]]:
|
||||
"""Filter accounts whose expiry date has passed.
|
||||
|
||||
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 that have expired.
|
||||
"""
|
||||
@ -38,9 +38,11 @@ def filter_accounts_expired(accounts: List[Dict[str, int]]) -> List[Dict[str, in
|
||||
current_timestamp = int(datetime.now().timestamp())
|
||||
|
||||
# Filter accounts where the current date is greater than the expiryDate
|
||||
expired_accounts = [
|
||||
account for account in accounts
|
||||
if account['expiaryDate'] < current_timestamp
|
||||
]
|
||||
expired_accounts = []
|
||||
for account in accounts:
|
||||
if account['expiaryDate'] < current_timestamp:
|
||||
expiry_date = datetime.fromtimestamp(account['expiaryDate'])
|
||||
account['expiaryDate_rendered'] = expiry_date.strftime('%d-%m-%Y')
|
||||
expired_accounts.append(account)
|
||||
|
||||
return expired_accounts
|
||||
|
@ -23,7 +23,7 @@
|
||||
<tr>
|
||||
<td>{{ account.stream }}</td>
|
||||
<td>{{ account.username }}</td>
|
||||
<td>{{ account.expiaryDate_rendered }}</td>
|
||||
<td>{{ account.expiaryDate_rendered }} {% if account.days_to_expiry is defined %}<span style="color: red;">({{ account.days_to_expiry }} days)</span>{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
Loading…
x
Reference in New Issue
Block a user