replace spaces with tabs

remotes/1693045480750635534/spooky-22
Aevann1 2022-06-13 20:33:25 +02:00
parent d8fff0bc72
commit 0f49c8e32f
10 changed files with 344 additions and 344 deletions

View File

@ -6,27 +6,27 @@ from files.helpers.const import *
class Lottery(Base): class Lottery(Base):
__tablename__ = "lotteries" __tablename__ = "lotteries"
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
is_active = Column(Boolean, default=False) is_active = Column(Boolean, default=False)
ends_at = Column(Integer) ends_at = Column(Integer)
prize = Column(Integer, default=0) prize = Column(Integer, default=0)
tickets_sold = Column(Integer, default=0) tickets_sold = Column(Integer, default=0)
winner_id = Column(Integer, ForeignKey("users.id")) winner_id = Column(Integer, ForeignKey("users.id"))
@property @property
@lazy @lazy
def timeleft(self): def timeleft(self):
if not self.is_active: if not self.is_active:
return 0 return 0
epoch_time = int(time.time()) epoch_time = int(time.time())
remaining_time = self.ends_at - epoch_time remaining_time = self.ends_at - epoch_time
return 0 if remaining_time < 0 else remaining_time return 0 if remaining_time < 0 else remaining_time
@property @property
@lazy @lazy
def stats(self): def stats(self):
return {"active": self.is_active, "timeLeft": self.timeleft, "prize": self.prize, "ticketsSoldThisSession": self.tickets_sold,} return {"active": self.is_active, "timeLeft": self.timeleft, "prize": self.prize, "ticketsSoldThisSession": self.tickets_sold,}

View File

@ -4,7 +4,7 @@ from files.classes.badges import Badge, BadgeDef
# TODO: More sanity checks on passed parameters. # TODO: More sanity checks on passed parameters.
# TODO: Add `replace=False` parameter which, when set true, removes any # TODO: Add `replace=False` parameter which, when set true, removes any
# existing badge with identical id & user and replaces with new one. # existing badge with identical id & user and replaces with new one.
def badge_grant(user_id, badge_id, desc='', url='', commit=True): def badge_grant(user_id, badge_id, desc='', url='', commit=True):
user = g.db.query(User).filter(User.id == int(user_id)).one_or_none() user = g.db.query(User).filter(User.id == int(user_id)).one_or_none()
if not user: if not user:

View File

