Last active
September 15, 2021 19:12
-
-
Save purarue/dc9f4130b618cc41adb70746c9fcce73 to your computer and use it in GitHub Desktop.
Some codegen for the Jikan PHP constants https://github.com/jikan-me/jikan/blob/master/src/Helper/Constants.php#L117
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# pass 'manga' as the first arg to the script to scrape manga instead | |
# requires https://github.com/ericchiang/pup to be installed | |
sort_by_id() { | |
sort -n -t= -k 2 | |
} | |
scrape_type="${1:-anime}" | |
case "${scrape_type}" in | |
anime) | |
curl -s 'https://myanimelist.net/anime.php' | pup 'a[href*="/anime/genre/"] attr{href}' | awk 'BEGIN { FS = "/" } { sub("-", "_", $0); print "public const GENRE_ANIME_" toupper($5), "=", $4 ";" }' | sort_by_id | |
;; | |
manga) | |
curl -s 'https://myanimelist.net/manga.php' | pup 'a[href*="/manga/genre/"] attr{href}' | awk 'BEGIN { FS = "/" } { sub("-", "_", $0); print "public const GENRE_MANGA_" toupper($5), "=", $4 ";" }' | sort_by_id | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current output: