Skip to main content

Remove a set of scripts I no longer use

ID
35dbca1
date
2025-05-23 21:28:49+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
a848c18
message
Remove a set of scripts I no longer use
changed files
9 files, 410 deletions

Changed files

textexpander/README.md (3465) → textexpander/README.md (0)

diff --git a/textexpander/README.md b/textexpander/README.md
deleted file mode 100644
index dbb19b3..0000000
--- a/textexpander/README.md
+++ /dev/null
@@ -1,120 +0,0 @@
-# textexpander
-
-These scripts I invoke as text expansion macros in [TextExpander](https://textexpander.com/).
-
-## The individual scripts
-
-<!-- [[[cog
-
-# This adds the root of the repo to the PATH, which has cog_helpers.py
-from os.path import abspath, dirname
-import sys
-
-sys.path.append(abspath(dirname(dirname("."))))
-
-import cog_helpers
-
-folder_name = "textexpander"
-
-scripts = [
-    {
-        "name": "copy_file_into_obsidian.py",
-        "description": """
-        get the latest download from my Desktop, copy it into Obsidian, and print a ![[…]] link to insert it into my current document.
-        """
-    },
-    {
-        "name": "create_books_commit_message",
-        "description": """
-        create a commit message for when I'm adding new books to my book tracker.
-        """
-    },
-    {
-        "name": "create_til_commit_message",
-        "description": """
-        create a commit message for when I'm updating my TIL (Today-I-Learned) repository.
-        """
-    },
-    {
-        "name": "get_markdown_link.py",
-        "description": """
-        print a reference-style Markdown link to my frontmost Safari URL
-        """,
-    },
-    {
-        "name": "get_mastodon_text.py",
-        "description": """
-        print a Markdown-formatted blockquote of a Mastodon I've got open in Safari, suitable for saving in Obsidian
-        """,
-    },
-    {
-        "name": "get_wikipedia_quote.py",
-        "description": """
-        get URL and first paragraph of a Wikipedia entry I have open in Safari, suitable for saving in Obsidian.
-        """,
-    },
-]
-
-cog_helpers.create_description_table(
-    folder_name=folder_name,
-    scripts=scripts,
-    ignore_files={"urls.py"}
-)
-
-]]]-->
-<dl>
-  <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/textexpander/copy_file_into_obsidian.py">
-      <code>copy_file_into_obsidian.py</code>
-    </a>
-  </dt>
-  <dd>
-    get the latest download from my Desktop, copy it into Obsidian, and print a ![[…]] link to insert it into my current document.
-  </dd>
-
-  <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/textexpander/create_books_commit_message">
-      <code>create_books_commit_message</code>
-    </a>
-  </dt>
-  <dd>
-    create a commit message for when I'm adding new books to my book tracker.
-  </dd>
-
-  <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/textexpander/create_til_commit_message">
-      <code>create_til_commit_message</code>
-    </a>
-  </dt>
-  <dd>
-    create a commit message for when I'm updating my TIL (Today-I-Learned) repository.
-  </dd>
-
-  <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/textexpander/get_markdown_link.py">
-      <code>get_markdown_link.py</code>
-    </a>
-  </dt>
-  <dd>
-    print a reference-style Markdown link to my frontmost Safari URL
-  </dd>
-
-  <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/textexpander/get_mastodon_text.py">
-      <code>get_mastodon_text.py</code>
-    </a>
-  </dt>
-  <dd>
-    print a Markdown-formatted blockquote of a Mastodon I've got open in Safari, suitable for saving in Obsidian
-  </dd>
-
-  <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/textexpander/get_wikipedia_quote.py">
-      <code>get_wikipedia_quote.py</code>
-    </a>
-  </dt>
-  <dd>
-    get URL and first paragraph of a Wikipedia entry I have open in Safari, suitable for saving in Obsidian.
-  </dd>
-</dl>
-<!-- [[[end]]] (checksum: 75dbd3e0c7b1be65eb5c169399792cc4) -->

textexpander/copy_file_into_obsidian.py (655) → textexpander/copy_file_into_obsidian.py (0)

diff --git a/textexpander/copy_file_into_obsidian.py b/textexpander/copy_file_into_obsidian.py
deleted file mode 100755
index b5cd0bd..0000000
--- a/textexpander/copy_file_into_obsidian.py
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/env python3
-
-import datetime
-import os
-import subprocess
-
-
-if __name__ == "__main__":
-    latest_download = (
-        subprocess.check_output(["/Users/alexwlchan/repos/scripts/fs/latest_download"])
-        .strip()
-        .decode("utf8")
-    )
-
-    name = os.path.basename(latest_download)
-
-    out_dir = os.path.join(
-        os.environ["HOME"],
-        "textfiles",
-        "Attachments",
-        str(datetime.datetime.now().year),
-    )
-
-    os.makedirs(out_dir, exist_ok=True)
-
-    out_path = os.path.join(out_dir, name)
-
-    assert not os.path.exists(out_path)
-
-    os.rename(latest_download, out_path)
-
-    print(f"![[{name}]]", end="")

textexpander/create_books_commit_message (620) → textexpander/create_books_commit_message (0)

diff --git a/textexpander/create_books_commit_message b/textexpander/create_books_commit_message
deleted file mode 100755
index e85c93a..0000000
--- a/textexpander/create_books_commit_message
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env bash
-# When I add an entry to my book tracker, I typically commit two files:
-#
-#   - the Markdown file containing my review
-#   - the image of the book's cover
-#
-# This script looks at the currently staged files, works out the title
-# of the book I just reviewed, and creates a commit message for my
-# Git commit.
-
-set -o errexit
-set -o nounset
-
-pushd ~/repos/books.alexwlchan.net >/dev/null
-    markdown_file=$(git diff --cached --name-only | grep ".md$" | head -n 1)
-    title=$(grep 'title:' "$markdown_file" | head -n 1 | sed 's/^ *title: *//')
-    echo -n "Add review for \"$title\""
-popd >/dev/null

textexpander/create_til_commit_message (441) → textexpander/create_til_commit_message (0)

diff --git a/textexpander/create_til_commit_message b/textexpander/create_til_commit_message
deleted file mode 100755
index fdeac19..0000000
--- a/textexpander/create_til_commit_message
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-# Create a commit message for my TIL (Today-I-Learned) repo.
-
-set -o errexit
-set -o nounset
-
-pushd ~/repos/til >/dev/null
-    markdown_file=$(git diff --cached --name-only | head -n 1)
-
-    title=$(grep 'title:' "$markdown_file" | sed 's/^title: //')
-
-    # Use printf rather than echo so it prints Unicode escapes,
-    # e.g. "that\342\200\231s" ~> "that’s"
-    printf "Add a new TIL: \"%b\"" "$title"
-popd >/dev/null

textexpander/get_markdown_link.py (1505) → textexpander/get_markdown_link.py (0)

diff --git a/textexpander/get_markdown_link.py b/textexpander/get_markdown_link.py
deleted file mode 100755
index bcf9258..0000000
--- a/textexpander/get_markdown_link.py
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/usr/bin/env python3
-"""
-Create a reference-style Markdown link to my frontmost Safari URL.
-
-This assumes I've already typed the link label, and it adds the reference.
-It tries to deduce a sensible name for the reference, or prompts for input
-if it can't pick one.
-"""
-
-import subprocess
-
-import hyperlink
-
-from get_safari_url import normalise_url
-from urls import get_safari_url
-
-
-def get_reference_label(url: str) -> str:
-    """
-    Get the reference label that should accompany this URL in the link.
-    """
-    u = hyperlink.DecodedURL.from_text(url)
-
-    # If it's a package on PyPI, the link label is the project name.
-    #
-    # e.g. "https://pypi.org/project/eyed3/" ~> "eyed3"
-    if u.host == "pypi.org" and len(u.path) >= 2 and u.path[0] == "project":
-        return u.path[1]
-
-    # If we can't deduce a default link name, prompt the user for input.
-    #
-    # Note: this seems to steal focus from the current app, prevent
-    # TextExpander from actually filling in the snippet.
-    # TODO: Investigate further!
-    cmd = [
-        "osascript",
-        "-e",
-        f"""
-        set theResponse to display dialog "The URL is {url}.\n\nWhat’s the link label?" default answer ""
-        get text returned of theResponse
-    """,
-    ]
-
-    label = subprocess.check_output(cmd).decode("utf8").strip()
-
-    return label
-
-
-if __name__ == "__main__":
-    url = get_safari_url()
-    url = normalise_url(url)
-
-    label = get_reference_label(url)
-
-    print(f"[{label}]\n\n[{label}]: {url}")

textexpander/get_mastodon_text.py (2679) → textexpander/get_mastodon_text.py (0)

diff --git a/textexpander/get_mastodon_text.py b/textexpander/get_mastodon_text.py
deleted file mode 100755
index 9a0c9dc..0000000
--- a/textexpander/get_mastodon_text.py
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/env python3
-"""
-Look at the Mastodon URL in the frontmost Safari window, and print it
-as a blockquote.
-"""
-
-import datetime
-import html
-import os
-from pathlib import Path
-import re
-import subprocess
-
-import httpx
-import hyperlink
-
-
-ATTACHMENTS_DIR = Path.home() / "textfiles" / "Attachments" / "mastodon"
-
-
-def download(url):
-    """
-    Download a file to the attachments directory, or do nothing if it's
-    already downloaded.
-    """
-    resp = httpx.get(url)
-    content = resp.content
-
-    ATTACHMENTS_DIR.mkdir(exist_ok=True)
-
-    out_path = ATTACHMENTS_DIR / os.path.basename(url)
-
-    try:
-        with open(out_path, "xb") as out_file:
-            out_file.write(content)
-    except FileExistsError:
-        if open(out_path, "rb").read() == content:
-            pass
-        else:
-            raise
-
-
-def normalise_text(text: str) -> str:
-    text = text.replace("</p><p>", "\n\n")
-    text = text.replace("<p>", "").replace("</p>", "")
-    text = text.replace("*", "\\*")
-    text = re.sub(
-        r'<a href="[^"]+" class="mention hashtag" rel="tag">#<span>(?P<hashtag>[^<]+)</span></a>',
-        r"\\#\g<hashtag>",
-        text,
-    )
-    text = re.sub(
-        r'<a href="(?P<url>[^"]+)" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">[^<]+</span><span class="ellipsis">[^<]+</span><span class="invisible">[^<]+</span></a>',
-        r"\g<url>",
-        text,
-    )
-    text = html.unescape(text)
-    return text
-
-
-if __name__ == "__main__":
-    url = subprocess.check_output(
-        ["osascript", "-e", 'tell application "Safari" to get URL of document 1']
-    ).decode("utf8")
-
-    u = hyperlink.URL.from_text(url)
-
-    # e.g. https://hachyderm.io/@djnavarro/111535929722933178
-    # ~>  https://hachyderm.io/api/v1/statuses/111535929722933178
-    api_url = f"https://{u.host}/api/v1/statuses/{u.path[1]}".strip()
-
-    resp = httpx.get(api_url)
-
-    post_data = resp.json()
-
-    for attachment in post_data["media_attachments"]:
-        download(attachment["url"])
-
-    author = post_data["account"]["display_name"]
-    post_url = post_data["url"]
-
-    # e.g. 2023-12-06T22:53:44.536Z
-    created_at = datetime.datetime.strptime(
-        post_data["created_at"], "%Y-%m-%dT%H:%M:%S.%fz"
-    )
-
-    print(f"[{author}]({post_url}) ({created_at.strftime('%-d %B %Y')}):")
-    print("")
-    for line in normalise_text(post_data["content"]).splitlines():
-        print(f"> {line}".strip())
-
-    if post_data["media_attachments"]:
-        print(">\n> ", end="")
-        for attachment in post_data["media_attachments"]:
-            print("![[%s|200]]" % os.path.basename(attachment["url"]), end="")
-
-    print("")

textexpander/get_wikipedia_quote.py (640) → textexpander/get_wikipedia_quote.py (0)

diff --git a/textexpander/get_wikipedia_quote.py b/textexpander/get_wikipedia_quote.py
deleted file mode 100755
index af05a73..0000000
--- a/textexpander/get_wikipedia_quote.py
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/python3
-"""
-Look at the Wikipedia URL in my frontmost browser window, and print
-a link with a quote of the first paragraph.
-"""
-
-import re
-
-import bs4
-import httpx
-
-from urls import get_safari_url
-
-
-if __name__ == "__main__":
-    url = get_safari_url()
-    assert "wikipedia.org" in url
-
-    resp = httpx.get(url)
-
-    soup = bs4.BeautifulSoup(resp.text, "html.parser")
-
-    title = soup.find("span", attrs={"class": "mw-page-title-main"}).text
-    text = re.sub(
-        r"\[\d+\]", "", soup.find("div", attrs={"id": "mw-content-text"}).find("p").text
-    )
-
-    print(f"[{title}]({url}):")
-    print("")
-    print(f"> {text}")

textexpander/test_get_mastodon_text.py (1481) → textexpander/test_get_mastodon_text.py (0)

diff --git a/textexpander/test_get_mastodon_text.py b/textexpander/test_get_mastodon_text.py
deleted file mode 100644
index a390a6e..0000000
--- a/textexpander/test_get_mastodon_text.py
+++ /dev/null
@@ -1,31 +0,0 @@
-import pytest
-
-from get_mastodon_text import normalise_text
-
-
-@pytest.mark.parametrize(
-    ["input", "output"],
-    [
-        (
-            "<p>A variation on the previous system for todays <a "
-            'href="https://hachyderm.io/tags/ArtAdventCalendar" class="mention '
-            'hashtag" rel="tag">#<span>ArtAdventCalendar</span></a> '
-            "contribution</p>",
-            "A variation on the previous system for todays \\#ArtAdventCalendar contribution",
-        ),
-        (
-            '<p>my rules for git rebase</p><p>permalink: <a href="https://wizardzines.com/comics/rules-for-rebasing/" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">wizardzines.com/comics/rules-f</span><span class="invisible">or-rebasing/</span></a></p>',
-            "my rules for git rebase\n\npermalink: https://wizardzines.com/comics/rules-for-rebasing/",
-        ),
-        (
-            "I realize it&#39;s (comparatively) super easy to set up",
-            "I realize it's (comparatively) super easy to set up",
-        ),
-        (
-            'The "this site is faster in the app" prompts have the benefit of truth *because they broke the website with React*',
-            'The "this site is faster in the app" prompts have the benefit of truth \*because they broke the website with React\*',
-        ),
-    ],
-)
-def test_normalise_text(input, output):
-    assert normalise_text(input) == output

textexpander/urls.py (277) → textexpander/urls.py (0)

diff --git a/textexpander/urls.py b/textexpander/urls.py
deleted file mode 100644
index e9f1fc5..0000000
--- a/textexpander/urls.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import subprocess
-
-
-def get_safari_url(window: int = 1) -> str:
-    """
-    Get the URL of the given Safari window.
-    """
-    cmd = ["/Users/alexwlchan/.cargo/bin/safari", "url", "--window", str(window)]
-
-    url = subprocess.check_output(cmd).decode("utf8")
-
-    return url