@ -525,13 +525,13 @@ AWARDS = {
"price": 500 "price": 500
}, },
"glowie": { "glowie": {
"kind": "glowie", "kind": "glowie",
"title": "Glowie", "title": "Glowie",
"description": "Indicates that the recipient can be seen when driving. Just run them over.", "description": "Indicates that the recipient can be seen when driving. Just run them over.",
"icon": "fas fa-user-secret", "icon": "fas fa-user-secret",
"color": "text-green", "color": "text-green",
"price": 500 "price": 500
}, },
"rehab": { "rehab": {
"kind": "rehab", "kind": "rehab",
"title": "Rehab", "title": "Rehab",
@ -541,13 +541,13 @@ AWARDS = {
"price": 777 "price": 777
}, },
"beano": { "beano": {
"kind": "beano", "kind": "beano",
"title": "Beano", "title": "Beano",
"description": "Stops you from embarrassing yourself with your flatulence", "description": "Stops you from embarrassing yourself with your flatulence",
"icon": "fas fa-gas-pump-slash", "icon": "fas fa-gas-pump-slash",
"color": "text-green", "color": "text-green",
"price": 1000 "price": 1000
}, },
"progressivestack": { "progressivestack": {
"kind": "progressivestack", "kind": "progressivestack",
"title": "Progressive Stack", "title": "Progressive Stack",

View File

@ -10,120 +10,120 @@ from .const import *
LOTTERY_WINNER_BADGE_ID = 137 LOTTERY_WINNER_BADGE_ID = 137
def get_active_lottery(): def get_active_lottery():
return g.db.query(Lottery).order_by(Lottery.id.desc()).filter(Lottery.is_active).one_or_none() return g.db.query(Lottery).order_by(Lottery.id.desc()).filter(Lottery.is_active).one_or_none()
def get_users_participating_in_lottery(): def get_users_participating_in_lottery():
return g.db.query(User) \ return g.db.query(User) \
.filter(User.currently_held_lottery_tickets > 0) \ .filter(User.currently_held_lottery_tickets > 0) \
.order_by(User.currently_held_lottery_tickets.desc()).all() .order_by(User.currently_held_lottery_tickets.desc()).all()
def get_active_lottery_stats(): def get_active_lottery_stats():
active_lottery = get_active_lottery() active_lottery = get_active_lottery()
participating_users = get_users_participating_in_lottery() participating_users = get_users_participating_in_lottery()
return None if active_lottery is None else active_lottery.stats, len(participating_users) return None if active_lottery is None else active_lottery.stats, len(participating_users)
def end_lottery_session(): def end_lottery_session():
active_lottery = get_active_lottery() active_lottery = get_active_lottery()
if (active_lottery is None): if (active_lottery is None):
return False, "There is no active lottery." return False, "There is no active lottery."
participating_users = get_users_participating_in_lottery() participating_users = get_users_participating_in_lottery()
raffle = [] raffle = []
for user in participating_users: for user in participating_users:
for _ in range(user.currently_held_lottery_tickets): for _ in range(user.currently_held_lottery_tickets):
raffle.append(user.id) raffle.append(user.id)
winner = choice(raffle) winner = choice(raffle)
active_lottery.winner_id = winner active_lottery.winner_id = winner
winning_user = next(filter(lambda x: x.id == winner, participating_users)) winning_user = next(filter(lambda x: x.id == winner, participating_users))
winning_user.coins += active_lottery.prize winning_user.coins += active_lottery.prize
winning_user.total_lottery_winnings += active_lottery.prize winning_user.total_lottery_winnings += active_lottery.prize
badge_grant(winner, LOTTERY_WINNER_BADGE_ID) badge_grant(winner, LOTTERY_WINNER_BADGE_ID)
for user in participating_users: for user in participating_users:
chance_to_win = user.currently_held_lottery_tickets / len(raffle) * 100 chance_to_win = user.currently_held_lottery_tickets / len(raffle) * 100
if user.id == winner: if user.id == winner:
notification_text = f'You won {active_lottery.prize} coins in the lottery! ' \ notification_text = f'You won {active_lottery.prize} coins in the lottery! ' \
+ f'Congratulations!\nYour odds of winning were: {chance_to_win}%' + f'Congratulations!\nYour odds of winning were: {chance_to_win}%'
else: else:
notification_text = f'You did not win the lottery. Better luck next time!\n' \ notification_text = f'You did not win the lottery. Better luck next time!\n' \
+ f'Your odds of winning were: {chance_to_win}%\nWinner: @{winning_user.username} (won {active_lottery.prize} coins)' + f'Your odds of winning were: {chance_to_win}%\nWinner: @{winning_user.username} (won {active_lottery.prize} coins)'
send_repeatable_notification(user.id, notification_text) send_repeatable_notification(user.id, notification_text)
user.currently_held_lottery_tickets = 0 user.currently_held_lottery_tickets = 0
active_lottery.is_active = False active_lottery.is_active = False
g.db.commit() g.db.commit()
return True, f'{winning_user.username} won {active_lottery.prize} coins!' return True, f'{winning_user.username} won {active_lottery.prize} coins!'
def start_new_lottery_session(): def start_new_lottery_session():
end_lottery_session() end_lottery_session()
lottery = Lottery() lottery = Lottery()
epoch_time = int(time.time()) epoch_time = int(time.time())
# Subtract 4 minutes from one week so cronjob interval doesn't cause the # Subtract 4 minutes from one week so cronjob interval doesn't cause the
# time to drift toward over multiple weeks. # time to drift toward over multiple weeks.
one_week_from_now = epoch_time + 60 * 60 * 24 * 7 - (4 * 60) one_week_from_now = epoch_time + 60 * 60 * 24 * 7 - (4 * 60)
lottery.ends_at = one_week_from_now lottery.ends_at = one_week_from_now
lottery.is_active = True lottery.is_active = True
g.db.add(lottery) g.db.add(lottery)
g.db.commit() g.db.commit()
def check_if_end_lottery_task(): def check_if_end_lottery_task():
active_lottery = get_active_lottery() active_lottery = get_active_lottery()
if active_lottery is None: if active_lottery is None:
return False return False
elif active_lottery.timeleft > 0: elif active_lottery.timeleft > 0:
return False return False
start_new_lottery_session() start_new_lottery_session()
return True return True
def lottery_ticket_net_value(): def lottery_ticket_net_value():
return LOTTERY_TICKET_COST - LOTTERY_SINK_RATE return LOTTERY_TICKET_COST - LOTTERY_SINK_RATE
def purchase_lottery_tickets(v, quantity=1): def purchase_lottery_tickets(v, quantity=1):
if quantity < 1: if quantity < 1:
return False, "Must purchase one or more lottery tickets." return False, "Must purchase one or more lottery tickets."
elif (v.coins < LOTTERY_TICKET_COST * quantity): elif (v.coins < LOTTERY_TICKET_COST * quantity):
return False, f'Lottery tickets cost {LOTTERY_TICKET_COST} coins each.' return False, f'Lottery tickets cost {LOTTERY_TICKET_COST} coins each.'
most_recent_lottery = get_active_lottery() most_recent_lottery = get_active_lottery()
if (most_recent_lottery is None): if (most_recent_lottery is None):
return False, "There is no active lottery." return False, "There is no active lottery."
v.coins -= LOTTERY_TICKET_COST * quantity v.coins -= LOTTERY_TICKET_COST * quantity
v.currently_held_lottery_tickets += quantity v.currently_held_lottery_tickets += quantity
v.total_held_lottery_tickets += quantity v.total_held_lottery_tickets += quantity
net_ticket_value = lottery_ticket_net_value() * quantity net_ticket_value = lottery_ticket_net_value() * quantity
most_recent_lottery.prize += net_ticket_value most_recent_lottery.prize += net_ticket_value
most_recent_lottery.tickets_sold += quantity most_recent_lottery.tickets_sold += quantity
g.db.commit() g.db.commit()
if quantity == 1: return True, f'Successfully purchased {quantity} lottery ticket!' if quantity == 1: return True, f'Successfully purchased {quantity} lottery ticket!'
return True, f'Successfully purchased {quantity} lottery tickets!' return True, f'Successfully purchased {quantity} lottery tickets!'
def grant_lottery_tickets_to_user(v, quantity): def grant_lottery_tickets_to_user(v, quantity):
active_lottery = get_active_lottery() active_lottery = get_active_lottery()
prize_value = lottery_ticket_net_value() * quantity prize_value = lottery_ticket_net_value() * quantity
if active_lottery: if active_lottery:
v.currently_held_lottery_tickets += quantity v.currently_held_lottery_tickets += quantity
v.total_held_lottery_tickets += quantity v.total_held_lottery_tickets += quantity
active_lottery.prize += prize_value active_lottery.prize += prize_value
active_lottery.tickets_sold += quantity active_lottery.tickets_sold += quantity
g.db.commit() g.db.commit()

View File

@ -63,13 +63,13 @@ def chart(kind, site):
plt.rcParams['figure.figsize'] = (chart_width, 20) plt.rcParams['figure.figsize'] = (chart_width, 20)
signup_chart = plt.subplot2grid((chart_width, 20), ( 0, 0), rowspan=6, colspan=chart_width) signup_chart = plt.subplot2grid((chart_width, 20), ( 0, 0), rowspan=6, colspan=chart_width)
posts_chart = plt.subplot2grid((chart_width, 20), (10, 0), rowspan=6, colspan=chart_width) posts_chart = plt.subplot2grid((chart_width, 20), (10, 0), rowspan=6, colspan=chart_width)
comments_chart = plt.subplot2grid((chart_width, 20), (20, 0), rowspan=6, colspan=chart_width) comments_chart = plt.subplot2grid((chart_width, 20), (20, 0), rowspan=6, colspan=chart_width)
signup_chart.grid(), posts_chart.grid(), comments_chart.grid() signup_chart.grid(), posts_chart.grid(), comments_chart.grid()
signup_chart.plot (daily_times, daily_signups, color='red') signup_chart.plot (daily_times, daily_signups, color='red')
posts_chart.plot (daily_times, post_stats, color='blue') posts_chart.plot (daily_times, post_stats, color='blue')
comments_chart.plot(daily_times, comment_stats, color='purple') comments_chart.plot(daily_times, comment_stats, color='purple')
signup_chart.set_ylim(ymin=0) signup_chart.set_ylim(ymin=0)

View File

@ -11,16 +11,16 @@ import requests
@admin_level_required(3) @admin_level_required(3)
@lottery_required @lottery_required
def lottery_end(v): def lottery_end(v):
success, message = end_lottery_session() success, message = end_lottery_session()
return {"message": message} if success else {"error": message} return {"message": message} if success else {"error": message}
@app.post("/lottery/start") @app.post("/lottery/start")
@admin_level_required(3) @admin_level_required(3)
@lottery_required @lottery_required
def lottery_start(v): def lottery_start(v):
start_new_lottery_session() start_new_lottery_session()
return {"message": "Lottery started."} return {"message": "Lottery started."}
@app.post("/lottery/buy") @app.post("/lottery/buy")
@ -28,15 +28,15 @@ def lottery_start(v):
@auth_required @auth_required
@lottery_required @lottery_required
def lottery_buy(v): def lottery_buy(v):
quantity = int(request.values.get("quantity")) quantity = int(request.values.get("quantity"))
success, message = purchase_lottery_tickets(v, quantity) success, message = purchase_lottery_tickets(v, quantity)
lottery, participants = get_active_lottery_stats() lottery, participants = get_active_lottery_stats()
if success: if success:
return {"message": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}} return {"message": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}}
else: else:
return {"error": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}} return {"error": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}}
@app.get("/lottery/active") @app.get("/lottery/active")
@ -44,20 +44,20 @@ def lottery_buy(v):
@auth_required @auth_required
@lottery_required @lottery_required
def lottery_active(v): def lottery_active(v):
lottery, participants = get_active_lottery_stats() lottery, participants = get_active_lottery_stats()
return {"message": "", "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}} return {"message": "", "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}}
@app.get("/lottery") @app.get("/lottery")
@auth_required @auth_required
@lottery_required @lottery_required
def lottery(v): def lottery(v):
lottery_stats, participant_stats = get_active_lottery_stats() lottery_stats, participant_stats = get_active_lottery_stats()
return render_template("lottery.html", v=v, lottery_stats=lottery_stats, participant_stats=participant_stats) return render_template("lottery.html", v=v, lottery_stats=lottery_stats, participant_stats=participant_stats)
@app.get("/admin/lottery/participants") @app.get("/admin/lottery/participants")
@admin_level_required(2) @admin_level_required(2)
@lottery_required @lottery_required
def lottery_admin(v): def lottery_admin(v):
participants = get_users_participating_in_lottery() participants = get_users_participating_in_lottery()
return render_template("admin/lottery.html", v=v, participants=participants) return render_template("admin/lottery.html", v=v, participants=participants)

View File

@ -44,11 +44,11 @@
} }
{% endif %} {% endif %}
</style> </style>
<div id="logo-container" class="flex-grow-1 logo-container"> <div id="logo-container" class="flex-grow-1 logo-container">
<a href="/"> <a href="/">
<img class="ml-1" id="logo" alt="logo" src="/assets/images/{{SITE_NAME}}/logo.webp?v=1013" width=70> <img class="ml-1" id="logo" alt="logo" src="/assets/images/{{SITE_NAME}}/logo.webp?v=1013" width=70>
</a> </a>
</div> </div>
{% endif %} {% endif %}
<div class="flex-grow-1 d-fl d-none d-md-block {% if not v %}pad{% endif %}"> <div class="flex-grow-1 d-fl d-none d-md-block {% if not v %}pad{% endif %}">

View File

@ -1,191 +1,191 @@
{% extends "default.html" %} {% block content %} {% extends "default.html" %} {% block content %}
<div> <div>
<div class="lottery-page--wrapper"> <div class="lottery-page--wrapper">
<div class="lottery-page--image"> <div class="lottery-page--image">
<img src="/assets/images/{{SITE_NAME}}/lottery.webp?v=2" /> <img src="/assets/images/{{SITE_NAME}}/lottery.webp?v=2" />
<img <img
id="lotteryTicketPulled" id="lotteryTicketPulled"
src="/assets/images/{{SITE_NAME}}/lottery_active.webp?v=2" src="/assets/images/{{SITE_NAME}}/lottery_active.webp?v=2"
style="display: none" style="display: none"
/> />
</div> </div>
<div class="lottery-page--stats"> <div class="lottery-page--stats">
{% if v.admin_level > 2 %} {% if v.admin_level > 2 %}
<div <div
class="lottery-page--stat" class="lottery-page--stat"
style="position: relative; padding-top: 1rem; overflow: hidden" style="position: relative; padding-top: 1rem; overflow: hidden"
> >
<i <i
class="fas fa-broom" class="fas fa-broom"
style=" style="
position: absolute; position: absolute;
bottom: -4px; bottom: -4px;
right: -4px; right: -4px;
font-size: 50px; font-size: 50px;
color: var(--gray-600); color: var(--gray-600);
" "
> >
</i> </i>
<button <button
type="button" type="button"
class="btn btn-danger" class="btn btn-danger"
id="endLotterySession" id="endLotterySession"
style="display: none" style="display: none"
onclick="endLotterySession()" onclick="endLotterySession()"
> >
End Current Session End Current Session
</button> </button>
<button <button
type="button" type="button"
class="btn btn-success" class="btn btn-success"
id="startLotterySession" id="startLotterySession"
style="display: none" style="display: none"
onclick="startLotterySession()" onclick="startLotterySession()"
> >
Start New Session Start New Session
</button> </button>
</div> </div>
{% endif %} {% endif %}
<div class="lottery-page--stat"> <div class="lottery-page--stat">
<div class="lottery-page--stat-keys"> <div class="lottery-page--stat-keys">
<div>Prize</div> <div>Prize</div>
<div>Time Left</div> <div>Time Left</div>
<div>Tickets Sold</div> <div>Tickets Sold</div>
<div>Participants</div> <div>Participants</div>
</div> </div>
<div class="lottery-page--stat-values"> <div class="lottery-page--stat-values">
<div> <div>
<img <img
id="prize-image" id="prize-image"
alt="coins" alt="coins"
class="mr-1 ml-1" class="mr-1 ml-1"
data-bs-toggle="tooltip" data-bs-toggle="tooltip"
data-bs-placement="bottom" data-bs-placement="bottom"
height="13" height="13"
src="/assets/images/{{SITE_NAME}}/coins.webp?v=2" src="/assets/images/{{SITE_NAME}}/coins.webp?v=2"
title="" title=""
aria-label="coins" aria-label="coins"
data-bs-original-title="coins" data-bs-original-title="coins"
style="display: none; position: relative; top: -2px" style="display: none; position: relative; top: -2px"
/> />
<span id="prize">-</span> <span id="prize">-</span>
</div> </div>
<div id="timeLeft">-</div> <div id="timeLeft">-</div>
<div id="ticketsSoldThisSession">-</div> <div id="ticketsSoldThisSession">-</div>
<div id="participantsThisSession">-</div> <div id="participantsThisSession">-</div>
</div> </div>
</div> </div>
<div class="lottery-page--stat"> <div class="lottery-page--stat">
<div class="lottery-page--stat-keys"> <div class="lottery-page--stat-keys">
<div>Your Held Tickets</div> <div>Your Held Tickets</div>
<div>Lifetime Held Tickets</div> <div>Lifetime Held Tickets</div>
<div>Lifetime Winnings</div> <div>Lifetime Winnings</div>
</div> </div>
<div class="lottery-page--stat-values"> <div class="lottery-page--stat-values">
<div id="ticketsHeldCurrent">-</div> <div id="ticketsHeldCurrent">-</div>
<div id="ticketsHeldTotal">-</div> <div id="ticketsHeldTotal">-</div>
<div id="winnings">-</div> <div id="winnings">-</div>
</div> </div>
</div> </div>
<div class="lottery-page--stat"> <div class="lottery-page--stat">
<div class="lottery-page--stat-keys"> <div class="lottery-page--stat-keys">
<div>Purchase Quantity</div> <div>Purchase Quantity</div>
</div> </div>
<div class="lottery-page--stat-values"> <div class="lottery-page--stat-values">
<div> <div>
<input <input
id="ticketPurchaseQuantity" id="ticketPurchaseQuantity"
class="form-control" class="form-control"
autocomplete="off" autocomplete="off"
value="1" value="1"
min="1" min="1"
step="1" step="1"
aria-label="Quantity" aria-label="Quantity"
name="ticketPurchaseQuantity" name="ticketPurchaseQuantity"
type="number" type="number"
style="flex: 1; max-width: 100px; text-align: center;" style="flex: 1; max-width: 100px; text-align: center;"
/> />
</div> </div>
</div> </div>
</div> </div>
<button <button
type="button" type="button"
class="btn btn-success lottery-page--action" class="btn btn-success lottery-page--action"
id="purchaseTicket" id="purchaseTicket"
onclick="purchaseLotteryTicket()" onclick="purchaseLotteryTicket()"
> >
Purchase <span id="totalQuantityOfTickets">1</span> for Purchase <span id="totalQuantityOfTickets">1</span> for
<img <img
alt="coins" alt="coins"
class="mr-1 ml-1" class="mr-1 ml-1"
data-bs-toggle="tooltip" data-bs-toggle="tooltip"
data-bs-placement="bottom" data-bs-placement="bottom"
height="13" height="13"
src="/assets/images/{{SITE_NAME}}/coins.webp?v=2" src="/assets/images/{{SITE_NAME}}/coins.webp?v=2"
title="" title=""
aria-label="coins" aria-label="coins"
data-bs-original-title="coins" data-bs-original-title="coins"
/> />
<span id="totalCostOfTickets">12</span> <span id="totalCostOfTickets">12</span>
</button> </button>
</div> </div>
<!-- Success --> <!-- Success -->
<div <div
class="toast" class="toast"
id="lottery-post-success" id="lottery-post-success"
style=" style="
position: fixed; position: fixed;
bottom: 1.5rem; bottom: 1.5rem;
margin: 0 auto; margin: 0 auto;
left: 0; left: 0;
right: 0; right: 0;
width: unset; width: unset;
z-index: 1000; z-index: 1000;
height: auto !important; height: auto !important;
" "
role="alert" role="alert"
aria-live="assertive" aria-live="assertive"
aria-atomic="true" aria-atomic="true"
data-bs-animation="true" data-bs-animation="true"
data-bs-autohide="true" data-bs-autohide="true"
data-bs-delay="5000" data-bs-delay="5000"
> >
<div class="toast-body bg-success text-center text-white"> <div class="toast-body bg-success text-center text-white">
<i class="fas fa-comment-alt-smile mr-2"></i <i class="fas fa-comment-alt-smile mr-2"></i
><span id="lottery-post-success-text"></span> ><span id="lottery-post-success-text"></span>
</div> </div>
</div> </div>
<!-- Error --> <!-- Error -->
<div <div
class="toast" class="toast"
id="lottery-post-error" id="lottery-post-error"
style=" style="
position: fixed; position: fixed;
bottom: 1.5rem; bottom: 1.5rem;
margin: 0 auto; margin: 0 auto;
left: 0; left: 0;
right: 0; right: 0;
width: unset; width: unset;
z-index: 1000; z-index: 1000;
height: auto !important; height: auto !important;
" "
role="alert" role="alert"
aria-live="assertive" aria-live="assertive"
aria-atomic="true" aria-atomic="true"
data-bs-animation="true" data-bs-animation="true"
data-bs-autohide="true" data-bs-autohide="true"
data-bs-delay="5000" data-bs-delay="5000"
> >
<div class="toast-body bg-danger text-center text-white"> <div class="toast-body bg-danger text-center text-white">
<i class="fas fa-exclamation-circle mr-2"></i <i class="fas fa-exclamation-circle mr-2"></i
><span id="lottery-post-error-text"></span> ><span id="lottery-post-error-text"></span>
</div> </div>
</div> </div>
</div> </div>
<script src="{{asset('js/lottery.js')}}"></script> <script src="{{asset('js/lottery.js')}}"></script>

View File

@ -68,7 +68,7 @@
{% endif %} {% endif %}
{% if p.award_count("firework") %} {% if p.award_count("firework") %}
<script defer src="/assets/js/fireworks.js?v=4"></script> <script defer src="/assets/js/fireworks.js?v=4"></script>
<div class="firework"> <div class="firework">
<img src=""> <img src="">
</div> </div>

View File

@ -5,48 +5,48 @@ import sys
# we want to leave the container in whatever state it currently is, so check to see if it's running # we want to leave the container in whatever state it currently is, so check to see if it's running
docker_inspect = subprocess.run([ docker_inspect = subprocess.run([
"docker", "docker",
"container", "container",
"inspect", "inspect",
"-f", "{{.State.Status}}", "-f", "{{.State.Status}}",
"rDrama", "rDrama",
], ],
capture_output = True, capture_output = True,
).stdout.decode("utf-8").strip() ).stdout.decode("utf-8").strip()
was_running = docker_inspect == "running" was_running = docker_inspect == "running"
# update containers, just in case they're out of date # update containers, just in case they're out of date
if was_running: if was_running:
print("Updating containers . . .", flush=True) print("Updating containers . . .", flush=True)
else: else:
print("Starting containers . . .", flush=True) print("Starting containers . . .", flush=True)
subprocess.run([ subprocess.run([
"docker-compose", "docker-compose",
"up", "up",
"--build", "--build",
"-d", "-d",
], ],
check = True, check = True,
) )
# run the test # run the test
print("Running test . . .", flush=True) print("Running test . . .", flush=True)
result = subprocess.run([ result = subprocess.run([
"docker", "docker",
"exec", "exec",
"rDrama", "rDrama",
"bash", "-c", "cd service && python3 -m pytest -s" "bash", "-c", "cd service && python3 -m pytest -s"
]) ])
if not was_running: if not was_running:
# shut down, if we weren't running in the first place # shut down, if we weren't running in the first place
print("Shutting down containers . . .", flush=True) print("Shutting down containers . . .", flush=True)
subprocess.run([ subprocess.run([
"docker-compose", "docker-compose",
"stop", "stop",
], ],
check = True, check = True,
) )
sys.exit(result.returncode) sys.exit(result.returncode)