From d54fd73e5398bf6ce5bc596c53aa30f3e631b11a Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 8 Apr 2026 23:51:21 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20black-ify=20the=20code=20base?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 0_get_recipes.py | 2 +- 1_clean_json.py | 4 ++- 2_to_markdown.py | 1 - 4_post_to_wiki.py | 5 +-- fruehstueck.py | 37 +++++++++++++------ pyproject.toml | 5 +++ report_allergene.py | 5 +-- requirements-dev.txt | 1 - uv.lock | 85 ++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 126 insertions(+), 19 deletions(-) delete mode 100644 requirements-dev.txt diff --git a/0_get_recipes.py b/0_get_recipes.py index 72f2346..ed550ad 100644 --- a/0_get_recipes.py +++ b/0_get_recipes.py @@ -81,7 +81,7 @@ def fetch_recipe(recipe_id): params = {} response = requests.get( - f"{TANDOOR_URL}{endpoint}{recipe_id}/", params=params, headers=headers + f"{TANDOOR_URL}{endpoint}{recipe_id}/", params=params, headers=headers ) if response.status_code != 200: diff --git a/1_clean_json.py b/1_clean_json.py index a557d97..52d4ff3 100644 --- a/1_clean_json.py +++ b/1_clean_json.py @@ -20,7 +20,9 @@ def clean_recipe(recipe): recipe.pop("food_properties", None) for step in recipe["steps"]: for ingredient in step["ingredients"]: - ingredient["conversions"] = sorted(ingredient["conversions"], key=lambda c: c["unit"]) + ingredient["conversions"] = sorted( + ingredient["conversions"], key=lambda c: c["unit"] + ) return recipe diff --git a/2_to_markdown.py b/2_to_markdown.py index c74827d..594de27 100644 --- a/2_to_markdown.py +++ b/2_to_markdown.py @@ -9,7 +9,6 @@ from tqdm import tqdm from config import * - include_title = False diff --git a/4_post_to_wiki.py b/4_post_to_wiki.py index 2cb353d..a5b231a 100644 --- a/4_post_to_wiki.py +++ b/4_post_to_wiki.py @@ -18,7 +18,7 @@ site.login(WIKI_USERNAME, WIKI_PASSWORD) @click.command() -@click.argument('files', nargs=-1) +@click.argument("files", nargs=-1) def post(files): if files[0] == "all": files = [] @@ -47,6 +47,7 @@ def post(files): if __name__ == "__main__": if WIKI_DEFUSE: - print("Abort, wiki posting defused."); sys.exit(1) + print("Abort, wiki posting defused.") + sys.exit(1) else: post() diff --git a/fruehstueck.py b/fruehstueck.py index 9a4a134..a28673a 100644 --- a/fruehstueck.py +++ b/fruehstueck.py @@ -17,7 +17,7 @@ def grams(ingredient): if c["unit"] in ["g / Gramm", "g"]: conversion = c if conversion: - return conversion.get('amount') + return conversion.get("amount") def allergens_for_step_ingredients(step): @@ -50,6 +50,7 @@ def allergens_for_recipe(recipe): def link(recipe): return f"{TANDOOR_URL + "/view/recipe/" + str(recipe["id"])}" + def wiki_link(recipe): wiki_slug = recipe["name"] wiki_slug = re.sub(" ", "_", wiki_slug) @@ -84,10 +85,20 @@ def main(): recipes.sort(key=lambda r: r["name"]) # filter "Frühstück" - recipes = [r for r in recipes if any(k["name"] == "Fr\u00fchst\u00fcck" for k in r["keywords"])] + recipes = [ + r + for r in recipes + if any(k["name"] == "Fr\u00fchst\u00fcck" for k in r["keywords"]) + ] with open("fruehstueck.csv", "w", newline="") as f: - fwriter = csv.writer(f, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL, lineterminator="\n") + fwriter = csv.writer( + f, + delimiter=";", + quotechar='"', + quoting=csv.QUOTE_MINIMAL, + lineterminator="\n", + ) fwriter.writerow(["title", "url", "isVegan", "ingredients", "comment"]) for recipe in recipes: @@ -98,7 +109,9 @@ def main(): zn = decruft_ingredient(i_name) if i_allergens != "(keine)": - i_allergens = i_allergens.replace("⁉\ufe0f", "\\faExclamationTriangle") + i_allergens = i_allergens.replace( + "⁉\ufe0f", "\\faExclamationTriangle" + ) zn += f" (\\Alg{{{i_allergens}}})" zutaten.append((i_grams, zn)) @@ -106,13 +119,15 @@ def main(): zutaten = aggregate_zutaten(zutaten) zutaten.sort(key=lambda z: z[0], reverse=True) - fwriter.writerow([ - recipe["name"], - wiki_link(recipe), - 1, # XXX hardcoded - ", ".join(z[1] for z in zutaten), - "" - ]) + fwriter.writerow( + [ + recipe["name"], + wiki_link(recipe), + 1, # XXX hardcoded + ", ".join(z[1] for z in zutaten), + "", + ] + ) if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index f799fb6..8260983 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,3 +11,8 @@ dependencies = [ "requests>=2.33.1", "tqdm>=4.67.3", ] + +[dependency-groups] +dev = [ + "black>=26.3.1", +] diff --git a/report_allergene.py b/report_allergene.py index 2323be5..2e56cff 100644 --- a/report_allergene.py +++ b/report_allergene.py @@ -9,8 +9,6 @@ from tqdm import tqdm from config import * - - def allergens_for_step_ingredients(step): l = [] for ingredient in step["ingredients"]: @@ -40,6 +38,7 @@ def allergens_for_recipe(recipe): def link(recipe): return f"{TANDOOR_URL + "/view/recipe/" + str(recipe["id"])}" + def wiki_link(recipe): wiki_slug = recipe["name"] wiki_slug = re.sub(" ", "_", wiki_slug) @@ -54,6 +53,7 @@ def decruft_ingredient(i_name: str): i_name = i_name.replace(" (getrocknet)", "") return i_name + def main(): Path("report_allergene_korrektur.csv").unlink(missing_ok=True) @@ -90,5 +90,6 @@ def main(): f.write(zutaten + "\n") f.write("\n\n\n") + if __name__ == "__main__": main() diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 7e66a17..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1 +0,0 @@ -black diff --git a/uv.lock b/uv.lock index 46db599..36dcab1 100644 --- a/uv.lock +++ b/uv.lock @@ -2,6 +2,28 @@ version = 1 revision = 3 requires-python = ">=3.14" +[[package]] +name = "black" +version = "26.3.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "click" }, + { name = "mypy-extensions" }, + { name = "packaging" }, + { name = "pathspec" }, + { name = "platformdirs" }, + { name = "pytokens" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/e1/c5/61175d618685d42b005847464b8fb4743a67b1b8fdb75e50e5a96c31a27a/black-26.3.1.tar.gz", hash = "sha256:2c50f5063a9641c7eed7795014ba37b0f5fa227f3d408b968936e24bc0566b07", size = 666155, upload-time = "2026-03-12T03:36:03.593Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d5/da/e36e27c9cebc1311b7579210df6f1c86e50f2d7143ae4fcf8a5017dc8809/black-26.3.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:2d6bfaf7fd0993b420bed691f20f9492d53ce9a2bcccea4b797d34e947318a78", size = 1889234, upload-time = "2026-03-12T03:40:30.964Z" }, + { url = "https://files.pythonhosted.org/packages/0e/7b/9871acf393f64a5fa33668c19350ca87177b181f44bb3d0c33b2d534f22c/black-26.3.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:f89f2ab047c76a9c03f78d0d66ca519e389519902fa27e7a91117ef7611c0568", size = 1720522, upload-time = "2026-03-12T03:40:32.346Z" }, + { url = "https://files.pythonhosted.org/packages/03/87/e766c7f2e90c07fb7586cc787c9ae6462b1eedab390191f2b7fc7f6170a9/black-26.3.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b07fc0dab849d24a80a29cfab8d8a19187d1c4685d8a5e6385a5ce323c1f015f", size = 1787824, upload-time = "2026-03-12T03:40:33.636Z" }, + { url = "https://files.pythonhosted.org/packages/ac/94/2424338fb2d1875e9e83eed4c8e9c67f6905ec25afd826a911aea2b02535/black-26.3.1-cp314-cp314-win_amd64.whl", hash = "sha256:0126ae5b7c09957da2bdbd91a9ba1207453feada9e9fe51992848658c6c8e01c", size = 1445855, upload-time = "2026-03-12T03:40:35.442Z" }, + { url = "https://files.pythonhosted.org/packages/86/43/0c3338bd928afb8ee7471f1a4eec3bdbe2245ccb4a646092a222e8669840/black-26.3.1-cp314-cp314-win_arm64.whl", hash = "sha256:92c0ec1f2cc149551a2b7b47efc32c866406b6891b0ee4625e95967c8f4acfb1", size = 1258109, upload-time = "2026-03-12T03:40:36.832Z" }, + { url = "https://files.pythonhosted.org/packages/8e/0d/52d98722666d6fc6c3dd4c76df339501d6efd40e0ff95e6186a7b7f0befd/black-26.3.1-py3-none-any.whl", hash = "sha256:2bd5aa94fc267d38bb21a70d7410a89f1a1d318841855f698746f8e7f51acd1b", size = 207542, upload-time = "2026-03-12T03:36:01.668Z" }, +] + [[package]] name = "certifi" version = "2026.2.25" @@ -85,6 +107,11 @@ dependencies = [ { name = "tqdm" }, ] +[package.dev-dependencies] +dev = [ + { name = "black" }, +] + [package.metadata] requires-dist = [ { name = "click", specifier = ">=8.3.2" }, @@ -94,6 +121,9 @@ requires-dist = [ { name = "tqdm", specifier = ">=4.67.3" }, ] +[package.metadata.requires-dev] +dev = [{ name = "black", specifier = ">=26.3.1" }] + [[package]] name = "idna" version = "3.11" @@ -115,6 +145,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b0/ad/2bf4551a9f9c5c360b990ce6119edd717e0f28bb332a71921f4aa52889dc/mwclient-0.11.0-py3-none-any.whl", hash = "sha256:27914a307cb4539fd49a16d634c9c777c0de0976b3af9225bd95d4657bfd4d74", size = 33274, upload-time = "2024-08-12T09:08:13Z" }, ] +[[package]] +name = "mypy-extensions" +version = "1.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/a2/6e/371856a3fb9d31ca8dac321cda606860fa4548858c0cc45d9d1d4ca2628b/mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558", size = 6343, upload-time = "2025-04-22T14:54:24.164Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/79/7b/2c79738432f5c924bef5071f933bcc9efd0473bac3b4aa584a6f7c1c8df8/mypy_extensions-1.1.0-py3-none-any.whl", hash = "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505", size = 4963, upload-time = "2025-04-22T14:54:22.983Z" }, +] + [[package]] name = "oauthlib" version = "3.3.1" @@ -124,6 +163,24 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/be/9c/92789c596b8df838baa98fa71844d84283302f7604ed565dafe5a6b5041a/oauthlib-3.3.1-py3-none-any.whl", hash = "sha256:88119c938d2b8fb88561af5f6ee0eec8cc8d552b7bb1f712743136eb7523b7a1", size = 160065, upload-time = "2025-06-19T22:48:06.508Z" }, ] +[[package]] +name = "packaging" +version = "26.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/65/ee/299d360cdc32edc7d2cf530f3accf79c4fca01e96ffc950d8a52213bd8e4/packaging-26.0.tar.gz", hash = "sha256:00243ae351a257117b6a241061796684b084ed1c516a08c48a3f7e147a9d80b4", size = 143416, upload-time = "2026-01-21T20:50:39.064Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b7/b9/c538f279a4e237a006a2c98387d081e9eb060d203d8ed34467cc0f0b9b53/packaging-26.0-py3-none-any.whl", hash = "sha256:b36f1fef9334a5588b4166f8bcd26a14e521f2b55e6b9de3aaa80d3ff7a37529", size = 74366, upload-time = "2026-01-21T20:50:37.788Z" }, +] + +[[package]] +name = "pathspec" +version = "1.0.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/fa/36/e27608899f9b8d4dff0617b2d9ab17ca5608956ca44461ac14ac48b44015/pathspec-1.0.4.tar.gz", hash = "sha256:0210e2ae8a21a9137c0d470578cb0e595af87edaa6ebf12ff176f14a02e0e645", size = 131200, upload-time = "2026-01-27T03:59:46.938Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ef/3c/2c197d226f9ea224a9ab8d197933f9da0ae0aac5b6e0f884e2b8d9c8e9f7/pathspec-1.0.4-py3-none-any.whl", hash = "sha256:fb6ae2fd4e7c921a165808a552060e722767cfa526f99ca5156ed2ce45a5c723", size = 55206, upload-time = "2026-01-27T03:59:45.137Z" }, +] + [[package]] name = "pathvalidate" version = "3.3.1" @@ -133,6 +190,34 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/9a/70/875f4a23bfc4731703a5835487d0d2fb999031bd415e7d17c0ae615c18b7/pathvalidate-3.3.1-py3-none-any.whl", hash = "sha256:5263baab691f8e1af96092fa5137ee17df5bdfbd6cff1fcac4d6ef4bc2e1735f", size = 24305, upload-time = "2025-06-15T09:07:19.117Z" }, ] +[[package]] +name = "platformdirs" +version = "4.9.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/19/56/8d4c30c8a1d07013911a8fdbd8f89440ef9f08d07a1b50ab8ca8be5a20f9/platformdirs-4.9.4.tar.gz", hash = "sha256:1ec356301b7dc906d83f371c8f487070e99d3ccf9e501686456394622a01a934", size = 28737, upload-time = "2026-03-05T18:34:13.271Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/63/d7/97f7e3a6abb67d8080dd406fd4df842c2be0efaf712d1c899c32a075027c/platformdirs-4.9.4-py3-none-any.whl", hash = "sha256:68a9a4619a666ea6439f2ff250c12a853cd1cbd5158d258bd824a7df6be2f868", size = 21216, upload-time = "2026-03-05T18:34:12.172Z" }, +] + +[[package]] +name = "pytokens" +version = "0.4.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/b6/34/b4e015b99031667a7b960f888889c5bd34ef585c85e1cb56a594b92836ac/pytokens-0.4.1.tar.gz", hash = "sha256:292052fe80923aae2260c073f822ceba21f3872ced9a68bb7953b348e561179a", size = 23015, upload-time = "2026-01-30T01:03:45.924Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/8f/a7/b470f672e6fc5fee0a01d9e75005a0e617e162381974213a945fcd274843/pytokens-0.4.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:4a14d5f5fc78ce85e426aa159489e2d5961acf0e47575e08f35584009178e321", size = 160821, upload-time = "2026-01-30T01:03:19.684Z" }, + { url = "https://files.pythonhosted.org/packages/80/98/e83a36fe8d170c911f864bfded690d2542bfcfacb9c649d11a9e6eb9dc41/pytokens-0.4.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:97f50fd18543be72da51dd505e2ed20d2228c74e0464e4262e4899797803d7fa", size = 254263, upload-time = "2026-01-30T01:03:20.834Z" }, + { url = "https://files.pythonhosted.org/packages/0f/95/70d7041273890f9f97a24234c00b746e8da86df462620194cef1d411ddeb/pytokens-0.4.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:dc74c035f9bfca0255c1af77ddd2d6ae8419012805453e4b0e7513e17904545d", size = 268071, upload-time = "2026-01-30T01:03:21.888Z" }, + { url = "https://files.pythonhosted.org/packages/da/79/76e6d09ae19c99404656d7db9c35dfd20f2086f3eb6ecb496b5b31163bad/pytokens-0.4.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:f66a6bbe741bd431f6d741e617e0f39ec7257ca1f89089593479347cc4d13324", size = 271716, upload-time = "2026-01-30T01:03:23.633Z" }, + { url = "https://files.pythonhosted.org/packages/79/37/482e55fa1602e0a7ff012661d8c946bafdc05e480ea5a32f4f7e336d4aa9/pytokens-0.4.1-cp314-cp314-win_amd64.whl", hash = "sha256:b35d7e5ad269804f6697727702da3c517bb8a5228afa450ab0fa787732055fc9", size = 104539, upload-time = "2026-01-30T01:03:24.788Z" }, + { url = "https://files.pythonhosted.org/packages/30/e8/20e7db907c23f3d63b0be3b8a4fd1927f6da2395f5bcc7f72242bb963dfe/pytokens-0.4.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:8fcb9ba3709ff77e77f1c7022ff11d13553f3c30299a9fe246a166903e9091eb", size = 168474, upload-time = "2026-01-30T01:03:26.428Z" }, + { url = "https://files.pythonhosted.org/packages/d6/81/88a95ee9fafdd8f5f3452107748fd04c24930d500b9aba9738f3ade642cc/pytokens-0.4.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:79fc6b8699564e1f9b521582c35435f1bd32dd06822322ec44afdeba666d8cb3", size = 290473, upload-time = "2026-01-30T01:03:27.415Z" }, + { url = "https://files.pythonhosted.org/packages/cf/35/3aa899645e29b6375b4aed9f8d21df219e7c958c4c186b465e42ee0a06bf/pytokens-0.4.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d31b97b3de0f61571a124a00ffe9a81fb9939146c122c11060725bd5aea79975", size = 303485, upload-time = "2026-01-30T01:03:28.558Z" }, + { url = "https://files.pythonhosted.org/packages/52/a0/07907b6ff512674d9b201859f7d212298c44933633c946703a20c25e9d81/pytokens-0.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:967cf6e3fd4adf7de8fc73cd3043754ae79c36475c1c11d514fc72cf5490094a", size = 306698, upload-time = "2026-01-30T01:03:29.653Z" }, + { url = "https://files.pythonhosted.org/packages/39/2a/cbbf9250020a4a8dd53ba83a46c097b69e5eb49dd14e708f496f548c6612/pytokens-0.4.1-cp314-cp314t-win_amd64.whl", hash = "sha256:584c80c24b078eec1e227079d56dc22ff755e0ba8654d8383b2c549107528918", size = 116287, upload-time = "2026-01-30T01:03:30.912Z" }, + { url = "https://files.pythonhosted.org/packages/c6/78/397db326746f0a342855b81216ae1f0a32965deccfd7c830a2dbc66d2483/pytokens-0.4.1-py3-none-any.whl", hash = "sha256:26cef14744a8385f35d0e095dc8b3a7583f6c953c2e3d269c7f82484bf5ad2de", size = 13729, upload-time = "2026-01-30T01:03:45.029Z" }, +] + [[package]] name = "requests" version = "2.33.1"