1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
use LWP::Simple; |
---|
17 |
use Jcode; |
---|
18 |
use Time::Local; |
---|
19 |
use DBI; |
---|
20 |
use DBD::Pg; |
---|
21 |
use Digest::MD5 qw(md5_hex); |
---|
22 |
|
---|
23 |
$path = $0; |
---|
24 |
$path =~ s/getxml2db.pl$//i; |
---|
25 |
if ($pwd ne "./"){ |
---|
26 |
push( @INC, "$path"); |
---|
27 |
} |
---|
28 |
require "foltialib.pl"; |
---|
29 |
|
---|
30 |
|
---|
31 |
$processes = &processfind("getxml2db.pl"); |
---|
32 |
if ($processes > 1 ){ |
---|
33 |
|
---|
34 |
&writelog("getxml2db processes exist. exit:"); |
---|
35 |
exit; |
---|
36 |
}else{ |
---|
37 |
|
---|
38 |
&writelog("getxml2db Normal launch."); |
---|
39 |
} |
---|
40 |
|
---|
41 |
if ($ARGV[0] eq "long"){ |
---|
42 |
$uri="http://cal.syoboi.jp/cal_chk.php"; |
---|
43 |
|
---|
44 |
&writelog("getxml2db use long mode."); |
---|
45 |
}else{ |
---|
46 |
$uri="http://cal.syoboi.jp/cal_chk.xml"; |
---|
47 |
|
---|
48 |
} |
---|
49 |
|
---|
50 |
|
---|
51 |
my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d", |
---|
52 |
$DBDriv,$DBName,$DBHost,$DBPort); |
---|
53 |
|
---|
54 |
$dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;; |
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 |
|
---|
59 |
my $CacheDir = '/tmp/shobocal'; |
---|
60 |
if (! -e $CacheDir) { |
---|
61 |
mkdir $CacheDir or die "cannot create $CacheDir: $!"; |
---|
62 |
} |
---|
63 |
my $cache = sprintf("%s/%s.xml", $CacheDir, Digest::MD5::md5_hex($uri)); |
---|
64 |
LWP::Simple::mirror($uri, $cache) or die "cannot get content from $uri"; |
---|
65 |
open(SHOBO, "<$cache"); |
---|
66 |
my (@line) = <SHOBO>; |
---|
67 |
close(SHOBO); |
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 |
foreach(@line){ |
---|
76 |
|
---|
77 |
Jcode::convert(\$_,'euc'); |
---|
78 |
|
---|
79 |
|
---|
80 |
if (/^<ProgItem /){ |
---|
81 |
s/<ProgItem //i; |
---|
82 |
s/\"\/>/\" /i; |
---|
83 |
s/\"[\s]/\";\n/gio; |
---|
84 |
s/\'/\\'/gio; |
---|
85 |
s/\"/\'/gio; |
---|
86 |
|
---|
87 |
|
---|
88 |
s/(\w+)=/\$item{$1}=/gio; |
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|
98 |
|
---|
99 |
|
---|
100 |
eval("$_"); |
---|
101 |
Jcode::convert(\$item{Title},'euc'); |
---|
102 |
|
---|
103 |
$programtitlename = $item{Title}; |
---|
104 |
$programtitlename =~ s/\<\;/</gi; |
---|
105 |
$programtitlename =~ s/\>\;/>/gi; |
---|
106 |
$programtitlename =~ s/\&\;/\&/gi; |
---|
107 |
$programtitle = $dbh->quote($programtitlename); |
---|
108 |
|
---|
109 |
Jcode::convert(\$item{ChName},'euc'); |
---|
110 |
Jcode::convert(\$item{SubTitle},'euc'); |
---|
111 |
|
---|
112 |
|
---|
113 |
$programSubTitle = $item{SubTitle}; |
---|
114 |
$programSubTitle =~ s/\<\;/</gi; |
---|
115 |
$programSubTitle =~ s/\>\;/>/gi; |
---|
116 |
$programSubTitle =~ s/\&\;/\&/gi; |
---|
117 |
$programSubTitle = $dbh->quote($programSubTitle); |
---|
118 |
|
---|
119 |
$offsetmin = $item{StOffset}/60; |
---|
120 |
$edtime = &syobocaldate2foltiadate($item{EdTime}); |
---|
121 |
$sttime = &syobocaldate2foltiadate($item{StTime}); |
---|
122 |
$length = &calclength($sttime,$edtime); |
---|
123 |
$recstartdate = &calcoffsetdate($sttime ,$offsetmin ); |
---|
124 |
$recenddate = &calcoffsetdate($edtime ,$offsetmin ); |
---|
125 |
|
---|
126 |
$stationid = &getstationid($item{ChName}); |
---|
127 |
|
---|
128 |
|
---|
129 |
$DBQuery = "SELECT count(*) FROM foltia_program WHERE tid = '$item{TID}'"; |
---|
130 |
$sth = $dbh->prepare($DBQuery); |
---|
131 |
$sth->execute(); |
---|
132 |
@titlecount= $sth->fetchrow_array; |
---|
133 |
|
---|
134 |
if ($titlecount[0] == 0){ |
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 |
$nomalstarttime = substr($sttime,8,4); |
---|
139 |
$DBQuery = "insert into foltia_program values ($item{TID},$programtitle,'','$nomalstarttime','$length','','','3','1','')"; |
---|
140 |
|
---|
141 |
|
---|
142 |
$oserr = $dbh->do($DBQuery); |
---|
143 |
&writelog("getxml2db ADD TV Progtam:$item{TID}:$programtitle"); |
---|
144 |
|
---|
145 |
|
---|
146 |
}else{ |
---|
147 |
|
---|
148 |
|
---|
149 |
$DBQuery = "SELECT title FROM foltia_program WHERE tid = '$item{TID}'"; |
---|
150 |
$sth = $dbh->prepare($DBQuery); |
---|
151 |
$sth->execute(); |
---|
152 |
@titlearray = $sth->fetchrow_array; |
---|
153 |
|
---|
154 |
|
---|
155 |
if ($titlearray[0] ne "$programtitlename" ){ |
---|
156 |
$DBQuery = "UPDATE foltia_program SET title = $programtitle where tid = '$item{TID}' "; |
---|
157 |
|
---|
158 |
|
---|
159 |
$oserr = $dbh->do($DBQuery); |
---|
160 |
&writelog("getxml2db UPDATE TV Progtam:$item{TID}:$programtitle"); |
---|
161 |
} |
---|
162 |
} |
---|
163 |
|
---|
164 |
|
---|
165 |
|
---|
166 |
$DBQuery = "SELECT count(*) FROM foltia_subtitle WHERE tid = '$item{TID}' AND pid = '$item{PID}' "; |
---|
167 |
$sth = $dbh->prepare($DBQuery); |
---|
168 |
$sth->execute(); |
---|
169 |
@subticount= $sth->fetchrow_array; |
---|
170 |
if ($subticount[0] >= 1){ |
---|
171 |
|
---|
172 |
|
---|
173 |
|
---|
174 |
|
---|
175 |
if ($item{Count} == ""){ |
---|
176 |
|
---|
177 |
$DBQuery = "UPDATE foltia_subtitle SET |
---|
178 |
stationid = '$stationid', |
---|
179 |
countno = null, |
---|
180 |
subtitle = $programSubTitle , |
---|
181 |
startdatetime = '$recstartdate' , |
---|
182 |
enddatetime = '$recenddate', |
---|
183 |
startoffset = '$offsetmin' , |
---|
184 |
lengthmin = '$length' |
---|
185 |
WHERE tid = '$item{TID}' AND pid = '$item{PID}' "; |
---|
186 |
|
---|
187 |
}else{ |
---|
188 |
|
---|
189 |
$DBQuery = "UPDATE foltia_subtitle SET |
---|
190 |
stationid = '$stationid', |
---|
191 |
countno = '$item{Count}', |
---|
192 |
subtitle = $programSubTitle , |
---|
193 |
startdatetime = '$recstartdate' , |
---|
194 |
enddatetime = '$recenddate', |
---|
195 |
startoffset = '$offsetmin' , |
---|
196 |
lengthmin = '$length' |
---|
197 |
WHERE tid = '$item{TID}' AND pid = '$item{PID}' "; |
---|
198 |
} |
---|
199 |
|
---|
200 |
|
---|
201 |
$oserr = $dbh->do($DBQuery); |
---|
202 |
|
---|
203 |
}else{ |
---|
204 |
|
---|
205 |
|
---|
206 |
|
---|
207 |
|
---|
208 |
if ($item{Count} eq ""){ |
---|
209 |
$DBQuery = "insert into foltia_subtitle values ( '$item{PID}','$item{TID}','$stationid',null,$programSubTitle,'$recstartdate','$recenddate','$offsetmin' ,'$length')"; |
---|
210 |
}else{ |
---|
211 |
$DBQuery = "insert into foltia_subtitle values ( '$item{PID}','$item{TID}','$stationid','$item{Count}',$programSubTitle,'$recstartdate','$recenddate','$offsetmin' ,'$length')"; |
---|
212 |
} |
---|
213 |
|
---|
214 |
|
---|
215 |
$oserr = $dbh->do($DBQuery); |
---|
216 |
|
---|
217 |
} |
---|
218 |
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 |
|
---|
225 |
} |
---|
226 |
} |
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 |
|
---|
231 |
|
---|