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