Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Download MTGO Vintage results from magic.wizards.com
- # Get script's directory
- ROOT=$(dirname $(readlink -f ${0}))
- # Store the date of the most recent results in the script's root
- DATE_FILE="${ROOT}/vintage-last-checked"
- # If ./last-checked exists, get the date of the last results. Otherwise,
- # don't restrict the search window. By default, this appears to return the
- # most recent 6 results.
- FROM_DATE=""
- [ -f ${DATE_FILE} ] && FROM_DATE=$(egrep "^[0-9/]{10}$" ${DATE_FILE})
- # URL definitions. Use magic.wizards.com for both searches and event links.
- URL_BASE="https://magic.wizards.com/en/"
- SEARCH_PATH="section-articles-see-more-ajax?l=en&f=9041&search-result-theme=&fromDate=${FROM_DATE}&word=Vintage"
- RESULT_PATH="articles/archive/mtgo-standings"
- # Query the recent tournament results. Clean up the output enough to extract
- # links. Sort them chronologically, ascending.
- #
- # Note: We must reverse the results manually intead of using the website's
- # search function because reversing the sort in the curl request returns results
- # from ~2014 if no fromDate is defined.
- SEARCH=$(curl -s "${URL_BASE}${SEARCH_PATH}" \
- | sed -r "s/\\\n/\n/g" \
- | egrep -o "href.*$" \
- | sed -r "s/^.*mtgo-standings(.+)\\.*$/\1/g" \
- | awk -F\\ '{print $2}' \
- | tr '\n' ' ' \
- | tac -rs' ')
- # Loop over the results. Extract the date from the end for later use, then
- # format the result as a link and print it.
- for S in ${SEARCH}; do
- D=$(echo "${S}" | egrep -o "[0-9-]{10}$")
- # Clean up the result: strip the leading '/', convert to proper case,
- # and replace dashes with spaces.
- T=$(echo "${S:0:-10}" | tr -d '/' | tr '-' ' ' | sed 's/[^ ]\+/\L\u&/g')
- echo "${T}${D}"
- done
- # Reformat the date of the last entry and save it to ${DATE_FILE}
- [ ! -z ${D} ] && date -d "${D}+1 day" "+%m/%d/%Y" > ${DATE_FILE} 2>/dev/null
Add Comment
Please, Sign In to add comment