From c688a46f74f12b565da07455da3299546ed88b3a Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Wed, 4 Feb 2015 20:06:09 +0100 Subject: [PATCH] import from profile share --- image | 175 -------------------------------------------- index | 16 ++--- lib/image | 179 ++++++++++++++++++++++++++++++++++++++++++++++ lib/import_images | 29 ++++++++ lib/readlast | 1 + 5 files changed, 213 insertions(+), 187 deletions(-) delete mode 100755 image create mode 100755 lib/image create mode 100644 lib/import_images diff --git a/image b/image deleted file mode 100755 index e71b43e..0000000 --- a/image +++ /dev/null @@ -1,175 +0,0 @@ -#!/bin/bash - -source settings -for file in lib/* -do - source $file -done - -declare -A values - -#for indice in ${!uinames[@]} -#do -# uitods[$indice]="${uinames[$indice]}" -#done - -tmpfile=$(mktemp --suffix=.png) -convert -contrast "$1" "$tmpfile" -readarray -t tactout < <(tesseract -l eng -psm 4 "$tmpfile" stdout) -rm "$tmpfile" - -for line in "${tactout[@]}" -do - case "$line" in - #14,522,411 AP 144mm AP - *' AP'*) - read value junk <<<"$line" - values[AP]=${value//,/} - ;; - #Unique Portals Visited 718 - 'Unique Portals Visited'*) - value="${line#Unique Portals Visited }" - read values[Explorer] junk <<<"${value//,}" - ;; - #Portals Discovered 9 - 'Portals Discovered'*) - value="${line#Portals Discovered }" - read values[Seer] junk <<<"${value//,/}" - ;; - #XM Collected 130,908,527 XM - 'XM Collected'*) - value="${line#XM Collected}" - read values[XM] junk <<<"${value//,/}" - ;; - #Distance Walked 1,785 km - 'Distance Walked'*) - value="${line#Distance Walked }" - read values[Walked] junk <<<"${value//,/}" - ;; - #Resonators Deployed 24,451 - 'Resonators Deployed'*) - value="${line#Resonators Deployed }" - read values[Builder] junk <<<"${value//,/}" - ;; - #Links Created 4,479 - 'Links Created'*) - value="${line#Links Created }" - read values[Connector] junk <<<"${value//,/}" - ;; - #Control Fields Created 2,340 - 'Control Fields Created'*) - value="${line#Control Fields Created }" - read values[Mind_Controller] junk <<<"${value//,/}" - ;; - #Mind Units Captured 155,815 MUs - 'Mind Units Captured'*) - value="${line#Mind Units Captured }" - read values[MU] junk <<<"${value//,/}" - ;; - #Longest Link Ever Created 3 km - 'Longest Link Ever Created'*) - value="${line#Longest Link Ever Created }" - read values[Longest_Link] junk <<<"${value//,/}" - ;; - #Largest Control Field 11,588 MUs - 'Largest Control Field'*) - value="${line#Largest Control Field }" - read values[Largest_Field] junk <<<"${value//,/}" - ;; - #XM Recharged 92,120,959 XM - 'XM Recharged'*) - value="${line#XM Recharged }" - read values[Recharger] junk <<<"${value//,/}" - ;; - #Portals Captured 2,022 - 'Portals Captured'*) - value="${line#Portals Captured }" - read values[Liberator] junk <<<"${value//,/}" - ;; - #Unique Portals Captured 375 - 'Unique Portals Captured'*) - value="${line#Unique Portals Captured }" - read values[Pioneer] junk <<<"${value//,/}" - ;; - #Mods Deployed 995 - 'Mods Deployed'*) - value="${line#Mods Deployed }" - read values[Engineer] junk <<<"${value//,/}" - ;; - #Resonators Destroyed 15,855 - 'Resonators Destroyed'*) - value="${line#Resonators Destroyed }" - read values[Purifier] junk <<<"${value//,/}" - ;; - #Portals Neutralized 2,145 - 'Portals Neutralized'*) - value="${line#Portals Neutralized }" - read values[Neutralized] junk <<<"${value//,/}" - ;; - #Enemy Links Destroyed 2,725 - 'Enemy Links Destroyed'*) - value="${line#Enemy Links Destroyed }" - read values[Links_Destroyed] junk <<<"${value//,/}" - ;; - #Enemy Control Fields Destroyed 1,418 - 'Enemy Control Fields Destroyed'*) - value="${line#Enemy Control Fields Destroyed }" - read values[Fields_Destroyed] junk <<<"${value//,/}" - ;; - #Max Time Portal Held 105 days - 'Max Time Portal Held'*) - value="${line#Max Time Portal Held }" - read values[Guardian] junk <<<"${value//,/}" - ;; - #Max Time Link Maintained 75 days - 'Max Time Link Maintained'*) - value="${line#Max Time Link Maintained }" - read values[Link_Maintained] junk <<<"${value//,/}" - ;; - #Max Link Length x Days 89 km-days - 'Max Link Length x Days'*) - value="${line#Max Link Length x Days }" - read values[Link_Length_x_Days] junk <<<"${value//,/}" - ;; - #Max Time Field Held 55 days - 'Max Time Field Held'*) - value="${line#Max Time Field Held }" - read values[Field_Held] junk <<<"${value//,/}" - ;; - #Largest Field MUs x Days 58,959 MU-days - 'Largest Field MUs x Days'*) - value="${line#Largest Field MUs x Days }" - read values[Field_x_Days] junk <<<"${value//,/}" - ;; - #Unique Missions Completed 1 - 'Unique Missions Completed'*) - value="${line#Unique Missions Completed }" - read values[Mercenary] junk <<<"${value//,/}" - ;; - #Hacks 25,741 - 'Hacks'*) - value="${line#Hacks }" - read values[Hacker] junk <<<"${value//,/}" - ;; - #Glyph Hack Points 1,022 - 'Glyph Hack Points'*) - value="${line#Glyph Hack Points }" - read values[Translator] junk <<<"${value//,/}" - ;; - #Agents Recruited 1 - 'Agents Recruited'*) - value="${line#Agents Recruited }" - read values[Recruiter] junk <<<"${value//,/}" - ;; - esac -done - -for indice in ${!uinames[@]} -do - if [[ -n "${values[$indice]}" ]] - then - echo "$indice: ${values[$indice]}" - else - echo "Missing $indice (${uinames[$indice]})" - fi -done diff --git a/index b/index index 2c1d6b6..b40cdfd 100755 --- a/index +++ b/index @@ -22,26 +22,18 @@ for lib in lib/* do source $lib done -if [ ! -w "$rrdfile" ] -then - cat <<-EOHead - Content-type: text/plain - Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') - Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') - refresh: 0,url=/cgi/$webuser/add.html - - EOHead - exit -fi +import_images & read_query_string (( start >= end)) && (( end = start + 604800 )) if [ -z "$graph" ] then + refresh=300 + [[ -r .importing ]] && refresh=5 send_headers <<-EOHead content-type: application/xhtml+xml - refresh: 300 + refresh: $refresh EOHead readlast diff --git a/lib/image b/lib/image new file mode 100755 index 0000000..671aee0 --- /dev/null +++ b/lib/image @@ -0,0 +1,179 @@ +#!/bin/bash + +# IngRRD (https://forge.riquer.fr/p/ingrrd/) +# Copyright (C) 2015 Vincent Riquer +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +image() { + exec 2>&1 + local timestamp=$2 + declare -A values + + tmpfile=$(mktemp --suffix=.png) + convert -contrast "$1" "$tmpfile" + readarray -t tactout < <(tesseract -l eng -psm 4 "$tmpfile" stdout) + rm "$tmpfile" + + for line in "${tactout[@]}" + do + case "$line" in + #14,522,411 AP 144mm AP + *' AP'*) + read value junk <<<"$line" + values[AP]=${value//,/} + ;; + #Unique Portals Visited 718 + 'Unique Portals Visited'*) + value="${line#Unique Portals Visited }" + read values[Explorer] junk <<<"${value//,}" + ;; + #Portals Discovered 9 + 'Portals Discovered'*) + value="${line#Portals Discovered }" + read values[Seer] junk <<<"${value//,/}" + ;; + #XM Collected 130,908,527 XM + 'XM Collected'*) + value="${line#XM Collected}" + read values[XM] junk <<<"${value//,/}" + ;; + #Distance Walked 1,785 km + 'Distance Walked'*) + value="${line#Distance Walked }" + read values[Walked] junk <<<"${value//,/}" + ;; + #Resonators Deployed 24,451 + 'Resonators Deployed'*) + value="${line#Resonators Deployed }" + read values[Builder] junk <<<"${value//,/}" + ;; + #Links Created 4,479 + 'Links Created'*) + value="${line#Links Created }" + read values[Connector] junk <<<"${value//,/}" + ;; + #Control Fields Created 2,340 + 'Control Fields Created'*) + value="${line#Control Fields Created }" + read values[Mind_Controller] junk <<<"${value//,/}" + ;; + #Mind Units Captured 155,815 MUs + 'Mind Units Captured'*) + value="${line#Mind Units Captured }" + read values[MU] junk <<<"${value//,/}" + ;; + #Longest Link Ever Created 3 km + 'Longest Link Ever Created'*) + value="${line#Longest Link Ever Created }" + read values[Longest_Link] junk <<<"${value//,/}" + ;; + #Largest Control Field 11,588 MUs + 'Largest Control Field'*) + value="${line#Largest Control Field }" + read values[Largest_Field] junk <<<"${value//,/}" + ;; + #XM Recharged 92,120,959 XM + 'XM Recharged'*) + value="${line#XM Recharged }" + read values[Recharger] junk <<<"${value//,/}" + ;; + #Portals Captured 2,022 + 'Portals Captured'*) + value="${line#Portals Captured }" + read values[Liberator] junk <<<"${value//,/}" + ;; + #Unique Portals Captured 375 + 'Unique Portals Captured'*) + value="${line#Unique Portals Captured }" + read values[Pioneer] junk <<<"${value//,/}" + ;; + #Mods Deployed 995 + 'Mods Deployed'*) + value="${line#Mods Deployed }" + read values[Engineer] junk <<<"${value//,/}" + ;; + #Resonators Destroyed 15,855 + 'Resonators Destroyed'*) + value="${line#Resonators Destroyed }" + read values[Purifier] junk <<<"${value//,/}" + ;; + #Portals Neutralized 2,145 + 'Portals Neutralized'*) + value="${line#Portals Neutralized }" + read values[Neutralized] junk <<<"${value//,/}" + ;; + #Enemy Links Destroyed 2,725 + 'Enemy Links Destroyed'*) + value="${line#Enemy Links Destroyed }" + read values[Links_Destroyed] junk <<<"${value//,/}" + ;; + #Enemy Control Fields Destroyed 1,418 + 'Enemy Control Fields Destroyed'*) + value="${line#Enemy Control Fields Destroyed }" + read values[Fields_Destroyed] junk <<<"${value//,/}" + ;; + #Max Time Portal Held 105 days + 'Max Time Portal Held'*) + value="${line#Max Time Portal Held }" + read values[Guardian] junk <<<"${value//,/}" + ;; + #Max Time Link Maintained 75 days + 'Max Time Link Maintained'*) + value="${line#Max Time Link Maintained }" + read values[Link_Maintained] junk <<<"${value//,/}" + ;; + #Max Link Length x Days 89 km-days + 'Max Link Length x Days'*) + value="${line#Max Link Length x Days }" + read values[Link_Length_x_Days] junk <<<"${value//,/}" + ;; + #Max Time Field Held 55 days + 'Max Time Field Held'*) + value="${line#Max Time Field Held }" + read values[Field_Held] junk <<<"${value//,/}" + ;; + #Largest Field MUs x Days 58,959 MU-days + 'Largest Field MUs x Days'*) + value="${line#Largest Field MUs x Days }" + read values[Field_x_Days] junk <<<"${value//,/}" + ;; + #Unique Missions Completed 1 + 'Unique Missions Completed'*) + value="${line#Unique Missions Completed }" + read values[Mercenary] junk <<<"${value//,/}" + ;; + #Hacks 25,741 + 'Hacks'*) + value="${line#Hacks }" + read values[Hacker] junk <<<"${value//,/}" + ;; + #Glyph Hack Points 1,022 + 'Glyph Hack Points'*) + value="${line#Glyph Hack Points }" + read values[Translator] junk <<<"${value//,/}" + ;; + #Agents Recruited 1 + 'Agents Recruited'*) + value="${line#Agents Recruited }" + read values[Recruiter] junk <<<"${value//,/}" + ;; + esac + done + + template="${!values[@]}" + updatevalues="${values[@]}" + + rrdtool update "$rrdfile" -t "${template// /:}" "$timestamp:${updatevalues// /:}" +} diff --git a/lib/import_images b/lib/import_images new file mode 100644 index 0000000..987bf3f --- /dev/null +++ b/lib/import_images @@ -0,0 +1,29 @@ +#!/bin/bash + +import_images() { + local starttime=$(date +%s) imagetime timestamp elapsed + exec >> images.log + exec 2>> images.log + declare -r oldIFS="$IFS" + [[ -r .importing ]] && return 2 + touch .importing + [[ -w "$rrdfile" ]] || rrdcreate + readlast + for file in dav/* + do + [[ -r "$file" ]] || continue + IFS=_. + read junk date time junk <<<"$file" + IFS="$oldIFS" + if (( $(date '+%Y%m%d%H%M%S' -d @${last[time]}) < $date$time )) + then + imagetime="${date:0:4}/${date:4:2}/${date:6:2} ${time:0:2}:${time:2:2}:${time:4:2}" + echo "$(date +"%Y/%m/%d:%H:%M:%S") - $file: $imagetime" + timestamp=$(date +%s -d "$imagetime") + image "$file" $timestamp + fi + done + elapsed=$(( $(date +%s) - starttime )) + echo "$(date +"%Y/%m/%d:%H:%M:%S"): Spent $elapsed seconds" + rm .importing +} diff --git a/lib/readlast b/lib/readlast index e870185..bd2a428 100644 --- a/lib/readlast +++ b/lib/readlast @@ -7,6 +7,7 @@ readlast() { lastupdatelines \ values \ + last["time"]=0 readarray -t lastupdatelines < <( rrdtool lastupdate $rrdfile )