Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created August 6, 2011 09:06
Show Gist options
  • Save Shinpeim/1129201 to your computer and use it in GitHub Desktop.
Save Shinpeim/1129201 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Config::Pit;
use Net::Twitter::Lite;
use DateTime;
use Encode;
use utf8;
my $now = DateTime->now;
my $this_year = $now->year;
my $reset_time = DateTime->new(
year => $this_year,
month => 9,
day => 1,
hour => 0,
minute => 0,
second => 0,
nanosecond => 0,
time_zone => 'Asia/Tokyo',
);
#すでにリセットしてたら来年の値
if ($reset_time->epoch < $now->epoch) {
$reset_time = DateTime->new(
year => $this_year + 1,
month => 9,
day => 1,
hour => 0,
minute => 0,
second => 0,
nanosecond => 0,
time_zone => 'Asia/Tokyo',
);
}
my $rest_secs = $reset_time->epoch - $now->epoch;
my $rest_mins = int ($rest_secs / 60);
my $rest_hours = int ($rest_mins / 60);
my $rest_days = int ($rest_hours / 24);
my $show_hours = ($rest_hours % 24);
my $show_mins = ($rest_mins % 60);
my $conf = Config::Pit::get("twitter.com", require => {
'token' => "your access token on twitter",
'token_secret' => "your access token secret on twitter",
'consumer_key' => "your consumer key on twitter",
'consumer_secret' => "your consumer secret on twitter",
});
my $nt = Net::Twitter::Lite->new(
consumer_key => $conf->{consumer_key},
consumer_secret => $conf->{consumer_secret},
);
$nt->access_token($conf->{token});
$nt->access_token_secret($conf->{token_secret});
my $rest_time = "";
if ($rest_days != 0) {
$rest_time .= $rest_days . "日";
}
if ($show_hours != 0) {
$rest_time .= "と" if $rest_days != 0;
$rest_time .= $show_hours . "時間";
}
if ($show_mins != 0) {
$rest_time .= "と" if $rest_days != 0 && $show_hours == 0;
$rest_time .= $show_mins . "分";
}
eval { $nt->update("舞浜サーバーリセットまで、あと" . $rest_time . 'か…') };
die "$@\n" if $@;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment