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