Skip to content

Commit

Permalink
Improve LowWine alert system (#293)
Browse files Browse the repository at this point in the history
* Update alertLowWine.py

* Update alertLowWine.py

* Update alertLowWine.py

* Update alertLowWine.py

* Update alertLowWine.py

* Update alertLowWine.py

* Update alertLowWine.py

I have change and now the was_alerted will be clear. Added in message_log to pull the amount of wine and consumption.
  • Loading branch information
morecs authored Feb 6, 2025
1 parent e2c84f8 commit edd487b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ikabot/function/alertLowWine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import re
import time
import datetime
import traceback
from decimal import *
import json
Expand Down Expand Up @@ -50,8 +51,7 @@ def alertLowWine(session, event, stdin_fd, predetermined_input):
else:
auto_transfer = False
transfer_amount = 0

print("It will be alerted when the wine runs out in less than {:d} hours in any city".format(hours))
print("It will be alerted when the wine runs out in less than {:d} hours in any city, and {:,d} wine will be transferred if necessary.".format(hours, transfer_amount))
enter()
except KeyboardInterrupt:
event.set()
Expand Down Expand Up @@ -134,8 +134,15 @@ def do_it(session, hours, auto_transfer, transfer_amount):
was_alerted = {}
message_log = []
routes = [] # Store all routes for batch execution

last_reset_time = datetime.datetime.now()

while True:
current_time = datetime.datetime.now()
time_elapsed = (current_time - last_reset_time).total_seconds()
if time_elapsed >= 12 * 60 * 60: # 12 h to reset the alerted list
was_alerted.clear() # Reset all alerts
last_reset_time = current_time # Update the last time reseted the list

ids, cities = getIdsOfCities(session)

for cityId in cities:
Expand Down Expand Up @@ -176,7 +183,7 @@ def do_it(session, hours, auto_transfer, transfer_amount):
if seconds_left < hours * 60 * 60:
if was_alerted[cityId] is False:
time_left = daysHoursMinutes(seconds_left)
message_log.append(f"In {city['name']}, the wine will run out in {time_left}")
message_log.append(f"In {city['name']} you have: {city['availableResources'][1]:,.0f} wine. Consumption: {consumption_per_hour:.2f} per hour.\nThe wine will run out in {time_left}")

if auto_transfer:
transport_status = isWineTransportInProgress(session, cityId)
Expand Down Expand Up @@ -222,7 +229,7 @@ def do_it(session, hours, auto_transfer, transfer_amount):
0, # Sulfur
))

message_log.append(f"Will transfer {transfer_amount} from {donor_city['name']}.")
message_log.append(f"Will transfer {transfer_amount:,.0f:,.0f} from {donor_city['name']}.")
else:
message_log.append(f"No city has sufficient wine to transfer to {city['name']}.")

Expand Down

0 comments on commit edd487b

Please sign in to comment.