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 |
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
51 |
$uri = "http://cal.syoboi.jp/cal_chk.php?days="; |
---|
52 |
$uri .= ($ARGV[0] eq "long")? 14: 7; |
---|
53 |
|
---|
54 |
$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;; |
---|
55 |
|
---|
56 |
$dbh->{AutoCommit} = 0; |
---|
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 |
s/\xef\xbd\x9e/\xe3\x80\x9c/g; |
---|
77 |
s/\xef\xbc\x8d/\xe2\x88\x92/g; |
---|
78 |
s/& |
---|
79 |
|
---|
80 |
Jcode::convert(\$_,'euc','utf8'); |
---|
81 |
|
---|
82 |
|
---|
83 |
if (/^<ProgItem /){ |
---|
84 |
s/<ProgItem //i; |
---|
85 |
s/\"\/>/\" /i; |
---|
86 |
s/\"[\s]/\";\n/gio; |
---|
87 |
s/\'/\\'/gio; |
---|
88 |
s/\"/\'/gio; |
---|
89 |
|
---|
90 |
|
---|
91 |
s/(\w+)=/\$item{$1}=/gio; |
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 |
|
---|
103 |
eval("$_"); |
---|
104 |
|
---|
105 |
|
---|
106 |
$programtitlename = $item{Title}; |
---|
107 |
$programtitlename =~ s/\<\;/</gi; |
---|
108 |
$programtitlename =~ s/\>\;/>/gi; |
---|
109 |
$programtitlename =~ s/\&\;/\&/gi; |
---|
110 |
|
---|
111 |
$programtitle = $programtitlename; |
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 |
|
---|
116 |
|
---|
117 |
$programSubTitle = $item{SubTitle}; |
---|
118 |
$programSubTitle =~ s/\<\;/</gi; |
---|
119 |
$programSubTitle =~ s/\>\;/>/gi; |
---|
120 |
$programSubTitle =~ s/\&\;/\&/gi; |
---|
121 |
|
---|
122 |
|
---|
123 |
$offsetmin = $item{StOffset}/60; |
---|
124 |
$edtime = &syobocaldate2foltiadate($item{EdTime}); |
---|
125 |
$sttime = &syobocaldate2foltiadate($item{StTime}); |
---|
126 |
$length = &calclength($sttime,$edtime); |
---|
127 |
$recstartdate = &calcoffsetdate($sttime ,$offsetmin ); |
---|
128 |
$recenddate = &calcoffsetdate($edtime ,$offsetmin ); |
---|
129 |
|
---|
130 |
$stationid = &getstationid($item{ChName}); |
---|
131 |
|
---|
132 |
|
---|
133 |
$sth = $dbh->prepare($stmt{'getxml2db.1'}); |
---|
134 |
$sth->execute($item{TID}); |
---|
135 |
@titlecount= $sth->fetchrow_array; |
---|
136 |
|
---|
137 |
if ($titlecount[0] == 0){ |
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 |
$nomalstarttime = substr($sttime,8,4); |
---|
142 |
|
---|
143 |
$sth = $dbh->prepare($stmt{'getxml2db.2'}); |
---|
144 |
$oserr = $sth->execute($item{TID}, $programtitle, '', $nomalstarttime, $length, '', '', 3, 1, '', ''); |
---|
145 |
&writelog("getxml2db ADD TV Progtam:$item{TID}:$programtitle"); |
---|
146 |
}else{ |
---|
147 |
|
---|
148 |
|
---|
149 |
$sth = $dbh->prepare($stmt{'getxml2db.3'}); |
---|
150 |
$sth->execute($item{TID}); |
---|
151 |
@titlearray = $sth->fetchrow_array; |
---|
152 |
|
---|
153 |
|
---|
154 |
if ($titlearray[0] ne "$programtitlename" ){ |
---|
155 |
$sth = $dbh->prepare($stmt{'getxml2db.4'}); |
---|
156 |
$oserr = $sth->execute($programtitle, $item{TID}); |
---|
157 |
&writelog("getxml2db UPDATE TV Progtam:$item{TID}:$programtitle"); |
---|
158 |
} |
---|
159 |
} |
---|
160 |
|
---|
161 |
|
---|
162 |
|
---|
163 |
$sth = $dbh->prepare($stmt{'getxml2db.5'}); |
---|
164 |
$sth->execute($item{'TID'}, $item{'PID'}); |
---|
165 |
@subticount= $sth->fetchrow_array; |
---|
166 |
if ($subticount[0] >= 1){ |
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 |
|
---|
171 |
if ($item{Count} == ""){ |
---|
172 |
$sth = $dbh->prepare($stmt{'getxml2db.6'}); |
---|
173 |
$oserr = $sth->execute($stationid, undef, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length, $item{'TID'}, $item{'PID'}); |
---|
174 |
}else{ |
---|
175 |
$sth = $dbh->prepare($stmt{'getxml2db.7'}); |
---|
176 |
$oserr = $sth->execute($stationid, $item{'Count'}, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length, $item{'TID'}, $item{'PID'}); |
---|
177 |
} |
---|
178 |
}else{ |
---|
179 |
|
---|
180 |
|
---|
181 |
|
---|
182 |
|
---|
183 |
if ($item{Count} eq ""){ |
---|
184 |
$sth = $dbh->prepare($stmt{'getxml2db.8'}); |
---|
185 |
$oserr = $sth->execute($item{'PID'}, $item{'TID'}, $stationid, undef, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length); |
---|
186 |
}else{ |
---|
187 |
$sth = $dbh->prepare($stmt{'getxml2db.9'}); |
---|
188 |
$oserr = $sth->execute($item{'PID'}, $item{'TID'}, $stationid, $item{'Count'}, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length); |
---|
189 |
} |
---|
190 |
} |
---|
191 |
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|
195 |
|
---|
196 |
|
---|
197 |
} |
---|
198 |
} |
---|
199 |
|
---|
200 |
$oserr = $dbh->commit; |
---|
201 |
|
---|
202 |
|
---|