Instantly share code, notes, and snippets.
Last active
November 8, 2015 23:37
-
Star
1
(1)
You must be signed in to star a gist -
Fork
1
(1)
You must be signed in to fork a gist
-
Save Grogdor/61a547b85879f896a0c2 to your computer and use it in GitHub Desktop.
TeamSpeak banner with upcoming CW battles
This file contains hidden or 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/sh | |
# | |
# Copyright (c) 2015, Grogdor. | |
# All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions | |
# are met: | |
# 1. Redistributions of source code must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. | |
# 2. Redistributions in binary form must reproduce the above copyright | |
# notice, this list of conditions and the following disclaimer in the | |
# documentation and/or other materials provided with the distribution. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
# SUCH DAMAGE. | |
# | |
# | |
# | |
######### https://gist.github.com/Grogdor/61a547b85879f896a0c2 ######### | |
# | |
# REQUIRES: curl, jq, lib-gd AKA gd-devel (or full PHP-gd?), fly (command-line gd processor) | |
# | |
# CONFIG: appID: replace "demo" (resource-limited) with your own app or server ID | |
# from https://na.wargaming.net/developers/applications/ (or eu/ru/asia) | |
# | |
# TZ: set display timezone, be sure to use proper format | |
# | |
# USAGE: ./tsBattleBanner.sh clanID [clanID2 .. clanID9] | |
# Get clanID from website, ie. http://na.wargaming.net/clans/0000000000 | |
# | |
# OUTPUT: clanID.png battles for each clan | |
# battles.png with battles for clans, in order specified | |
# | |
# EXAMPLE: http://i.imgur.com/7BT8SDK.png | |
# | |
# CRON: (crontab example that updates more often during primetime, remember timezone) | |
# | |
# TODO: Pre-pend a clan alliance header.png | |
# Get more/accurate information about landing tournaments (API methods exist) | |
# For EU region use https://api.worldoftanks.eu ... sea, ru | |
# | |
# Fix problem with string format sent to fly/gd, where extended characters | |
# aren't displayed properly: jq can output utf8 or \0xaabb and gd allegedly | |
# takes htmlentities? In the meantime, just don't output $province (API call | |
# is still needed to check clan map) | |
# | |
# gd/fly absolutely mangles the color palette | |
# gl/fly cannot convert png emblems to jpeg/gif/truecolor | |
# | |
############################################################################ | |
appID=demo | |
export TZ=EST | |
overall=0 | |
height=0 | |
PNGtemp="new | |
size 300,1000 | |
type png | |
name temp.png | |
#transparent 255,255,255 | |
fill 0,0,255,255,255" | |
echo "${PNGtemp}" | fly | |
for i in "$@" | |
do | |
### is clanInfo only needed for the tag/emblem now? | |
### if emblems exist, can we skip this API request and use emblem filename for tag? | |
### would need clanID in filename as well, lots of logic/grep to save one API call? | |
### clanTag can start with - or _ but $i.$tag would bypass those issues? | |
clanInfo="$(curl -s "https://api.worldoftanks.com/wgn/clans/info/?application_id=${appID}&clan_id=${i}")" | |
clanTag="$(echo "${clanInfo}" | jq -r ".data.\"${i}\".tag")" | |
emblemFilename="${clanTag}.emblem_32x32.png" | |
clanProvinces="$(curl -s "https://api.worldoftanks.com/wot/globalwar/clanprovinces/?application_id=${appID}&clan_id=${i}")" | |
clanMap="$(echo "${clanProvinces}" | jq -r ".data.\"${i}\".map_id")" | |
if [ ! -f "${emblemFilename}" ]; then | |
emblemURL="$(echo "${clanInfo}" | jq -r ".data.\"${i}\".emblems.x32.portal")" | |
curl -s -o "${emblemFilename}" "${emblemURL}" | |
fi | |
battles="$(curl -s "https://api.worldoftanks.com/wot/globalwar/battles/?application_id=${appID}&map_id=${clanMap}&clan_id=${i}")" | |
numBattles="$(echo "${battles}" | jq ".data.\"${i}\" | length")" | |
overall="$((overall+height))" | |
height="$((40+numBattles*20))" | |
PNGheader="new | |
size 300,${height} | |
type png | |
name ${i}.png | |
#transparent 255,255,255 | |
fill 0,0,255,255,255 | |
copy 5,5,0,0,32,32,${emblemFilename} | |
string 255,0,0,44,16,small,[${clanTag}]" | |
PNGstring=" | |
" | |
battlePointer=0 | |
while [ "${battlePointer}" -lt "${numBattles}" ] | |
do | |
# province="$(echo "${battles}" | jq -r ".data.\"${i}\"[${battlePointer}].provinces_i18n[0].name_i18n")" | |
### - sometimes multiple/optional arenas in this array? | |
map="$(echo "${battles}" | jq -r ".data.\"${i}\"[${battlePointer}].arenas[0].name_i18n")" | |
# type="$(echo "${battles}" | jq -r ".data.\"${i}\"[${battlePointer}].type")" | |
battleTime="$(echo "${battles}" | jq -r ".data.\"${i}\"[${battlePointer}].time")" | |
if [ "${battleTime}" -eq 0 ]; | |
### landing tournaments, how do they work? | |
### can pull starting time.. applied clans.. current bracket times after turn? | |
then time="--:--" | |
else | |
if [ "$(uname -s)" = "FreeBSD" ]; then | |
time="$(date -r "${battleTime}" +%H:%M)" | |
elif [ "$(uname -s)" = "Linux" ]; then | |
time="$(date -d @"${battleTime}" +%H:%M)" | |
else | |
time="date() error" | |
fi | |
fi | |
y="$((40+battlePointer*20))" | |
PNGstring="${PNGstring}string 255,0,0,10,${y},small,${time} ${map} | |
" | |
battlePointer="$((battlePointer+1))" | |
done | |
echo "${PNGheader} ${PNGstring}" | fly | |
PNGcopy="existing temp.png | |
name temp.png | |
type png | |
copy 0,${overall},-1,-1,-1,-1,${i}.png" | |
echo "${PNGcopy}" | fly | |
done | |
all="$((overall+height))" | |
PNGbattles="new | |
size 300,${all} | |
type png | |
name battles.png | |
copy 0,0,-1,-1,-1,-1,temp.png" | |
echo "${PNGbattles}" | fly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
I can't install fly because that library is too old and fail with lttf on make
How you install it...?