Skip to main content

The Flickr scripts have graduated to their own repo

ID
70ae50a
date
2024-04-11 12:10:17+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
3290ce8
message
The Flickr scripts have graduated to their own repo
changed files
6 files, 3 additions, 222 deletions

Changed files

config.fish (6697) → config.fish (6590)

diff --git a/config.fish b/config.fish
index cce9a36..3b8883e 100644
--- a/config.fish
+++ b/config.fish
@@ -59,6 +59,8 @@ prepend_to_path ~/repos/scripts/terraform
 prepend_to_path ~/repos/scripts/text
 prepend_to_path ~/repos/scripts/web
 
+prepend_to_path ~/repos/flapi.sh
+
 # Paths for Ruby and bundler
 prepend_to_path /opt/homebrew/bin
 prepend_to_path /opt/homebrew/opt/ruby/bin
@@ -166,11 +168,8 @@ function __create_python_script_alias
     end
 end
 
-__create_bash_script_alias flickr/flapi.sh
-__create_bash_script_alias flickr/flphoto.sh
 __create_bash_script_alias text/pp_xml.sh
 
-__create_python_script_alias flickr/fluser_lookup.py
 __create_python_script_alias fs/emptydir.py
 __create_python_script_alias git/find_big_commits.py
 __create_python_script_alias git/git-cloc.py

flickr/README.md (2214) → flickr/README.md (989)

diff --git a/flickr/README.md b/flickr/README.md
index 2460709..2eae43a 100644
--- a/flickr/README.md
+++ b/flickr/README.md
@@ -23,24 +23,6 @@ scripts = [
         deploy a new version of a Flickr Foundation Python library: bump the version, tag the Git commit, push to PyPI and GitHub.
         """,
     },
-    {
-        "usage": "flapi.sh [METHOD] [PARAMS]",
-        "description": """
-        call a method with the Flickr API and print the XML response to stdout.
-        """,
-    },
-    {
-        "usage": "flphoto.sh [PHOTO_ID]",
-        "description": """
-        look up a single photo with the Flickr API and print the XML response to stdout.
-        """,
-    },
-    {
-        "usage": "fluser_lookup.py [USER_ID]",
-        "description": """
-        Look up a Flickr user by URL or path alias.
-        """,
-    },
 ]
 
 cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
@@ -55,32 +37,5 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
   <dd>
     deploy a new version of a Flickr Foundation Python library: bump the version, tag the Git commit, push to PyPI and GitHub.
   </dd>
-
-  <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/flickr/flapi.sh">
-      <code>flapi.sh [METHOD] [PARAMS]</code>
-    </a>
-  </dt>
-  <dd>
-    call a method with the Flickr API and print the XML response to stdout.
-  </dd>
-
-  <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/flickr/flphoto.sh">
-      <code>flphoto.sh [PHOTO_ID]</code>
-    </a>
-  </dt>
-  <dd>
-    look up a single photo with the Flickr API and print the XML response to stdout.
-  </dd>
-
-  <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/flickr/fluser_lookup.py">
-      <code>fluser_lookup.py [USER_ID]</code>
-    </a>
-  </dt>
-  <dd>
-    Look up a Flickr user by URL or path alias.
-  </dd>
 </dl>
-<!-- [[[end]]] (checksum: c6023a15d18d6ef6f489f55f8b032b9a) -->
+<!-- [[[end]]] (checksum: 25a2e0861d7f789ae830f7da3763f089) -->

flickr/flapi.sh (549) → flickr/flapi.sh (0)

diff --git a/flickr/flapi.sh b/flickr/flapi.sh
deleted file mode 100755
index 201c34e..0000000
--- a/flickr/flapi.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/env bash
-# A thin wrapper around the Flickr API.
-#
-# I use this to do quick inspection of API responses, e.g.
-#
-#     $ flapi flickr.photos.getInfo photo_id=52782497889
-#
-
-set -o errexit
-set -o nounset
-
-if (( $# == 1 ))
-then
-  method="$1"
-  params=""
-elif (( $# == 2 ))
-then
-  method="$1"
-  params="$2"
-else
-  echo "Usage: $0 <METHOD> <PARAMS>" >&2
-  exit 1
-fi
-
-api_key=$(keyring get flickr_api key)
-
-curl --silent "https://api.flickr.com/services/rest/?api_key=${api_key}&method=${method}&${params}" \
-  | ~/repos/scripts/text/pp_xml.sh

flickr/flphoto.sh (474) → flickr/flphoto.sh (0)

diff --git a/flickr/flphoto.sh b/flickr/flphoto.sh
deleted file mode 100755
index 854f508..0000000
--- a/flickr/flphoto.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/usr/bin/env bash
-
-set -o errexit
-set -o nounset
-
-if (( $# != 1 ))
-then
-  echo "Usage: $0 <PHOTO_ID>" >&2
-  exit 1
-fi
-
-PHOTO_ID="$1"
-
-if [[ "$PHOTO_ID" =~ ^[0-9]+$ ]]
-then
-  flapi.sh flickr.photos.getInfo photo_id=$PHOTO_ID
-else
-  PARSED_ID=$(flickr_url_parser "$PHOTO_ID" | jq -r .photo_id)
-
-  if [[ "$PARSED_ID" =~ ^[0-9]+$ ]]
-  then
-    flapi.sh flickr.photos.getInfo photo_id=$PARSED_ID
-  else
-    echo "I don't know how to interpret $PHOTO_ID" >&2
-    exit 1
-  fi
-fi

flickr/fluser_lookup.py (2242) → flickr/fluser_lookup.py (0)

diff --git a/flickr/fluser_lookup.py b/flickr/fluser_lookup.py
deleted file mode 100755
index 48c0f30..0000000
--- a/flickr/fluser_lookup.py
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/usr/bin/env python3
-"""
-Look up a user by URL or path alias.
-
-    $ fluser_lookup.py amymle
-    ID:       82621159@N00
-    username: amymle
-    realname: Amy Esau
-    profile:  https://www.flickr.com/people/amymle/
-    photos:   https://www.flickr.com/photos/amymle/
-
-"""
-
-import sys
-from typing import TypedDict
-
-from flickr_photos_api import FlickrPhotosApi
-from flickr_url_parser import is_flickr_user_id
-import hyperlink
-import keyring
-
-
-class PathAlias(TypedDict):
-    path_alias: str
-
-
-class UserId(TypedDict):
-    id: str
-
-
-def get_user_id(user_text: str) -> PathAlias | UserId:
-    # e.g. 35468159852@N01
-    if is_flickr_user_id(user_text):
-        return {"id": user_text}
-
-    u = hyperlink.URL.from_text(user_text)
-
-    # e.g. https://www.youtube.com/watch?v=0naRXbQQ838
-    if (
-        u.host == "commons.flickr.org"
-        and len(u.path) == 3
-        and u.path[0] == "members"
-        and u.path[2] == ""
-    ):
-        return {"path_alias": u.path[1]}
-
-    # e.g. "https://www.flickr.com/photos/35468159852@N01/"
-    # e.g. https://www.flickr.com/photos/powerhouse_museum/2532449275/
-    if (
-        u.host == "www.flickr.com"
-        and len(u.path) >= 2
-        and u.path[0] in {"photos", "people"}
-    ):
-        if is_flickr_user_id(u.path[1]):
-            return {"id": u.path[1]}
-        else:
-            return {"path_alias": u.path[1]}
-
-    raise ValueError(f"Cannot get Flickr user from {user_text!r}")
-
-
-if __name__ == "__main__":
-    try:
-        USER_TEXT = sys.argv[1]
-    except IndexError:
-        sys.exit(f"Usage: {__file__} <URL|PATH_ALIAS>")
-
-    api = FlickrPhotosApi(
-        api_key=keyring.get_password("flickr_api", "key"),
-        user_agent="Alex Chan's personal scripts <alex@alexwlchan.net>",
-    )
-
-    user_id = get_user_id(USER_TEXT)
-
-    if "path_alias" in user_id:
-        user = api.lookup_user_by_url(
-            url=f"https://www.flickr.com/people/{user_id['path_alias']}"
-        )
-    else:
-        user = api.lookup_user_by_id(user_id=user_id["id"])
-
-    print(f"ID:       {user['id']}")
-    print(f"username: {user['username']}")
-    print(f"realname: {user['realname'] or '<none>'}")
-    print(f"profile:  {user['profile_url']}")
-    print(f"photos:   {user['photos_url']}")

flickr/test_fluser_lookup.py (834) → flickr/test_fluser_lookup.py (0)

diff --git a/flickr/test_fluser_lookup.py b/flickr/test_fluser_lookup.py
deleted file mode 100644
index aaa623e..0000000
--- a/flickr/test_fluser_lookup.py
+++ /dev/null
@@ -1,32 +0,0 @@
-import pytest
-
-from fluser_lookup import get_user_id
-
-
-@pytest.mark.parametrize(
-    ["user_text", "user_id"],
-    [
-        (
-            "https://commons.flickr.org/members/csj_canada_archives/",
-            {"path_alias": "csj_canada_archives"},
-        ),
-        (
-            "https://www.flickr.com/photos/powerhouse_museum/2532449275/",
-            {"path_alias": "powerhouse_museum"},
-        ),
-        (
-            "https://www.flickr.com/people/alexwlchan/",
-            {"path_alias": "alexwlchan"},
-        ),
-        (
-            "35468159852@N01",
-            {"id": "35468159852@N01"},
-        ),
-        (
-            "https://www.flickr.com/photos/35468159852@N01/",
-            {"id": "35468159852@N01"},
-        ),
-    ],
-)
-def test_get_user_id(user_text, user_id):
-    assert get_user_id(user_text) == user_id