|
|
@ -5,6 +5,8 @@ import os
|
|
|
|
import socket
|
|
|
|
import socket
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
|
|
from .config import get_config
|
|
|
|
from .config import get_config
|
|
|
|
from .zulip import Client
|
|
|
|
from .zulip import Client
|
|
|
|
|
|
|
|
|
|
|
@ -38,12 +40,29 @@ def get_giveaway():
|
|
|
|
now = time.time()
|
|
|
|
now = time.time()
|
|
|
|
timeout = REFRESH_RISING if g is None else REFRESH_FALLING
|
|
|
|
timeout = REFRESH_RISING if g is None else REFRESH_FALLING
|
|
|
|
if t is None or now - t > timeout:
|
|
|
|
if t is None or now - t > timeout:
|
|
|
|
resp = session.get("https://desertbus.org/wapi/currentGiveaway")
|
|
|
|
try:
|
|
|
|
resp.raise_for_status()
|
|
|
|
g = _get_giveaway()
|
|
|
|
g = resp.json()["giveaway"]
|
|
|
|
except Exception:
|
|
|
|
giveaway_cache[0] = t
|
|
|
|
logging.warning("Failed to fetch giveaway", exc_info=True)
|
|
|
|
giveaway_cache[1] = g
|
|
|
|
else:
|
|
|
|
return g
|
|
|
|
giveaway_cache[0] = t
|
|
|
|
|
|
|
|
giveaway_cache[1] = g
|
|
|
|
|
|
|
|
return giveaway_cache[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_giveaway():
|
|
|
|
|
|
|
|
resp = session.get("https://desertbus.org/2024/donate", headers={"User-Agent": ""})
|
|
|
|
|
|
|
|
resp.raise_for_status()
|
|
|
|
|
|
|
|
html = BeautifulSoup(resp.content.decode(), "html.parser")
|
|
|
|
|
|
|
|
island = html.find("astro-island", **{"component-export": "DonateForm"})
|
|
|
|
|
|
|
|
if island is None:
|
|
|
|
|
|
|
|
logging.warning("Could not find DonateForm astro-island in donate page")
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
data = json.loads(island["props"])
|
|
|
|
|
|
|
|
giveaways = data["giveaways"][1]
|
|
|
|
|
|
|
|
if giveaways:
|
|
|
|
|
|
|
|
return giveaways[1]["amount"][1] / 100.
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(conf_file, message_log_file, name=socket.gethostname()):
|
|
|
|
def main(conf_file, message_log_file, name=socket.gethostname()):
|
|
|
@ -97,15 +116,14 @@ def main(conf_file, message_log_file, name=socket.gethostname()):
|
|
|
|
increase = None if total is None else msg["d"] - total
|
|
|
|
increase = None if total is None else msg["d"] - total
|
|
|
|
log["increase"] = increase
|
|
|
|
log["increase"] = increase
|
|
|
|
increase_str = "" if increase is None else " (+${:.2f})".format(msg["d"] - total)
|
|
|
|
increase_str = "" if increase is None else " (+${:.2f})".format(msg["d"] - total)
|
|
|
|
giveaway = None
|
|
|
|
giveaway_amount = get_giveaway()
|
|
|
|
entries_str = ""
|
|
|
|
entries_str = ""
|
|
|
|
if increase is not None and giveaway is not None:
|
|
|
|
if increase is not None and giveaway_amount is not None:
|
|
|
|
amount = giveaway["amount"]
|
|
|
|
if (increase + 0.005) % giveaway_amount < 0.01:
|
|
|
|
if (increase + 0.005) % amount < 0.01:
|
|
|
|
entries = int((increase + 0.005) / giveaway_amount)
|
|
|
|
entries = int((increase + 0.005) / amount)
|
|
|
|
log["giveaway_amount"] = giveaway_amount
|
|
|
|
log["giveaway_amount"] = amount
|
|
|
|
|
|
|
|
log["giveaway_entries"] = entries
|
|
|
|
log["giveaway_entries"] = entries
|
|
|
|
entries_str = " ({} entries of ${:.2f})".format(entries, amount)
|
|
|
|
entries_str = " ({} entries of ${:.2f})".format(entries, giveaway_amount)
|
|
|
|
logging.info("New donation total: {}{}{}".format(msg["d"], increase_str, entries_str))
|
|
|
|
logging.info("New donation total: {}{}{}".format(msg["d"], increase_str, entries_str))
|
|
|
|
client.send_to_stream("bot-spam", "Donation Firehose", "Donation total is now ${:.2f}{}{}".format(msg["d"], increase_str, entries_str))
|
|
|
|
client.send_to_stream("bot-spam", "Donation Firehose", "Donation total is now ${:.2f}{}{}".format(msg["d"], increase_str, entries_str))
|
|
|
|
if increase is not None and increase >= 500:
|
|
|
|
if increase is not None and increase >= 500:
|
|
|
|