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 DBD::SQLite; |
---|
22 |
use Digest::MD5 qw(md5_hex); |
---|
23 |
|
---|
24 |
$path = $0; |
---|
25 |
$path =~ s/getxml2db.pl$//i; |
---|
26 |
if ($path ne "./"){ |
---|
27 |
push( @INC, "$path"); |
---|
28 |
} |
---|
29 |
require "foltialib.pl"; |
---|
30 |
|
---|
31 |
|
---|
32 |
$processes = &processfind("getxml2db.pl"); |
---|
33 |
if ($processes > 1 ){ |
---|
34 |
|
---|
35 |
&writelog("getxml2db processes exist. exit:"); |
---|
36 |
exit; |
---|
37 |
}else{ |
---|
38 |
|
---|
39 |
&writelog("getxml2db Normal launch."); |
---|
40 |
} |
---|
41 |
|
---|
42 |
if ($ARGV[0] eq "long"){ |
---|
43 |
$uri="http://cal.syoboi.jp/cal_chk.php"; |
---|
44 |
|
---|
45 |
&writelog("getxml2db use long mode."); |
---|
46 |
}else{ |
---|
47 |
$uri="http://cal.syoboi.jp/cal_chk.xml"; |
---|
48 |
|
---|
49 |
} |
---|
50 |
|
---|
51 |
$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;; |
---|
52 |
|
---|
53 |
$dbh->{AutoCommit} = 0; |
---|
54 |
|
---|
55 |
|
---|
56 |
my $CacheDir = '/tmp/shobocal'; |
---|
57 |
if (! -e $CacheDir) { |
---|
58 |
mkdir $CacheDir or die "cannot create $CacheDir: $!"; |
---|
59 |
} |
---|
60 |
my $cache = sprintf("%s/%s.xml", $CacheDir, Digest::MD5::md5_hex($uri)); |
---|
61 |
LWP::Simple::mirror($uri, $cache) or die "cannot get content from $uri"; |
---|
62 |
open(SHOBO, "<$cache"); |
---|
63 |
my (@line) = <SHOBO>; |
---|
64 |
close(SHOBO); |
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 |
|
---|
72 |
foreach(@line){ |
---|
73 |
|
---|
74 |
Jcode::convert(\$_,'euc'); |
---|
75 |
|
---|
76 |
|
---|
77 |
if (/^<ProgItem /){ |
---|
78 |
s/<ProgItem //i; |
---|
79 |
s/\"\/>/\" /i; |
---|
80 |
s/\"[\s]/\";\n/gio; |
---|
81 |
s/\'/\\'/gio; |
---|
82 |
s/\"/\'/gio; |
---|
83 |
|
---|
84 |
|
---|
85 |
s/(\w+)=/\$item{$1}=/gio; |
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
|
---|
97 |
eval("$_"); |
---|
98 |
Jcode::convert(\$item{Title},'euc'); |
---|
99 |
|
---|
100 |
$programtitlename = $item{Title}; |
---|
101 |
$programtitlename =~ s/\<\;/</gi; |
---|
102 |
$programtitlename =~ s/\>\;/>/gi; |
---|
103 |
$programtitlename =~ s/\&\;/\&/gi; |
---|
104 |
|
---|
105 |
$programtitle = $programtitlename; |
---|
106 |
|
---|
107 |
Jcode::convert(\$item{ChName},'euc'); |
---|
108 |
Jcode::convert(\$item{SubTitle},'euc'); |
---|
109 |
|
---|
110 |
|
---|
111 |
$programSubTitle = $item{SubTitle}; |
---|
112 |
$programSubTitle =~ s/\<\;/</gi; |
---|
113 |
$programSubTitle =~ s/\>\;/>/gi; |
---|
114 |
$programSubTitle =~ s/\&\;/\&/gi; |
---|
115 |
|
---|
116 |
|
---|
117 |
$offsetmin = $item{StOffset}/60; |
---|
118 |
$edtime = &syobocaldate2foltiadate($item{EdTime}); |
---|
119 |
$sttime = &syobocaldate2foltiadate($item{StTime}); |
---|
120 |
$length = &calclength($sttime,$edtime); |
---|
121 |
$recstartdate = &calcoffsetdate($sttime ,$offsetmin ); |
---|
122 |
$recenddate = &calcoffsetdate($edtime ,$offsetmin ); |
---|
123 |
|
---|
124 |
$stationid = &getstationid($item{ChName}); |
---|
125 |
|
---|
126 |
|
---|
127 |
$sth = $dbh->prepare($stmt{'getxml2db.1'}); |
---|
128 |
$sth->execute($item{TID}); |
---|
129 |
@titlecount= $sth->fetchrow_array; |
---|
130 |
|
---|
131 |
if ($titlecount[0] == 0){ |
---|
132 |
|
---|
133 |
|
---|
134 |
|
---|
135 |
$nomalstarttime = substr($sttime,8,4); |
---|
136 |
|
---|
137 |
$sth = $dbh->prepare($stmt{'getxml2db.2'}); |
---|
138 |
$oserr = $sth->execute($item{TID}, $programtitle, '', $nomalstarttime, $length, '', '', 3, 1, '', ''); |
---|
139 |
&writelog("getxml2db ADD TV Progtam:$item{TID}:$programtitle"); |
---|
140 |
}else{ |
---|
141 |
|
---|
142 |
|
---|
143 |
$sth = $dbh->prepare($stmt{'getxml2db.3'}); |
---|
144 |
$sth->execute($item{TID}); |
---|
145 |
@titlearray = $sth->fetchrow_array; |
---|
146 |
|
---|
147 |
|
---|
148 |
if ($titlearray[0] ne "$programtitlename" ){ |
---|
149 |
$sth = $dbh->prepare($stmt{'getxml2db.4'}); |
---|
150 |
$oserr = $sth->execute($programtitle, $item{TID}); |
---|
151 |
&writelog("getxml2db UPDATE TV Progtam:$item{TID}:$programtitle"); |
---|
152 |
} |
---|
153 |
} |
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 |
$sth = $dbh->prepare($stmt{'getxml2db.5'}); |
---|
158 |
$sth->execute($item{'TID'}, $item{'PID'}); |
---|
159 |
@subticount= $sth->fetchrow_array; |
---|
160 |
if ($subticount[0] >= 1){ |
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 |
|
---|
165 |
if ($item{Count} == ""){ |
---|
166 |
$sth = $dbh->prepare($stmt{'getxml2db.6'}); |
---|
167 |
$oserr = $sth->execute($stationid, undef, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length, $item{'TID'}, $item{'PID'}); |
---|
168 |
}else{ |
---|
169 |
$sth = $dbh->prepare($stmt{'getxml2db.7'}); |
---|
170 |
$oserr = $sth->execute($stationid, $item{'Count'}, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length, $item{'TID'}, $item{'PID'}); |
---|
171 |
} |
---|
172 |
}else{ |
---|
173 |
|
---|
174 |
|
---|
175 |
|
---|
176 |
|
---|
177 |
if ($item{Count} eq ""){ |
---|
178 |
$sth = $dbh->prepare($stmt{'getxml2db.8'}); |
---|
179 |
$oserr = $sth->execute($item{'PID'}, $item{'TID'}, $stationid, undef, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length); |
---|
180 |
}else{ |
---|
181 |
$sth = $dbh->prepare($stmt{'getxml2db.9'}); |
---|
182 |
$oserr = $sth->execute($item{'PID'}, $item{'TID'}, $stationid, $item{'Count'}, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length); |
---|
183 |
} |
---|
184 |
} |
---|
185 |
|
---|
186 |
|
---|
187 |
|
---|
188 |
|
---|
189 |
|
---|
190 |
|
---|
191 |
} |
---|
192 |
} |
---|
193 |
|
---|
194 |
$oserr = $dbh->commit; |
---|
195 |
|
---|
196 |
|
---|