Skip to content

Instantly share code, notes, and snippets.

@visar
Created March 3, 2014 07:15
Show Gist options
  • Save visar/9319891 to your computer and use it in GitHub Desktop.
Save visar/9319891 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use HTTP::Cookies;
use File::Temp;
$| = 1;
my $ua = LWP::UserAgent->new( cookie_jar => HTTP::Cookies->new );
my $url = 'http://195.189.206.107:3000/';
while (42)
{
my $tmp_file = File::Temp->new( SUFFIX => '.png' );
my $response
= $ua->get( $url . 'code.png', ':content_file' => "$tmp_file" );
my $string = `pngtopnm $tmp_file | ocrad -s 2`;
$string =~ s/\n+$//;
print "$string\n";
last if $string eq 'END';
$response = $ua->post( $url . 'code', [ 'code' => $string ] );
last if $response->content eq 'ERR';
}
print "You should install ocrad and netpbm packages.\n" if $? >> 8;
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use HTTP::Cookies;
use File::Temp;
use Image::OCR::Tesseract 'get_ocr';
$| = 1;
my $ua = LWP::UserAgent->new( cookie_jar => HTTP::Cookies->new );
my $url = 'http://195.189.206.107:3000/';
while (42)
{
my $tmp_file = File::Temp->new( SUFFIX => '.png' );
my $response
= $ua->get( $url . 'code.png', ':content_file' => "$tmp_file" );
my $string = get_ocr($tmp_file);
$string =~ s/\s+//g;
$string =~ s/\|/l/g;
print "$string\n" if $string ne '';
print "END\n" if $string eq '';
last if $string eq '';
$response = $ua->post( $url . 'code', [ 'code' => $string ] );
last if $response->content eq 'ERR';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment