Created
January 5, 2015 08:15
-
-
Save naelstrof/7318b8ce46dda7576265 to your computer and use it in GitHub Desktop.
Takes a list of search terms as arguments, searches the Magic The Gathering database for an image related to each search term and downloads them.
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 | |
# Usage: ./mtgCardScraper.sh [search terms] | |
# Example: ./mtgCardScraper.sh "zombie" "angel" | |
# Searching for zombie.. | |
# Grabbed Zombie Apocalypse.jpg | |
# Searching for angel.. | |
# Grabbed Angel of Despair.jpg | |
# Please use responsibly. | |
for _arg in "$@"; do | |
_searchquery="${_arg// /+}" | |
echo "Searching for ${_searchquery}.." | |
_searchresults=`curl -q --request GET "http://gatherer.wizards.com/Handlers/InlineCardSearch.ashx?nameFragment=${_searchquery}"` | |
_cardname=`echo "${_searchresults}" | grep -Po '(?<="Name":")[^"]*' | head -1` | |
_cardid=`echo "${_searchresults}" | grep -Po '(?<="ID":")[^"]*' | head -1` | |
wget -q "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=${_cardid}&type=card" -O "/tmp/temp.jpg" | |
rm "/tmp/temp.jpg" | |
echo "Grabbed ${_cardname}.jpg" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment