From 2417d61b180914bc52b1bb008a9c43415e7674f9 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Mon, 29 Jan 2024 18:59:00 +0100 Subject: [PATCH] Save code + invoices.json --- invoices.json | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.py | 50 +++++++++++++++++++++ src/util.py | 77 ++++++++++++++++++++++++++++++++ 3 files changed, 247 insertions(+) create mode 100644 invoices.json create mode 100644 src/main.py create mode 100644 src/util.py diff --git a/invoices.json b/invoices.json new file mode 100644 index 0000000..615a703 --- /dev/null +++ b/invoices.json @@ -0,0 +1,120 @@ +{ + "data": { + "walletHistory": { + "facts": [ + { + "id": "148763", + "createdAt": "2024-01-21T09:30:03.480Z", + "sats": 1001, + "status": "CONFIRMED", + "invoiceComment": "Bitcoin $100K bet - Longtermwizard - 700" + }, + { + "id": "148728", + "createdAt": "2024-01-21T01:36:10.215Z", + "sats": 1000, + "status": "EXPIRED", + "invoiceComment": "Bitcoin 100k bet - Longtermwizard - 700" + }, + { + "id": "143791", + "createdAt": "2024-01-02T10:42:04.170Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "bitcoin $100k bet - 486DX2 - 486" + }, + { + "id": "142386", + "createdAt": "2023-12-27T09:35:18.952Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "bitcoin $100k bet - CheezeGrater - 418" + }, + { + "id": "141945", + "createdAt": "2023-12-24T10:15:49.953Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "bitcoin $100k bet - south_korea_ln - 608" + }, + { + "id": "141864", + "createdAt": "2023-12-23T23:52:56.472Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "bitcoin $100k bet - davidw - 564" + }, + { + "id": "141830", + "createdAt": "2023-12-23T17:36:36.196Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "bitcoin 100k bet - Lux - 522" + }, + { + "id": "141824", + "createdAt": "2023-12-23T16:52:11.103Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "100k bet - carlosfandango - 501" + }, + { + "id": "141819", + "createdAt": "2023-12-23T16:01:10.626Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "I don't recall my original number but whatever it was I am sticking with it. Cheers, grayruby. " + }, + { + "id": "141818", + "createdAt": "2023-12-23T15:57:58.806Z", + "sats": 10000, + "status": "EXPIRED", + "invoiceComment": "I don't recall my original number but whatever it was I am sticking with it. Cheers, grayruby. " + }, + { + "id": "141803", + "createdAt": "2023-12-23T14:19:22.075Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "Bitcoin 100k bet - Undisciplined - 653" + }, + { + "id": "141783", + "createdAt": "2023-12-23T08:56:28.387Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "bitcoin $100k bet - nikotsla 570" + }, + { + "id": "141781", + "createdAt": "2023-12-23T08:21:57.647Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "bitcoin $100k bet - 0fje0 - 427" + }, + { + "id": "141779", + "createdAt": "2023-12-23T08:09:35.781Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "bitcoin $100k bet - mango - 359" + }, + { + "id": "141777", + "createdAt": "2023-12-23T08:01:49.067Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "bitcoin $100k bet - gnilma - 666" + }, + { + "id": "141774", + "createdAt": "2023-12-23T06:49:03.149Z", + "sats": 1000, + "status": "CONFIRMED", + "invoiceComment": "bitcoin $100k bet - ekzyis - 420\n" + } + ] + } + } +} \ No newline at end of file diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..d71981c --- /dev/null +++ b/src/main.py @@ -0,0 +1,50 @@ +from util import START_DAY, TODAY, PASSED_DAYS, load_invoices, parse_invoices, Participant, populate_eliminated + +print(f""" +``` ++================================x +| Welcome to day {PASSED_DAYS} of the | +| _ _ _ _ | +| | |__ (_) |_ ___ ___ (_)_ __ | +| | '_ \| | __/ __/ _ \| | '_ \\ | +| | |_) | | || (_| (_) | | | | | | +| |_.__/|_|\__\___\___/|_|_| |_| | +| | +| 100k bet! | +x================================+ +``` +""") + +# last updated: 2024-01-29 +legend_of_snail_stacked = 119600 +oracle_stacked = 13769 +prize_pool = legend_of_snail_stacked + oracle_stacked + +invoices_path = "invoices.json" +invoices = load_invoices(invoices_path) + +participants = parse_invoices(invoices) +participants = populate_eliminated(participants) + +print(f"Date: {TODAY.strftime('%Y-%m-%d')}\n") +print(f"Number of participants: {len(participants)}\n") +print(f"Prize Pool: `{prize_pool} sats`\n") + +# add bets to prize pool +for p in participants: + if p.paid: + prize_pool += 1000 + + +# print participants table +print("| Nym | Day | Paid | Elimination Date | Eliminated |") +print("| --- | --- | ---- | ---------------- | ---------- |") +for p in participants: + print(p) + +for p in participants: + if not p.eliminated: + print(f"\nNext elimination: @{p.name} ({p.eliminated_in} days remaining)\n") + break + +print("_Want to participate? Click [here](https://stacker.news/items/363233) for more information._") diff --git a/src/util.py b/src/util.py new file mode 100644 index 0000000..7979b6d --- /dev/null +++ b/src/util.py @@ -0,0 +1,77 @@ +import json +import math +from datetime import datetime, timedelta +from operator import attrgetter + +# start date: 2023-04-16T22:18:10.830Z +# https://stacker.news/items/165652 +START_DAY = datetime.strptime("2023-04-16", '%Y-%m-%d') +TODAY = datetime.now() +# +1 since we start counting from 1 +PASSED_DAYS = (TODAY - START_DAY).days + 1 + + +def load_invoices(path): + with open(path, 'r') as file: + data = json.load(file) + invoices = data["data"]["walletHistory"]["facts"] + return invoices + +class Participant: + def __init__(self, name, day, paid=True): + self.name = name + self.day = day + self.paid = paid + self.eliminated = None + self.eliminated_in = -1 + self.elimination_date = None + def __str__(self): + return f"| @{self.name} | {self.day} | {'X' if self.paid else ''} | {self.elimination_date if self.elimination_date else ''} | {'X' if self.eliminated else ''} |" + +def parse_invoices(invoices): + participants = [ + # hardcoded participants (due to bad format in invoice comment) + Participant("orthwyrm", 260), + Participant("grayruby", 655), + Participant("nikotsla", 570), + Participant("siggy47", 380), + Participant("Alby", 365, False), + Participant("phatom", 440, False), + Participant("Longtermwizard", 700, True), + Participant("BitcoinIsTheFuture", 584, False) + ] + + for i in invoices: + status = i["status"] + if status != "CONFIRMED": + continue + sats = i["sats"] + if sats != 1000: + continue + comment = i["invoiceComment"].strip() + parts = [s.strip() for s in comment.split("-")] + if len(parts) != 3: + # print("invalid format:", comment) + continue + _, name, day = parts + participants.append(Participant(name, int(day))) + + participants = list(sorted(participants, key=attrgetter('day'))) + return participants + +def populate_eliminated(participants): + if len(participants) < 2: + return participants + + len_p = len(participants) + for index, p1 in enumerate(participants): + # last participant + if index == len_p - 1: + break + p2 = participants[index+1] + p1p2_center = p1.day + math.floor(abs(p1.day - p2.day)/2) + p1.eliminated_in = p1p2_center - PASSED_DAYS + p1.elimination_date = (TODAY + timedelta(days=p1.eliminated_in)).strftime("%Y-%m-%d") + p1.eliminated = PASSED_DAYS >= p1p2_center + + return participants \ No newline at end of file