Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r9744: LJSUP-7346 (Put the tweet to lj_times tw...

Committer: ailyin
LJSUP-7346 (Put the tweet to lj_times twitter account)
U   trunk/bin/upgrading/en_LJ.dat
U   trunk/bin/worker/twitter-times
Modified: trunk/bin/upgrading/en_LJ.dat
===================================================================
--- trunk/bin/upgrading/en_LJ.dat	2010-11-22 09:16:56 UTC (rev 9743)
+++ trunk/bin/upgrading/en_LJ.dat	2010-11-22 10:04:05 UTC (rev 9744)
@@ -6209,6 +6209,8 @@
 
 twitter_times.status=#ljtimes #news In the meantime in LjTimes www.livejournal.com/ljtimes/
 
+twitter_times.status.19=#ljtimes #news The most recent blogosphere news www.livejournal.com/ljtimes/
+
 twitterconnect.untitled.comment=New comment at LiveJournal:
 
 twitterconnect.untitled.entry=New entry at LiveJournal:

Modified: trunk/bin/worker/twitter-times
===================================================================
--- trunk/bin/worker/twitter-times	2010-11-22 09:16:56 UTC (rev 9743)
+++ trunk/bin/worker/twitter-times	2010-11-22 10:04:05 UTC (rev 9744)
@@ -44,29 +44,40 @@
 }
 
 my @POST_TIMES;
+my %POST_MESSAGES;
 BEGIN {
-    @POST_TIMES = qw( 13:00 19:00 ); # 1PM and 7PM MSK
+    %POST_MESSAGES = (
+        '13:00' => 'twitter_times.status',
+        '19:00' => 'twitter_times.status.19',
+    );
+    @POST_TIMES = keys %POST_MESSAGES; # 1PM and 7PM MSK
 }
 
 # return the list of all timestamps in the current day we're supposed
 # to update Twitter on; timezone is Moscow time
 sub _today_post_timestamps {
     my ($class) = @_;
-    return map { $class->_hour_to_timestamp($_) } @POST_TIMES;
+    return map { $_ => $class->_hour_to_timestamp($_) } @POST_TIMES;
 }
 
 sub work {
     my ($class) = @_;
 
+    my $status = LJ::Lang::get_text('ru', 'twitter_times.status');
+
     # check that we're posting at the specified time
     # we actually give it a five minute leeway because workers
     # can lag
-    my @timestamps = $class->_today_post_timestamps;
+    my %timestamps = $class->_today_post_timestamps;
     my $time_correct = 0;
-    foreach my $ts (@timestamps) {
+    foreach my $hour (keys %timestamps) {
+        my $ts = $timestamps{$hour};
+
         next unless (time - $ts > 0 and time - $ts < 300);
 
         $time_correct = 1;
+        $status = LJ::Lang::get_text('ru', $POST_MESSAGES{$hour});
+
         last;
     }
 
@@ -79,8 +90,6 @@
     }
 
     # now, actually post
-    my $status = LJ::Lang::get_text('ru', 'twitter_times.status');
-
     my $res = LJ::Client::Twitter->call(
         'api_method' => 'statuses/update',
         'user' => LJ::load_user($LJ::TIMES_TWITTER_ACCOUNT),
@@ -101,7 +110,8 @@
 sub on_idle {
     my ($class) = @_;
 
-    my @timestamps = sort { $a <=> $b } $class->_today_post_timestamps;
+    my %timestamps = $class->_today_post_timestamps;
+    my @timestamps = sort { $a <=> $b } values %timestamps;
 
     # try to find some time to post today
     my ($next_post_time) = grep { $_ > time } @timestamps;

Tags: andy, dat, ljcom
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments