about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2024-05-04 13:27:23 -0700
committerFranck Cuny <franck@fcuny.net>2024-05-04 13:28:46 -0700
commit4a86b5122c3c1bfcf442a59287da809248406526 (patch)
tree4ab5ec2af31159284c36765a54981fd2ceb28991
parentadd a comment to set environment variables (diff)
downloadworld-4a86b5122c3c1bfcf442a59287da809248406526.tar.gz
start the conversion to python
Add support to move all the tools to python and organize them in a way
that should be simple.

I'm using https://rye-up.com for this.
-rw-r--r--.envrc1
-rw-r--r--.python-version1
-rwxr-xr-xpackages/pizza/pizza.py58
-rw-r--r--pyproject.toml67
-rw-r--r--requirements-dev.lock109
-rw-r--r--requirements.lock32
-rwxr-xr-xsrc/cli/pizza.py54
7 files changed, 264 insertions, 58 deletions
diff --git a/.envrc b/.envrc
index 3550a30..34e6b2a 100644
--- a/.envrc
+++ b/.envrc
@@ -1 +1,2 @@
 use flake
+source .venv/bin/activate
diff --git a/.python-version b/.python-version
new file mode 100644
index 0000000..871f80a
--- /dev/null
+++ b/.python-version
@@ -0,0 +1 @@
+3.12.3
diff --git a/packages/pizza/pizza.py b/packages/pizza/pizza.py
deleted file mode 100755
index 727d2af..0000000
--- a/packages/pizza/pizza.py
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/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)
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..7783aab
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,67 @@
+[project]
+name = "world"
+version = "0.1.0"
+description = "collection of tools and scripts"
+authors = [{ name = "Franck Cuny", email = "franck@fcuny.net" }]
+dependencies = [
+  "bs4>=0.0.2",
+  "requests>=2.31.0",
+  "prettytable>=3.10.0",
+  "termcolor>=2.4.0",
+]
+readme = "README.md"
+requires-python = ">= 3.8"
+
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
+[tool.rye]
+managed = true
+dev-dependencies = [
+  "python-lsp-server[all]>=1.11.0",
+  "python-lsp-ruff>=2.2.1",
+  "types-requests>=2.31.0.20240406",
+]
+
+[tool.hatch.metadata]
+allow-direct-references = true
+
+[tool.hatch.build.targets.wheel]
+packages = ["src/cli", "src/rbx_nomad"]
+
+[tool.ruff]
+line-length = 120
+
+[tool.ruff.format]
+docstring-code-format = true
+
+[tool.ruff.lint]
+select = [
+  # isort
+  "I",
+  # bugbear rules
+  "B",
+  # remove unused imports
+  "F401",
+  # bare except statements
+  "E722",
+  # unused arguments
+  "ARG",
+  # misuse of typing.TYPE_CHECKING
+  "TCH004",
+  # import rules
+  "TID251",
+]
+
+[tool.ruff.lint.pycodestyle]
+max-line-length = 120
+
+[tool.ruff.lint.isort]
+length-sort = true
+length-sort-straight = true
+combine-as-imports = true
+known-first-party = ["rbx_nomad"]
+
+[project.scripts]
+pizza = "cli.pizza:main"
diff --git a/requirements-dev.lock b/requirements-dev.lock
new file mode 100644
index 0000000..13ce373
--- /dev/null
+++ b/requirements-dev.lock
@@ -0,0 +1,109 @@
+# generated by rye
+# use `rye lock` or `rye sync` to update this lockfile
+#
+# last locked with the following flags:
+#   pre: false
+#   features: []
+#   all-features: false
+#   with-sources: false
+
+-e file:.
+astroid==3.1.0
+    # via pylint
+attrs==23.2.0
+    # via cattrs
+    # via lsprotocol
+autopep8==2.0.4
+    # via python-lsp-server
+beautifulsoup4==4.12.3
+    # via bs4
+bs4==0.0.2
+    # via world
+cattrs==23.2.3
+    # via lsprotocol
+    # via python-lsp-ruff
+certifi==2024.2.2
+    # via requests
+charset-normalizer==3.3.2
+    # via requests
+dill==0.3.8
+    # via pylint
+docstring-to-markdown==0.15
+    # via python-lsp-server
+flake8==7.0.0
+    # via python-lsp-server
+idna==3.7
+    # via requests
+importlib-metadata==7.1.0
+    # via yapf
+isort==5.13.2
+    # via pylint
+jedi==0.19.1
+    # via python-lsp-server
+lsprotocol==2023.0.1
+    # via python-lsp-ruff
+mccabe==0.7.0
+    # via flake8
+    # via pylint
+    # via python-lsp-server
+packaging==24.0
+    # via pytoolconfig
+parso==0.8.4
+    # via jedi
+platformdirs==4.2.1
+    # via pylint
+    # via pytoolconfig
+    # via yapf
+pluggy==1.5.0
+    # via python-lsp-server
+prettytable==3.10.0
+    # via world
+pycodestyle==2.11.1
+    # via autopep8
+    # via flake8
+    # via python-lsp-server
+pydocstyle==6.3.0
+    # via python-lsp-server
+pyflakes==3.2.0
+    # via flake8
+    # via python-lsp-server
+pylint==3.1.0
+    # via python-lsp-server
+python-lsp-jsonrpc==1.1.2
+    # via python-lsp-server
+python-lsp-ruff==2.2.1
+python-lsp-server==1.11.0
+    # via python-lsp-ruff
+pytoolconfig==1.3.1
+    # via rope
+requests==2.31.0
+    # via world
+rope==1.13.0
+    # via python-lsp-server
+ruff==0.4.3
+    # via python-lsp-ruff
+snowballstemmer==2.2.0
+    # via pydocstyle
+soupsieve==2.5
+    # via beautifulsoup4
+termcolor==2.4.0
+    # via world
+tomli==2.0.1
+    # via yapf
+tomlkit==0.12.4
+    # via pylint
+types-requests==2.31.0.20240406
+ujson==5.9.0
+    # via python-lsp-jsonrpc
+    # via python-lsp-server
+urllib3==2.2.1
+    # via requests
+    # via types-requests
+wcwidth==0.2.13
+    # via prettytable
+whatthepatch==1.0.5
+    # via python-lsp-server
+yapf==0.40.2
+    # via python-lsp-server
+zipp==3.18.1
+    # via importlib-metadata
diff --git a/requirements.lock b/requirements.lock
new file mode 100644
index 0000000..ff7b3b3
--- /dev/null
+++ b/requirements.lock
@@ -0,0 +1,32 @@
+# generated by rye
+# use `rye lock` or `rye sync` to update this lockfile
+#
+# last locked with the following flags:
+#   pre: false
+#   features: []
+#   all-features: false
+#   with-sources: false
+
+-e file:.
+beautifulsoup4==4.12.3
+    # via bs4
+bs4==0.0.2
+    # via world
+certifi==2024.2.2
+    # via requests
+charset-normalizer==3.3.2
+    # via requests
+idna==3.7
+    # via requests
+prettytable==3.10.0
+    # via world
+requests==2.31.0
+    # via world
+soupsieve==2.5
+    # via beautifulsoup4
+termcolor==2.4.0
+    # via world
+urllib3==2.2.1
+    # via requests
+wcwidth==0.2.13
+    # via prettytable
diff --git a/src/cli/pizza.py b/src/cli/pizza.py
new file mode 100755
index 0000000..d07abc8
--- /dev/null
+++ b/src/cli/pizza.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+
+from textwrap import fill
+
+import requests
+from bs4 import BeautifulSoup
+from termcolor import colored
+from prettytable import PrettyTable
+
+url = "https://cheeseboardcollective.coop/pizza/"
+
+
+def main():
+    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)