Top > 日記 > 2014-10-08

**Dstarusers.orgのlist加工 [#ad00f95e]
USTRUST系のログサイトhttp://http://www.dstarusers.org/ の中で知りたい情報のみlist UPするプログラムを作成してみた。
+Webページからの切り取り。最初っから時間でソートした画面を利用。
 -- get_parse.pl --
 use strict;
 use warnings;
 use LWP::UserAgent;
 use HTML::TreeBuilder;
 
 # urlを指定する
 my $url = 'http://www.dstarusers.org/?lastheardsort=4';
 
 # IE8のフリをする
 my $user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1;  Trident/4.0)";
 
 # LWPを使ってサイトにアクセスし、HTMLの内容を取得する
 my $ua = LWP::UserAgent->new('agent' => $user_agent);
 my $res = $ua->get($url);
 my $content = $res->content;
 
 # HTML::TreeBuilderで解析する
 my $tree = HTML::TreeBuilder->new;
 $tree->parse($content);
 
 # DOM操作してトピックの部分だけ抜き出す。
 # <div id='topicsfb'><ul><li>....の部分を抽出する
 open (OUT, ">> dstarlist.txt");
 my @items =  $tree->look_down('class', 'systemtbl')->find('td');
 print OUT $_->as_text.":" for @items;
 close(OUT);
+抽出項目を指定して再リスト化
 -- bunkai.sh --
 #!/bin/bash
 if [ -f /home/moto/dstarlist.txt ]; then
   rm -f /home/moto/dstarlist.txt
 fi
 
 if [ -f /home/moto/dstlistx.txt ]; then
   rm -f /home/moto/dstlistx.txt
 fi
 
 /usr/bin/perl /home/moto/get_parse.pl
 
 nkf -a /home/moto/dstarlist.txt > dstlistx.txt
 
 if [ -f /home/moto/dslist.txt ]; then
   rm -f /home/moto/dslist.txt
 fi
 
 N=5
 while :
 do
 M=`expr $N + 5`
 X="$N-$M"
 #echo "$N"
 LS="/bin/cat /home/moto/dstlistx.txt | /usr/bin/cut -d \":\" -f $X >> /home/moto/dslist.txt"
 eval $LS
 N=`expr $N + 6`
 if test $N -gt 1500 ; then
   break
 fi
 done
 cat dslist.txt | grep -e "^7\|^J\|REF008\|REF047"
+応用
例えば、アクセス時間で新しい方から7局をlist UP する場合は
 $ ./bunkai.sh | head -7
 ide character in print at /home/moto/get_parse.pl line 25. ←データ中に3bite文字があるため。
 JP3KVE:10/08/14 09:30:13 UTC:ZL1VHD B 440 MHz:Auckland, New Zealand
 JA9MIZ A:10/08/14 09:26:38 UTC:JP9YEI A 1.2GHz:Nanto, Toyama-Pref, Japan
 JE1IXA:10/08/14 09:12:51 UTC:JP1YJQ A 1.2GHz:Chiba Inage-Ku, CHIBA, Japan
 JO1WID:10/08/14 09:00:51 UTC:JP1YDS A 1.2GHz:Katori, Chiba, Japan
 JL1LTE:10/08/14 09:00:44 UTC:JP1YDS A 1.2GHz:Katori, Chiba, Japan
 JE3HCZ:10/08/14 08:47:01 UTC:REF047 C 2 Meters DVD:Japan
 JK1MNC:10/08/14 08:41:36 UTC:JP1YJT A 1.2GHz:Yachimata, Chiba, Japan
+phpで作成
ブラウザで開けるタイプにしてみた。UTC 表示に JST も追加表示させた。
 -- wwdst.php --
 <html>
 <head>
 <meta http-equiv="refresh" content="60">
 <meta http-equiv="Content-Type" content="text/html; charset=x-sjis">
 <title>DstarUsers.org List(JP)</title>
 </head>
 <body>
 <?
 $lines = file("http://www.dstarusers.org/?lastheardsort=4");
 $ct = count($lines) - 30;
 
 print "<table border=4 width=850 align=left>\r\n";
 print "<tr><th colspan=4>----------&nbsp;<b>view-source:www.dstarusers.org/?lastheardsort=4</b>&nbsp;----------</th></tr>";
 print "<tr bgcolor='#cccccc'><th>Callsign</th>";
 print "<th>Time Heard<BR>MM/DD/YY&nbsp;&nbsp;UTC / JST&nbsp;</th>";
 print "<th>Reporting Node&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>";
 print "<th>Unique callsigns heard in the last hour</th></tr>\r\n";
 
 $i = 169;
 $hed = "http://www.dstarusers.org/viewrepeater.php";
 
 while( $i < $ct ){
  if(strpos($lines[$i],'google') <= 0 ){
    if(strpos($lines[$i],'/tr>') <= 0 ){
 
      if(substr($lines[$i],8,4) == "<b>7" ){
        print $lines[$i];
        $i++;
        $jst1 = substr($lines[$i],17,2) + 9;
        if($jst1 >=24 ){
          $jst1 = $jst1 - 24;
        }
        $jst1 = "/ ".$jst1.substr($lines[$i],19,6);
        $out1 = str_replace('UTC',$jst1,$lines[$i]);
        print $out1;
        $i++;
        $lines[$i] = str_replace('/viewrepeater.php',$hed,$lines[$i]);
        if(strpos($lines[$i],'1.2GHz') > 0 ){
          $out3 = str_replace('1.2GHz','440 MHz',$lines[$i]);
          print $out3;
        }elseif(strpos($lines[$i],'440') > 0 ){
          $out3 = str_replace('440 MHz','1.2GHz',$lines[$i]);
          print $out3;
        }else{
          print $lines[$i];
        }
        $i++;
        print $lines[$i]."</tr>";
        $i++;
      }
 
      if(substr($lines[$i],8,4) == "<b>J" ){
        print $lines[$i];
        $i++;
        $jst1 = substr($lines[$i],17,2) + 9;
        if($jst1 >=24 ){
         $jst1 = $jst1 - 24;
        }
        $jst1 = "/ ".$jst1.substr($lines[$i],19,6);
        $out1 = str_replace('UTC',$jst1,$lines[$i]);
        print $out1;
        $i++;
        $lines[$i] = str_replace('/viewrepeater.php',$hed,$lines[$i]);
        if(strpos($lines[$i],'1.2GHz') > 0 ){
          $out3 = str_replace('1.2GHz','440 MHz',$lines[$i]);
          print $out3;
        }elseif(strpos($lines[$i],'440') > 0 ){
          $out3 = str_replace('440 MHz','1.2GHz',$lines[$i]);
          print $out3;
        }else{
          print $lines[$i];
        }
        $i++;
        print $lines[$i]."</tr>";
        $i++;
      }
 
   }
  }
  $i++;
 }
 ?>
 </body>
 </html>
+表示例
&ref(wwdst_sample.jpg,,30%);
&ref(wwdst_sample.jpg,,80%);
#clear
#comment
#navi(日記)

リロード   新規 下位ページ作成 編集 凍結 差分 添付 コピー 名前変更   ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS