2010/03/24

Recent entries from same category

  1. PerlでWindowsと親和性の高いreadlineが欲しい → あった「Caroline」
  2. Perl をゆるふわと語ろう
  3. cpanfile とは何か、なぜそれを使いたいのか
  4. plackup の --path 引数
  5. Github Notification API が出たので通知を Growl するの書いた。

スクリプトを書いたりしてる人にとってはkarmaなんかの評価値は励みになったりもします。
#!/usr/bin/env perl
use strict;
use warnings;
use URI;
use LWP::UserAgent;
use Web::Scraper;

my $user_id = shift || '103';

local $Web::Scraper::UserAgent = LWP::UserAgent->new;
$Web::Scraper::UserAgent->env_proxy;

my $account_url = "http://www.vim.org/account/profile.php?user_id=$user_id";
my $s1      = scraper {
  process '//td/a[contains(@href,"/scripts/script")]', 'karmas[]' => sub {
    my $e1     = shift;
    my $script_url = URI->new_abs( $e1->attr('href'), $account_url );
    my $s2     = scraper {
      process '//title',                         'name'  => 'TEXT';
      process '//td[contains(text(),"Rating")]', 'karma' => sub {
        my $e2 = shift;
        if ( $e2->as_text =~ /Rating ([^\s]*), Downloaded by ([^\s]*)/ )
        {
          return { rating => $1, downloaded => $2 };
        }
      };
    };
    my $staff = $s2->scrape($script_url);
    $staff->{url} = $script_url;
    $staff;
  };
  result 'karmas';
};
my @r = @{ $s1->scrape( URI->new($account_url) ) };

use YAML::Syck;
warn Dump @r;

# vim:set et:

---
karma: 
  downloaded: 25932
  rating: 1355/552
name: "calendar.vim - Calendar : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=52
---
karma: 
  downloaded: 783
  rating: 9/7
name: "which.vim - This is a unix like \"Which\" function. : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=139
---
karma: 
  downloaded: 1054
  rating: 9/10
name: "XpMenu - Make vim use WinXP style menu. : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=928
---
karma: 
  downloaded: 1884
  rating: 13/13
name: "VS like Class Completion - This script can complete member of cpp or java like Visual Studio. : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=675
---
karma: 
  downloaded: 943
  rating: 16/9
name: "ftplugin for Calendar - This is a ftplugin for Calenar. : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=683
---
karma: 
  downloaded: 1871
  rating: 92/37
name: "VimTweak - The tweaking dll for GVim.exe. : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=687
---
karma: 
  downloaded: 980
  rating: -1/1
name: "VimSpeak - Speak selected text with MS Agent : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=692
---
karma: 
  downloaded: 960
  rating: 11/4
name: "FTP Completion - complete files in command line for ftp. : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=963
---
karma: 
  downloaded: 183
  rating: 2/2
name: "Pit Configuration - pit configuration library for vim : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=2404
---
karma: 
  downloaded: 1282
  rating: 81/24
name: "Gist.vim - vimscript for gist : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=2423
---
karma: 
  downloaded: 805
  rating: 82/29
name: "GoogleReader.vim - vimscript for googlereader : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=2678
---
karma: 
  downloaded: 252
  rating: 20/5
name: "FastLadder.vim - vimscript for fastladder : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=2683
---
karma: 
  downloaded: 78
  rating: 0/0
name: "GoogleSuggest Complete - complete function using google suggest API. perhaps, you should input japanese w : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=2948
---
karma: 
  downloaded: 833
  rating: 101/29
name: "ZenCoding.vim - vim plugins for HTML and CSS hi-speed coding. : vim online"
url: !!perl/scalar:URI::http http://www.vim.org/scripts/script.php?script_id=2981
ダメダメなスクリプトとか、もう消した方がいいかな...とか思った。
Posted at by