1 #// ong-mscha-t-1.awk
\r
2 #// The bot to ketchup frames from the mschaviewer, and enhance by remapping
\r
5 #// Copyright (C) 2015, 2019 Balthasar SzczepaĆski
\r
7 #// This program is free software: you can redistribute it and/or modify
\r
8 #// it under the terms of the GNU Affero General Public License as
\r
9 #// published by the Free Software Foundation, either version 3 of the
\r
10 #// License, or (at your option) any later version.
\r
12 #// This program is distributed in the hope that it will be useful,
\r
13 #// but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 #// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 #// GNU Affero General Public License for more details.
\r
17 #// You should have received a copy of the GNU Affero General Public License
\r
18 #// along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
22 framepath="/eizm/www/time/"
\r
23 datapath="/eizm/data/aftertime/"
\r
24 temppath="/eizm/tmp/aftertime/"
\r
25 passpath="/eizm/mem/aftertime/pass/"
\r
27 timecmd="date -u +%Y%m%d%H%s"
\r
30 mawk="/usr/bin/mawk"
\r
31 wget="/usr/bin/wget"
\r
32 remap="/eizm/pro/aftertime/remapt-1"
\r
33 npb="/eizm/pro/ong1/npb"
\r
34 bot4awk="/eizm/pro/aftertime/bot4.awk"
\r
35 uploadawk="/eizm/pro/aftertime/upload.awk"
\r
39 gsub(/[\r\n]/, "", $0)
\r
42 argtab[substr($0, 1, eq-1)]=substr($0, eq+1)
\r
52 if(argtab["ongoing"]!="2")
\r
54 print "Story is not externally onged."
\r
58 # timecmd | getline thistime
\r
61 statefile= datapath argtab["story"]"/ongstate"
\r
62 passfile= passpath argtab["story"]
\r
63 getline temp < statefile
\r
64 getline alt < statefile
\r
67 split(temp, temptab, " ")
\r
68 state=int(temptab[1])
\r
69 last=int(temptab[2])
\r
75 tempfile = temppath "ongmscha-"argtab["story"]"--1"
\r
76 tempfile2 = temppath "ongmscha-"argtab["story"]"--2"
\r
77 optionfile = datapath argtab["story"]"/settings"
\r
78 framedir = "aftertime/"argtab["story"]"/"
\r
80 # system("sleep 15")
\r
85 timecmd | getline thistime
\r
88 timetext = substr(thistime,1,10);
\r
89 timenumber = substr(thistime,11);
\r
91 print f" "timetext" "timenumber
\r
94 frameurl= sprintf(argtab["otherviewerframe"],f)
\r
95 viewerurl= sprintf(argtab["otherviewerurl"],f)
\r
97 frame= framepath framedir sprintf(argtab["frame"],f)
\r
98 npbframe= framepath framedir sprintf(argtab["npbframe"],f)
\r
100 remapframe= framepath framedir sprintf(argtab["frame-1"],f)
\r
101 npbremapframe= framepath framedir sprintf(argtab["npbframe-1"],f)
\r
103 getfcmd= wget " -q -O " frame " "frameurl
\r
104 getvcmd= wget " -q -O " tempfile " "viewerurl
\r
105 npbcmd= sprintf(npb " %s %s q",frame,npbframe)
\r
106 ongcmd= mawk" -f " bot4awk" -v story="argtab["story"]" -v frame="last" "optionfile
\r
107 ongremapcmd= mawk" -f " bot4awk" -v story="argtab["story"]" -v frame="last" -v enhance=1 "optionfile
\r
108 npbremapcmd= sprintf(npb " %s %s q",remapframe,npbremapframe)
\r
109 addhashcmd= mawk" -f "uploadawk" -v timenumber="timenumber" -v timetext="timetext" -v tempfile="tempfile" "tempfile2
\r
111 if(system(getfcmd)!=0)
\r
113 print "Frame download failed: "getfcmd
\r
118 if(system(getvcmd)!=0)
\r
120 print "Viewer download failed: "getvcmd
\r
127 while ((getline temp < tempfile) > 0)
\r
129 if(index(temp,frameurl)!=0 && foundalt=="")
\r
131 newalt=substr(temp,index(temp,"title=\"")+7)
\r
132 newalt=substr(newalt,1,index(newalt,"\"")-1)
\r
134 print "alt: "newalt
\r
136 if(index(temp,"class=\"hash\"")!=0 && foundpal=="" )
\r
138 pal=substr(temp,index(temp,">")+1)
\r
139 pal=substr(pal,1,index(pal,".")-1)
\r
143 if(foundalt!="" && foundpal!="")
\r
150 remapcmd= remap " "frame" "remapframe" "pal
\r
154 print f"="newalt >> optionfile
\r
158 if(system(npbcmd)!=0)
\r
162 print "ONG "f" "((alt==newalt)?"":""newalt)
\r
164 if(system(remapcmd)==0)
\r
166 if(system(npbremapcmd)!=0)
\r
171 getline namef < passfile
\r
172 getline passf < passfile
\r
174 if(namef!="" &&passf !="")
\r
176 print namef > tempfile2
\r
177 print passf > tempfile2
\r
178 print "" > tempfile2
\r
179 print argtab["story"]"#"f"#1" > tempfile2
\r
180 print "su" > tempfile2
\r
181 print substr(timetext,1,4)"-"substr(timetext,5,2)"-"substr(timetext,7,2)" "substr(timetext,9,2) > tempfile2
\r
182 print "Original filename" > tempfile2
\r
183 print "[code]"pal".png[/code]"> tempfile2
\r
184 print "" > tempfile2
\r
195 # system("sleep 5")
\r
196 # system(ongremapcmd)
\r
201 print nextstate" "f > statefile
\r
202 print newalt > statefile
\r