Guest User

iar update check

a guest
Jun 24th, 2015
171
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/perl
  2.  
  3. use LWP::Simple;
  4. use Mojo::DOM;
  5.  
  6.  
  7. sub dotarget {
  8.     my $domain = "http://supp.iar.com";
  9.     my $targetcode = @_[0];
  10.     my $targetname = @_[1];
  11.     my $url="$domain/Download/SW/?item=$targetcode";
  12.     my $outhtml;
  13.     my $browser = LWP::UserAgent->new;
  14.  
  15.     $response = $browser->get($url);
  16.     $response->is_success || die("$targetcode: Can't get $url -- ".$response->status_line);
  17.  
  18.     my $dom = Mojo::DOM->new( $response->content );
  19.  
  20.     my $dllink = $dom->find('frame[name*="exec"]')->[0]->{src};
  21.     if(not $dllink =~ /http:/) { $dllink = $domain.$dllink; }
  22.  
  23.     $response = $browser->get($dllink);
  24.     $response->is_success || die("$targetcode: Can't get $dllink -- ".$response->status_line);
  25.  
  26.     $dom = Mojo::DOM->new($response->content);
  27.  
  28.     my $finalurl = "";
  29.     $dom->find("a[href]")->each(sub {
  30.         if( $_->text =~ m/Download/ ) {
  31.             $finalurl = $_->{href};
  32.             if(not $finalurl =~ /http:/) { $finalurl = $domain.$finalurl; }
  33.         }
  34.     } );
  35.  
  36.     if($finalurl eq "") {
  37.         $outhtml.="    <item>\n";
  38.         $outhtml.="        <title>$targetname: not found</title>\n";
  39.         $outhtml.="        <description><![CDATA[$targetcode: registration required?]]></description>\n";
  40.         $outhtml.="    </item>\n";
  41.         print "$targetcode: can't find download url\n";
  42.         return $outhtml;
  43.     }
  44.  
  45.     my $headers = $browser->head($finalurl) || die("$targetcode: can't get headers");
  46.  
  47.     my $installerurl = $headers->{_request}->{_uri};
  48.     my $installerexe = (URI->new($installerurl)->path_segments)[-1];
  49.     my $installerupdated = $headers->{_headers}->{"last-modified"};
  50.     my $installersize = $headers->{_headers}->{"content-length"};
  51.  
  52.     $outhtml.="    <item>\n";
  53.     $outhtml.="        <title>$targetname</title>\n";
  54.     $outhtml.="        <link>$installerurl</link>\n";
  55.     $outhtml.="        <pubDate>$installerupdated</pubDate>\n";
  56.     $outhtml.="        <description><![CDATA[$targetcode <a href=\"$installerurl\">$installerexe</a><br>$installersize bytes]]></description>\n";
  57.     $outhtml.="    </item>\n";
  58.  
  59.     print "$targetcode: $installerurl\n";
  60.  
  61.     return $outhtml;
  62. }
  63.  
  64. #генерим список платформ
  65. my $url="https://www.iar.com/iar-embedded-workbench/downloads/";
  66. my $browser = LWP::UserAgent->new;
  67. $response = $browser->get($url);
  68. $response->is_success || die("Can't get list of platforms");
  69.  
  70. my $dom = Mojo::DOM->new( $response->content );
  71.  
  72. my %desclist;
  73. my $desc;
  74. my @a = $dom->find('div[id*="main-body"] tr td')->each(sub {
  75.     if($_ =~ m/IAR Embedded Workbench for ([\d\w]+)/g) {
  76.         $desc = $1;
  77.     }elsif($_ =~ m/Download\/SW\/\?item=([\d\w-]+)/g) {
  78.         $desclist{$1}=$desc;
  79.     }
  80. } );
  81. $desclist{"EWARM-EVAL"}="ARM";
  82.  
  83.  
  84.  
  85. ##########################################################
  86. open (OUTXML,">iarrss.xml");
  87. print OUTXML <<HTML;
  88. <?xml version="1.0"?>
  89. <rss version="2.0">
  90.   <channel>
  91.     <title>iar</title>
  92.     <description>iar rss</description>
  93. HTML
  94.  
  95. while(($targetcode,$targetname) = each(%desclist)) {
  96.     print OUTXML dotarget($targetcode, $targetname);
  97. }
  98.  
  99. print OUTXML "  </channel>\n";
  100. print OUTXML "</rss>\n";
  101. close(OUTXML);
RAW Paste Data