Last active
March 6, 2017 14:59
-
-
Save dbiesecke/70a6b821431c576aa265 to your computer and use it in GitHub Desktop.
Perl misc scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# cpanm -nf Text::ASCIITable Web::Scraper | |
# #hashrates > form > div:nth-child(3) | |
use URI; | |
use Web::Scraper; | |
use Data::Dumper; | |
use Text::ASCIITable; | |
my $show_coins = 10; | |
# First, create your scraper block | |
my $coins = scraper { | |
process "tr.Scrypt", "coins[]" => scraper { | |
process ".coinCode", coin => 'TEXT'; | |
process "td" , "list[]" => 'TEXT'; | |
process "span.background" , btcad => 'TEXT'; | |
process 'a[title]', exchange => 'TEXT'; | |
}; | |
}; | |
my $res = $coins->scrape( URI->new("http://cointweak.com/") ); | |
$t = Text::ASCIITable->new({ headingText => 'Scrypt - overview 24h - 1Mh/s' }); | |
my $x = 0; | |
$t->setCols('Coin','Exchange',"BTC/1MHs", "\$\$/1Mhs"); | |
for my $coin (@{$res->{coins}}) { $x++; | |
$coin->{list}[7] =~ s/\$(.+) -.*/$1/m; | |
$coin->{btcad} =~ s/.?(\d\.\d+)\/day/$1/m; | |
next if $1 == "1.00000000" or $x > $show_coins; | |
$t->addRow($coin->{coin},$coin->{exchange},$1,$coin->{list}[7]); | |
} | |
print $t; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
require Plugin::Tiny; | |
require Carp; | |
require Exporter; | |
require Moose; | |
require URI; | |
require Web::Scraper; | |
require Data::Dumper; | |
require Text::ASCIITable; | |
package Cli::cointweak; | |
use Web::Scraper; | |
use Text::ASCIITable; | |
use Finance::Bank::Kraken; | |
use JSON; | |
use MooseX::App::Command; # important | |
extends qw(Cli); # purely optional, only if you want to use global options from base class | |
option 'coins' => ( | |
is => 'rw', | |
isa => 'Int', | |
default => 10, | |
documentation => q[how many coins to display], | |
); # Option | |
command_short_description q[ cointweak 24h stats]; | |
command_long_description q[ Shows Scrypt - overview 24h - 1Mh/s from cointweak ]; | |
sub run { | |
my ($self,@arr) = @_; | |
#print Data::Dumper::Dumper($self)."\n"; | |
my $show_coins = $self->{coins} || '3'; | |
my $rest; | |
my $kraken = new Finance::Bank::Kraken; | |
$rest = $kraken->call(Public, 'Ticker', ['pair=XLTCZEUR,XXBTZEUR']); | |
printf "1 XLTC is %f EUR\n", | |
from_json($rest)->{'result'}->{'XXBTZEUR'}->{'c'}[0] | |
unless $rest =~ /^5/; | |
# First, create your scraper block | |
my $coins = scraper { | |
process "tr.Scrypt", "coins[]" => scraper { | |
process ".coinCode", coin => 'TEXT'; | |
process "td" , "list[]" => 'TEXT'; | |
process "span.background" , btcad => 'TEXT'; | |
process 'a[title]', exchange => 'TEXT'; | |
}; | |
}; | |
my $res = $coins->scrape( URI->new("http://cointweak.com/") ); | |
my $t = Text::ASCIITable->new({ headingText => 'Scrypt - overview 24h - 1Mh/s' }); | |
my $x = 0; | |
$t->setCols('Coin','Exchange',"BTC/1MHs", "\$\$/1Mhs"); | |
for my $coin (@{$res->{coins}}) { $x++; | |
$coin->{list}[7] =~ s/\$(.+) -.*/$1/m; | |
$coin->{btcad} =~ s/.?(\d\.\d+)\/day/$1/m; | |
next if $1 == "1.00000000" or $x > $show_coins; | |
$t->addRow($coin->{coin},$coin->{exchange},$1,$coin->{list}[7]); | |
} | |
print $t; | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# Usage perl $0 > ./yourlist.m3u | |
my $pwd = $ENV{'PWD'}; | |
print $pwd."\n"; | |
my $x = 0; | |
foreach my $file (<*>){ | |
my @name = split(/ - /,$file); | |
$name[1] =~ s/\.([\w\d]+)$//i; | |
print "#EXTINF:-1,$name[0] - $name[1]\n"; | |
open(FILE,$pwd.'/'.$file); | |
print <FILE>."\n"; | |
close (FILE); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval { | |
use autodie qw(system); | |
system(`backup_files`); | |
system(`delete_files`); | |
}; | |
if ($@) { | |
warn "Error in running commands: $@\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use File::Copy qw(move); | |
my $sess = "S01"; | |
@files = <*>; | |
my $pwd = $ENV{'PWD'}; | |
print $pwd."\n"; | |
my $x = 0; | |
foreach(@files) { | |
$x++; | |
chdir "$_"; | |
foreach(<*>){ | |
my $name = $_; | |
$name =~ s/.(e\d\d)./\.$sess$1\./g; | |
print "$name\n"; | |
move $_, $name; | |
} | |
chdir "$pwd"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use AnyEvent; | |
my @lines; # read data | |
my $idle_w; | |
my $io_w = AnyEvent->io (fh => \*STDIN, poll => 'r', cb => sub { | |
push @lines, scalar <STDIN>; | |
# start an idle watcher, if not already done | |
$idle_w ||= AnyEvent->idle (cb => sub { | |
# handle only one line, when there are lines left | |
if (my $line = shift @lines) { | |
print "handled when idle: $line"; | |
} else { | |
# otherwise disable the idle watcher again | |
undef $idle_w; | |
} | |
}); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
@files = <*>; | |
my $pwd = $ENV{'PWD'}; | |
print $pwd."\n"; | |
my $x = 0; | |
foreach(@files) { | |
$x++; | |
chdir "$_"; | |
system("unrar x *.rar"); | |
chdir "$pwd"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
require Plugin::Tiny; | |
require Carp; | |
require Exporter; | |
require Moose; | |
require URI; | |
require fget; | |
require Data::Dumper; | |
package Cli::zencloud; | |
use WWW::Mechanize; | |
use Data::Dumper qw( Dumper); | |
use JSON qw( to_json); | |
use Web::Scraper; | |
use MooseX::App::Command; # important | |
extends qw(Cli); # purely optional, only if you want to use global options from base class | |
parameter 'username' => ( | |
is => 'rw', | |
isa => 'Str', | |
required => 1, | |
documentation => q[Username for login], | |
cmd_tags => [qw(Important!)], # Extra tags. Displayed in square brackets | |
cmd_aliases => [qw(u)], # Alternative option name | |
); # Positional parameter | |
parameter 'password' => ( | |
is => 'rw', | |
isa => 'Str', | |
required => 1, | |
documentation => q[Password for login], | |
cmd_tags => [qw(Important!)], # Extra tags. Displayed in square brackets | |
cmd_aliases => [qw(p)], # Alternative option name | |
); # Positional parameter | |
option 'as_csv' => ( | |
is => 'rw', | |
isa => 'Bool', | |
default => 1, | |
documentation => q[ Print as csv], | |
); # Option | |
option 'show_miner' => ( | |
is => 'rw', | |
isa => 'Bool', | |
default => 0, | |
documentation => q[ Verbose miner stat's output ], | |
cmd_aliases => [qw(s)], # Alternative option name | |
); # Option | |
command_short_description q[ zencloud stats]; | |
command_long_description q[ zecloud api commands ]; | |
sub printexit { | |
my ($self,@arr) = @_; | |
print to_json($self->{stats})."\n" if ($self->{debug}); | |
return if ($self->{debug}); | |
print "Coin,est_payout,power,activated\n" if ($ self->{as_csv} ); | |
for my $tweet (@{$self->{stats}->{miner}}) { | |
print "$tweet->{coin}\t$tweet->{est_payoutBTC}\t$tweet->{power}\t$tweet->{activated}\n" if ($self->{as_csv} ); | |
} | |
} | |
sub run { | |
my ($self,@arr) = @_; | |
my $username = $self->{username}; | |
my $password = $self->{password}; | |
my $return = {}; | |
#print "--> Login : $username\r\n" if ($self->{debug}); | |
use WWW::Mechanize; | |
my $get = WWW::Mechanize->new(); | |
$get->get("https://cloud.zenminer.com/login"); | |
$get->set_visible( $username, $password ); | |
$get->click(); | |
$self->{stats} = get_default_stats($get); | |
$self->printexit("test") if not ($self->{show_miner}); | |
$self->{miner} = (); | |
$self->{stats}->{feeUSD} = 0; | |
$self->{stats}->{btc24hPayout_est} = 0; | |
foreach(get_miner_stats($get)){ | |
my $miner = $_; | |
$self->{stats}->{btc24hPayout_est} = ($self->{stats}->{btc24hPayout_est}+$miner->{est_payoutBTC}); | |
$self->{stats}->{feeUSD} = ($self->{stats}->{feeUSD}+$miner->{feeUSD}); | |
push(@{$self->{stats}->{miner}},$miner); | |
} | |
#print Data::Dumper::Dumper($_)."\n"; | |
$self->printexit("test"); | |
#$return = get_miner_stats($get); | |
#print Data::Dumper::Dumper($return)."\n"; | |
# $get->save_content("temp.html"); | |
#print "----------\n".Data::Dumper::Dumper($scrap->scrape($get->content()))."\n"; | |
#my $show_coins = $self->{coins} || '3'; | |
#$self->get("https://cloud.zenminer.com/ajax/miners"); | |
} | |
sub get_miner_stats(){ | |
my $get = shift or die("error with get"); | |
$get->get("https://cloud.zenminer.com/ajax/miners"); | |
my $scrap = scraper { | |
process "div.device", "list[]" => scraper { | |
process ".name", name => 'TEXT'; | |
process ".power", power => 'TEXT'; | |
#process "a", power_fix => '@data-device-power'; | |
#process "a", pool => '@data-pool'; | |
process ".payout", est_payoutBTC => 'TEXT'; | |
process ".device", feeUSD => '@data-dailyamount'; | |
process ".device", activated => '@data-activated'; | |
process ".device", sellprice => '@data-sellprice'; | |
process ".device", coin => '@data-type'; | |
}; | |
}; | |
#my $res = $scrap->scrape($get->content); | |
return @{$scrap->scrape($get->content)->{list}}; | |
} | |
sub get_default_stats(){ | |
my $get = shift or die("error with get"); | |
my $scrap = scraper { | |
process ".balance-value", btc_deposit => 'TEXT'; | |
process ".balanceUSD-value", btcUSD => 'TEXT'; | |
process ".btcAddress", btc_addr => 'TEXT'; | |
process ".24hPayout", btc24hPayout => 'TEXT'; | |
process ".totalScryptHashpower", totalScryptHashpower => 'TEXT'; | |
process ".totalBtcHashpower", totalBtcHashpower => 'TEXT'; | |
}; | |
return $scrap->scrape($get->content); | |
} | |
# sub do_some { print "Hello World @_\n" } | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment