about summary refs log tree commit diff
path: root/packages/pizza
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2024-04-28 19:15:51 -0700
committerFranck Cuny <franck@fcuny.net>2024-04-28 19:17:12 -0700
commit58d0a9cb616e35daf115b8e1aa9f5b79e4a21a70 (patch)
tree87f0cb04b860048f70c2f90cf9ba9d7d5e7f2634 /packages/pizza
parentchore: update flake (diff)
downloadworld-58d0a9cb616e35daf115b8e1aa9f5b79e4a21a70.tar.gz
add a script to fetch cheeseboard's menu
Delete the version in go.
Diffstat (limited to 'packages/pizza')
-rw-r--r--packages/pizza/default.nix31
-rwxr-xr-xpackages/pizza/pizza.py58
2 files changed, 89 insertions, 0 deletions
diff --git a/packages/pizza/default.nix b/packages/pizza/default.nix
new file mode 100644
index 0000000..cf5e836
--- /dev/null
+++ b/packages/pizza/default.nix
@@ -0,0 +1,31 @@
+{ lib, python3 }:
+
+python3.pkgs.buildPythonApplication rec {
+  pname = "pizza";
+  src = ./pizza.py;
+  version = "0.1.0";
+  format = "other";
+
+  buildInputs = [ python3 ];
+  propagatedBuildInputs = with python3.pkgs; [
+    beautifulsoup4
+    prettytable
+    requests
+    termcolor
+  ];
+
+  dontUnpack = true;
+  dontBuild = true;
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp $src $out/bin/${pname}
+  '';
+
+  meta = with lib; {
+    description = "Get the pizza for the week for CheeseBoard.";
+    license = with licenses; [ mit ];
+    platforms = platforms.unix;
+    maintainers = with maintainers; [ fcuny ];
+  };
+}
diff --git a/packages/pizza/pizza.py b/packages/pizza/pizza.py
new file mode 100755
index 0000000..727d2af
--- /dev/null
+++ b/packages/pizza/pizza.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+from bs4 import BeautifulSoup
+import requests
+from prettytable import PrettyTable
+from textwrap import fill
+from termcolor import colored
+
+
+url = "https://cheeseboardcollective.coop/pizza/"
+
+content = requests.get(url)
+soup = BeautifulSoup(content.text, "html.parser")
+
+magic_ingredients = ["corn"]
+
+table = PrettyTable()
+table.field_names = ["date", "pizza"]
+table.align = "l"
+
+pizzas = soup.select(".pizza-list > article")
+for pizza in pizzas:
+    date_color = "white"
+    menu_color = "white"
+
+    date = pizza.find(class_="date").text
+
+    # the pizza is the 1st element, the 2nd is the salad, and i don't
+    # care about the salad :)
+    menu = (
+        pizza.select(".menu > p:nth-of-type(1)")[0]
+        .get_text(strip=True, separator="\n")
+        .split("\n")
+    )
+
+    if "closed" in menu[0]:
+        date_color = "red"
+
+    if "Parbake pizza is available" in menu[0]:
+        menu.pop(0)
+
+    if "Lunch from" in menu[0]:
+        menu.pop(0)
+
+    if "No hot pizza today" in menu[0]:
+        menu.pop(0)
+
+    final_menu = "".join(menu)
+
+    for ingredient in magic_ingredients:
+        if ingredient in final_menu:
+            menu_color = "yellow"
+
+    table.add_row(
+        [colored(date, date_color), fill(colored(final_menu, menu_color), width=80)]
+    )
+
+print(table)