#!/usr/bin/perl | |
# $Id: fgtw3.pl,v 1.4 2015/10/08 21:28:29 yath Exp $ | |
# | |
# ---------------------------------------------------------------------------- | |
# "THE BEER-WARE LICENSE" (Revision 42): | |
# <marcel@rucksackreinigung.de> wrote this file. As long as you retain this | |
# notice you can do whatever you want with this stuff. If we meet some day, | |
# and you think this stuff is worth it, you can buy me a beer in return | |
# ---------------------------------------------------------------------------- | |
use local::lib; | |
use Net::Twitter; | |
use Date::Manip; | |
use feature "say"; | |
use strict; | |
use open qw<:encoding(UTF-8) :std>; | |
use warnings; | |
use Data::Dumper; | |
my $MAXDAYS=1; | |
my $nt = Net::Twitter->new( | |
traits => [qw/API::RESTv1_1/], | |
consumer_key => "foo", | |
consumer_secret => "bar", | |
access_token => "baz", | |
access_token_secret => "qux", | |
ssl => 1, | |
); | |
sub check_status_age { | |
my ($max_id, $list, $destroy, $day_cap) = @_; | |
my $timeline; | |
if ($max_id >0){ | |
$timeline = $nt->$list({count => 100, max_id => $max_id}); | |
}else{ | |
$timeline = $nt->$list({count => 100}); | |
} | |
my $status_ammount = @$timeline-1; | |
if ($status_ammount == 0) { return }; | |
my $today = time; | |
for my $status (@$timeline){ | |
my %element = %$status; | |
my $date = UnixDate($element{'created_at'}, '%s'); | |
my $days = ($today-$date)/86400; | |
my $maxage = $status->{retweeted} ? $MAXDAYS : | |
($MAXDAYS + $status->{favorite_count}*0.8 + $status->{retweet_count}*1.2); | |
$maxage = $day_cap if $day_cap and $maxage > $day_cap; | |
if ($days >= $maxage) { | |
my $tries = 0; | |
local $, = "|"; | |
say 3, $list, time, $date, $status->{user}->{screen_name}, $maxage, $status->{favorite_count}, $status->{retweet_count}, $status->{text}; | |
while ($tries++ < 3) { | |
eval { | |
$nt->$destroy($element{'id'}); | |
}; | |
if ($@) { sleep 5; } else { last; } | |
} | |
} | |
} | |
my $tmp = @$timeline[$status_ammount]; | |
exit 0 unless $tmp; | |
my %last = %$tmp; | |
check_status_age($last{id}, $list, $destroy, $day_cap); | |
} | |
check_status_age(0, 'user_timeline', 'destroy_status'); | |
check_status_age(0, 'favorites', 'destroy_favorite', 3); | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment