#!/usr/bin/perl
use POSIX qw(strftime);
use LWP::UserAgent;
use HTTP::Headers;
use HTTP::Cookies;
use Digest::MD5 qw(md5_hex);
use DBI;
use common::sense;
no utf8;
no strict;
$ua = new LWP::UserAgent;
$hh = HTTP::Headers->new(
User-Agent => 'Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0',
Accept => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
Accept-Language => 'en-us,en;q=0.7,ru;q=0.3',
Accept-Encoding => 'gzip, deflate',
Connection => 'keep-alive',
);
$ua->default_headers( $hh );
$ua->cookie_jar({});
$ua->timeout(20);
YMoney();
sub YMoney {
# Заглавная страница, для куков
$res = $ua->get('...');
# Логин
$res = $ua->post(... );
# Список пополнений в csv
.....
$res = $ua->get("...");
say $res->decoded_content();
$s = $res->decoded_content();
@list = reverse split("\n", $s);
# Обработка списка и добавление данных в базу
$dbh = DBI->connect("DBI:mysql:database=orders;host=localhost;port=3306", "...");
$dbh->do('SET CHARACTER SET cp1251');
for $line (@list) {
next if ($line !~ /^\+;/);
@pay{'data', 'amount', 'comment'} = map { s/"+//g; $_ } (split(';', $line))[1, 2, 5];
$pay{hash} = md5_hex( join('', @pay{'data', 'amount', 'comment'}) );
$id = $dbh->selectrow_array("SELECT id FROM ymoney WHERE hash = ?", {}, $pay{hash});
# Новый платёж
if (!$id) {
$dbh->do(
"INSERT INTO ymoney (operator, hash, data, amount, comment) VALUES ('yandex', ?, ?, ?, ?)", {},
$pay{hash}, DB_Date($pay{data}), DB_Amount($pay{amount}), $pay{comment}
);
}
}
}
sub DB_Date {
...
}
sub DB_Amount {
...
}