Skip to content

Instantly share code, notes, and snippets.

@robfrawley
Last active July 3, 2023 00:28
Show Gist options
  • Save robfrawley/f6d164a3e7e9d5be9e287598fccc9364 to your computer and use it in GitHub Desktop.
Save robfrawley/f6d164a3e7e9d5be9e287598fccc9364 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
declare -a MATCHES_LIST=(
'garbage'
'junk'
'rubbush'
'drivel'
'trash'
'shit'
'unredeemable'
'worthless'
)
declare -a ARTICLE_LIST=(
'https://www.ign.com/articles/dave-the-diver-review'
'https://www.ign.com/articles/greyhill-incident-review'
'https://www.ign.com/articles/diablo-4-review'
'https://www.ign.com/articles/the-outlast-trials-early-access-review'
'https://www.ign.com/articles/dead-island-2-review'
'https://www.ign.com/articles/meet-your-maker-review'
'https://www.ign.com/articles/destiny-2-lightfall-review'
'https://www.ign.com/articles/hogwarts-legacy-review-harry-potter-ps5-xbox-pc'
'https://www.ign.com/articles/spongebob-squarepants-the-cosmic-shake-review'
'https://www.ign.com/articles/high-on-life-review'
'https://www.ign.com/articles/choo-choo-charles-review'
'https://www.ign.com/articles/goat-simulator-3-review'
'https://www.ign.com/articles/sonic-frontiers-review'
'https://www.ign.com/articles/ghostbusters-spirits-unleashed-review'
'https://www.ign.com/articles/gotham-knights-review'
'https://www.ign.com/articles/a-plague-tale-requiem-review'
'https://www.ign.com/articles/slime-rancher-2-review'
'https://www.ign.com/articles/grounded-review'
'https://www.ign.com/articles/disney-dreamlight-valley-review'
'https://www.ign.com/articles/steelrising-review'
'https://www.ign.com/articles/digimon-survive-review'
'https://www.ign.com/articles/xenoblade-chronicles-3-review'
'https://www.ign.com/articles/outriders-worldslayer-review'
'https://www.ign.com/articles/mario-strikers-battle-league-review'
'https://www.ign.com/articles/evil-dead-the-game-review'
'https://www.ign.com/articles/trek-to-yomi-review'
'https://www.ign.com/articles/postal-4-no-regerts-review'
'https://www.ign.com/articles/tiny-tinas-wonderlands-review-pc-xbox-playstation'
'https://www.ign.com/articles/destiny-2-the-witch-queen-review'
'https://www.ign.com/articles/crossfirex-multiplayer-review'
'https://www.ign.com/articles/crossfirex-single-player-review'
'https://www.ign.com/articles/far-cry-6-joseph-collapse-dlc-review'
'https://www.ign.com/articles/dying-light-2-stay-human-review'
'https://www.ign.com/articles/windjammers-2-review'
'https://www.ign.com/articles/praey-for-the-gods-review'
'https://www.ign.com/articles/century-age-of-ashes-review'
'https://www.ign.com/articles/nerf-legends-review'
'https://www.ign.com/articles/riders-republic-review'
'https://www.ign.com/articles/the-riftbreaker-review'
'https://www.ign.com/articles/world-war-z-aftermath-review'
'https://www.ign.com/articles/sable-review'
'https://www.ign.com/articles/i-am-fish-review'
'https://www.ign.com/articles/maneater-truth-quest-review'
'https://www.ign.com/articles/recompile-review'
'https://www.ign.com/articles/cris-tales-review'
'https://www.ign.com/articles/the-legend-of-zelda-skyward-sword-hd-review'
'https://www.ign.com/articles/dungeons-and-dragons-dark-alliance-review'
'https://www.ign.com/articles/griftlands-review'
'https://www.ign.com/articles/necromunda-hired-gun-review'
'https://www.ign.com/articles/hood-outlaws-legends-review'
'https://www.ign.com/articles/oddworld-soulstorm-review'
'https://www.ign.com/articles/skul-the-hero-slayer-review'
'https://www.ign.com/articles/destiny-2-beyond-light-review'
'https://www.ign.com/articles/pokemon-sword-and-shield-the-crown-tundra-dlc-review'
'https://www.ign.com/articles/genshin-impact-review'
'https://www.ign.com/articles/borderlands-3-psycho-krieg-and-the-fantastic-fustercluck-dlc-review'
'https://www.ign.com/articles/pokemon-sword-and-shield-the-isle-of-armor-dlc-review'
'https://www.ign.com/articles/xenoblade-chronicles-definitive-edition-review'
'https://www.ign.com/articles/cooking-mama-cookstar-review'
'https://www.ign.com/articles/borderlands-3-guns-love-and-tentacles-dlc-review'
'https://www.ign.com/articles/temtem-review'
'https://www.ign.com/articles/pokemon-mystery-dungeon-rescue-team-dx-review'
'https://www.ign.com/articles/2019/10/23/medievil-review-2'
'https://www.ign.com/articles/2019/10/09/destiny-2-shadowkeep-review'
'https://www.ign.com/articles/2019/09/14/no-mans-sky-beyond-review'
'https://www.ign.com/articles/2019/08/26/decay-of-logos-review'
)
function get_article_html() {
local link="${1}"
curl "${link}" \
-H 'authority: www.ign.com' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'cache-control: max-age=0' \
-H 'dnt: 1' \
-H 'sec-ch-ua: "Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Windows"' \
-H 'sec-fetch-dest: document' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-site: same-origin' \
-H 'sec-fetch-user: ?1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' \
--compressed \
--silent
}
function get_article_text() {
local link="${1}"
local html="$(
get_article_html "${link}" \
| tr '\n' ' '
)"
date -d "$(
sed -E 's/.+?Posted: <!-- -->([A-Za-z]+ [0-9]{1,2}, [0-9]{4} [0-9:]{4,5} (am|pm)).+/\1/g' <<< "${html}"
)" +'%Y-%m-%d @ %H:%M' 2> /dev/null || printf -- 'UNDEFINED DATETIME'
grep -oE '(<p class="[^"]+">[^<]+|<h1.+?data-cy="(article-headline|article-sub-headline)">[^<]+)' <<< "${html}" \
| sed -E 's/<h1.+?data-cy="article-headline">([^<]+)([^<]*IGN[^<]*)?<\/h1>/\1\n/g' \
| sed -E 's/ - IGN//g' \
| sed -E 's/<h2.+?data-cy="article-sub-headline">([^<]+)/\1/g' \
| sed -E 's/<[^>]*>/ /g' \
| sed -E 's/(^[ ]+|[ ]+$)//g' \
| sed -E 's/[ ]{2,}/ /g'
}
function main() {
local match_checks='('"${$(printf -- '%s|' "${(@v)MATCHES_LIST}"):0: -1}"')'
local -a results_list=()
local -a matches_list=()
local outputs_pads
local article_link
printf -- '#\n# Script source code link : "%s"\n# Checking %02d articles for words : %s\n#\n' \
'https://gist.github.com/robfrawley/f6d164a3e7e9d5be9e287598fccc9364' \
"${#ARTICLE_LIST[@]}" \
"${$(printf -- '"%s", ' "${(@v)MATCHES_LIST}"):0: -2}"
for link in "${(@)ARTICLE_LIST}"; do
results_list=("${(@f)$(get_article_text "${link}")}")
matches_list=()
article_link="$(sed -E 's/https?:\/\/(www\.)?//g' <<< "${link}")"
outputs_pads="$(($(tput cols) - $((${#results_list[1]} + ${#results_list[2]} + ${#article_link} + 22 + 22))))"
if [[ ${outputs_pads} -lt 0 ]]; then
results_list[2]="${results_list[2]:0:$((${#results_list[2]} + outputs_pads - 9))} [...]"
outputs_pads=3
fi
printf -- '\033[1;30m- [ "\033[0m\033[1;27m%s\033[1;30m" -> "\033[0m\033[1;27m%s\033[1;30m" ]( "\033[0m\033[1;30m%s\033[1;30m" )%*s' \
"${results_list[1]}" \
"${results_list[2]}" \
"${article_link}" \
"$((${outputs_pads} + 1))" \
"$(
for i in $(seq 1 "${outputs_pads}"); do
printf -- '•'
done
)"
for line in "${(@v)results_list}"; do
if grep -E "${match_checks}" <<< "${line}" &> /dev/null; then
matches_list+=("${line}")
fi
done
if [[ ${#matches_list[@]} -gt 0 ]]; then
printf -- " \033[0;37m-->\033[0m \033[0;41m[FOUND \033[1;41m%02d\033[0m\033[0;41m MATCHES]\033[0m" \
"${#matches_list[@]}"
for match in "${(@v)matches_list}"; do
printf -- '\n%s' "$(
fold -s -w "$(($(tput cols) - 4))" <<< "${match}" | sed -E 's/^/ > /g'
)" | grep --color=always -E "${match_checks}|$"
done
else
echo -e " \033[0;37m-->\033[0m \033[0;32m[FOUND \033[1;32mNO\033[0m\033[0;32m MATCHES]\033[0m"
fi
sleep 1
done
}
main "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment