Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- $|++;
- use strict;
- use warnings;
- use Data::Dumper;
- use lib '../lib/';
- use WWW::Tumblr;
- use PerfectWord::Schema;
- use JSON;
- my $schema = PerfectWord::Schema->connect('dbi:Pg:host=localhost;dbname=perfectword', 'postgres', '');
- my $boob = $schema->resultset('Boob');
- my $rs = $boob->search( {
- site_id => 1
- });
- my $last_tm = $rs->get_column('unix_timestamp')->max();
- my $last_id = $rs->search( {'unix_timestamp' => $last_tm} )->get_column('tumblr_id')->max();
- # read method
- my $t = WWW::Tumblr->new;
- $t->user('awesometits');
- my $loops = 0;
- while ($loops < 1){
- my $json = $t->read_json(
- start => 0,
- num => 1,
- type => 'photo'
- );
- #print "\n$json\n";
- $json =~ s/.+?\{/{/o;
- $json =~ s/};/}/o;
- # my $json;
- # do{open(my $x, '<', 'cache.json'); undef($/);undef($\); $json = <$x> };
- #print "\n$json\n";
- my $obj = from_json($json);
- foreach my $img (@{$obj->{posts}}){
- my $size = 'photo-url-1280';
- $size = 'photo-url-url' unless ($img->{$size});
- last if ($img->{'unix-timestamp'} < $last_tm || $img->{'id'} == $last_id);
- my $boob_data = {
- site_id => 1,
- tumblr_id => $img->{id},
- image_url => $img->{$size},
- unix_timestamp => $img->{'unix-timestamp'}
- };
- print ('ID ' . $img->{id} . ' => [' . $img->{'unix-timestamp'} . '] ' . $img->{$size} . "...\n");
- $boob->create($boob_data);
- }
- # print Dumper $obj;
- $loops++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement