Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #!/usr/bin/perl
  2. $|++;
  3.  
  4. use strict;
  5. use warnings;
  6. use Data::Dumper;
  7.  
  8. use lib '../lib/';
  9. use WWW::Tumblr;
  10. use PerfectWord::Schema;
  11. use JSON;
  12.  
  13. my $schema = PerfectWord::Schema->connect('dbi:Pg:host=localhost;dbname=perfectword', 'postgres', '');
  14. my $boob = $schema->resultset('Boob');
  15. my $rs = $boob->search( {
  16. site_id => 1
  17. });
  18. my $last_tm = $rs->get_column('unix_timestamp')->max();
  19. my $last_id = $rs->search( {'unix_timestamp' => $last_tm} )->get_column('tumblr_id')->max();
  20.  
  21. # read method
  22. my $t = WWW::Tumblr->new;
  23.  
  24. $t->user('awesometits');
  25.  
  26. my $loops = 0;
  27. while ($loops < 1){
  28.  
  29. my $json = $t->read_json(
  30. start => 0,
  31. num => 1,
  32. type => 'photo'
  33. );
  34. #print "\n$json\n";
  35. $json =~ s/.+?\{/{/o;
  36. $json =~ s/};/}/o;
  37.  
  38.  
  39. # my $json;
  40. # do{open(my $x, '<', 'cache.json'); undef($/);undef($\); $json = <$x> };
  41.  
  42. #print "\n$json\n";
  43. my $obj = from_json($json);
  44. foreach my $img (@{$obj->{posts}}){
  45. my $size = 'photo-url-1280';
  46. $size = 'photo-url-url' unless ($img->{$size});
  47. last if ($img->{'unix-timestamp'} < $last_tm || $img->{'id'} == $last_id);
  48.  
  49. my $boob_data = {
  50. site_id => 1,
  51. tumblr_id => $img->{id},
  52. image_url => $img->{$size},
  53. unix_timestamp => $img->{'unix-timestamp'}
  54. };
  55.  
  56. print ('ID ' . $img->{id} . ' => [' . $img->{'unix-timestamp'} . '] ' . $img->{$size} . "...\n");
  57. $boob->create($boob_data);
  58.  
  59. }
  60.  
  61. # print Dumper $obj;
  62.  
  63. $loops++;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement