root/trunk/install/perl/getxml2db.pl

リビジョン 94, 5.8 kB (コミッタ: sorshi, コミット時期: 15 年 前)

SQLite採用

  • svn:executable 属性の設定値:
Line 
1 #!/usr/bin/perl
2 #
3 # Anime recording system foltia
4 # http://www.dcc-jpl.com/soft/foltia/
5 #
6 # usage :getxml2db [long]
7 #しょぼいカレンダー<http://cal.syoboi.jp/>から番組データXMLを取得しfoltia DBにインポートする
8 #
9 #オプション
10 #long:2週間分取り込む。このモードで一日一回回せばよいでしょう。
11 #
12 # DCC-JPL Japan/foltia project
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 #print "process  found:$processes\n";
35 &writelog("getxml2db   processes exist. exit:");
36 exit;
37 }else{
38 #print "process NOT found:$processes\n";
39 &writelog("getxml2db  Normal launch.");
40 }
41
42 if ($ARGV[0]  eq "long"){
43         $uri="http://cal.syoboi.jp/cal_chk.php";
44         #$uri="http://syobocal.orz.hm/cal_chk.php";
45         &writelog("getxml2db  use long mode.");
46 }else{
47         $uri="http://cal.syoboi.jp/cal_chk.xml";
48         #$uri="http://syobocal.orz.hm/cal_chk.xml";
49 }
50
51 $dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
52
53 $dbh->{AutoCommit} = 0;
54
55 # If-Modified-Since使うように変更#2008/11/14
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 #my ($content) = get("$uri");
66 #if ($content eq ""){
67 #&writelog("getxml2db   no responce from $uri, exit:");
68 #       exit;#しょぼかるが落ちているなど
69 #}
70 #my (@line) = split(/\n/, $content);
71
72 foreach(@line){
73
74 Jcode::convert(\$_,'euc');
75
76 #<ProgItem PID="21543" TID="528" StTime="20041114213000" EdTime="20041114220000" ChName="AT-X" Count="4" StOffset="0" SubTitle="いやだよ、サヨナラ…" Title="おとぎストーリー 天使のしっぽ" ProgComment=""/>
77 if (/^<ProgItem /){
78 s/<ProgItem //i;
79 s/\"\/>/\" /i;
80 s/\"[\s]/\";\n/gio;
81 s/\'/\\'/gio;
82 s/\"/\'/gio;
83 #s/[\w]*=/\$item{$&}=/gio;
84 #s/\=}=/}=/gio;
85 s/(\w+)=/\$item{$1}=/gio;#by foltiaBBS
86
87 #$item{PID}='21543';
88 #$item{TID}='528';
89 #$item{StTime}='20041114213000';
90 #$item{EdTime}='20041114220000';
91 #$item{ChName}='AT-X';
92 #$item{Count}='4';
93 #$item{StOffset}='0';
94 #$item{SubTitle}='いやだよ、サヨナラ…';
95 #$item{Title}='おとぎストーリー 天使のしっぽ';
96 #$item{ProgComment}='';
97 eval("$_");
98 Jcode::convert(\$item{Title},'euc');
99
100 $programtitlename = $item{Title};
101 $programtitlename =~ s/\&lt\;/</gi;
102 $programtitlename =~ s/\&gt\;/>/gi;
103 $programtitlename =~ s/\&amp\;/\&/gi;
104 #       $programtitle = $dbh->quote($programtitlename);
105         $programtitle = $programtitlename;
106
107 Jcode::convert(\$item{ChName},'euc');
108 Jcode::convert(\$item{SubTitle},'euc');
109
110 #$programSubTitle = $dbh->quote($item{SubTitle});
111 $programSubTitle = $item{SubTitle};
112 $programSubTitle =~ s/\&lt\;/</gi;
113 $programSubTitle =~ s/\&gt\;/>/gi;
114 $programSubTitle =~ s/\&amp\;/\&/gi;
115 #       $programSubTitle = $dbh->quote($programSubTitle);
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 #200412012359
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 #2006/2/26
142 #あったら、タイトル確認して
143             $sth = $dbh->prepare($stmt{'getxml2db.3'});
144             $sth->execute($item{TID});
145  @titlearray = $sth->fetchrow_array;
146 #更新などされてたらupdate
147 #print "$titlearray[0] / $programtitle\n";
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  }#end if update
153 }# end if TID
154
155
156 #PIDがあるか確認
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         #PIDあったら上書き更新
162 #ここでこんなエラー出てる
163 #       DBD::Pg::st execute failed: ERROR:  invalid input syntax for type bigint: "" at /home/foltia/perl/getxml2db.pl line 147.
164 #UPDATE  foltia_subtitle  SET stationid = '42',countno = '8',subtitle = '京都行きます' ,startdatetime = '200503010035'  ,enddatetime = '200503010050',startoffset  = '0' ,lengthmin = '15' WHERE tid = '550' AND pid =  '26000'
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 #print "$DBQuery\n\n\n";
187 #debug 20050803
188 #&writelog("getxml2db $DBQuery");
189
190
191 }#if
192 }#foreach
193
194 $oserr = $dbh->commit;
195 ##      $dbh->disconnect();
196
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed