Xu Xiaodong avatar Xu Xiaodong committed c5ee62f

initial commit

Comments (0)

Files changed (5)

+Some useful scripts for Conky.
+
++ forecast.pl: weather forecast
++ ggadcheck.pl: check Google Adsense revenue
++ gmailcount.pl: gmail unread count
++ greadercount.pl: greader unread count
+#!/usr/bin/env perl
+#
+# name:      weather forecast for conky
+# author:    Xu Xiaodong <xxdlhy@gmail.com>
+# license:   GPL
+# created:   2011 Mar 29
+# modified:  2011 Apr 13
+#
+
+use Modern::Perl;
+use HTTP::Tiny;
+use XML::Twig;
+
+my $http = HTTP::Tiny->new;
+my $url  = 'https://www.google.com/ig/api?weather=Nanchong';
+my $xml  = $http->get($url)->{content};
+
+my $twig = XML::Twig->new;
+$twig->parse($xml);
+
+my $condition = $twig->first_elt('condition')->att('data');
+my $temp      = $twig->first_elt('temp_c')->att('data');
+
+say "$temp° $condition";
+#!/usr/bin/env perl
+#
+# name:      check Google Adsense revenue
+# author:    Xu Xiaodong <xxdlhy@gmail.com>
+# license:   GPL
+# created:   2011 Feb  7
+# modified:  2011 Apr 13
+#
+
+use Modern::Perl;
+use LWP::UserAgent;
+use HTTP::Cookies;
+
+my $username = '';
+my $password = '';
+
+my $ua = LWP::UserAgent->new( cookie_jar => HTTP::Cookies->new() );
+
+my $google_account = $ua->get(
+    'https://www.google.com/accounts/ServiceLoginBoxAuth', {
+        continue => 'https://www.google.com/adsense/login-box-gaiaauth',
+        foolowup => 'https://www.google.com/adsense/login-box-gaiaauth',
+        service  => 'adsense',
+        ltmpl    => 'login',
+        rm       => 'false',
+        Email    => $username,
+        Passwd   => $password,
+        null     => 'Login'
+    }
+);
+
+my ($galx)
+    = $google_account->as_string =~ m{name="GALX"\s+value="([^"]+)">}msg;
+
+my $google_adsense = $ua->post(
+    'https://www.google.com/accounts/ServiceLoginBoxAuth', {
+        continue => 'https://www.google.com/adsense/login-box-gaiaauth',
+        foolowup => 'https://www.google.com/adsense/login-box-gaiaauth',
+        service  => 'adsense',
+        ltmpl    => 'login',
+        rm       => 'false',
+        Email    => $username,
+        Passwd   => $password,
+        GALX     => $galx,
+        null     => 'Login'
+    }
+);
+
+if ( $google_adsense->as_string =~ /CheckCookie/ ) {
+    $google_adsense
+        = $ua->get(
+        'https://www.google.com/accounts/CheckCookie?continue=https://www.google.com/adsense/login-box-gaiaauth&service=adsense&ltmpl=login&chtml=LoginDoneHtml'
+        );
+    if ( $google_adsense->as_string =~ /SetSID/ ) {
+        my ($uri)
+            = $google_adsense->as_string
+            =~ /Refresh:\s+\d+;\s*url\='([^']+)'/;
+
+        $google_adsense = $ua->get($uri);
+    }
+}
+
+my $balance = quotemeta('今日估算收入');
+my $income;
+if ( $google_adsense->as_string =~ /$balance.*?(\d+\.\d+)/s ) {
+    $income = $1;
+}
+
+my $google_adsense_thismonth = $ua->get(
+    'https://www.google.com/adsense/report/overview?timePeriod=thismonth');
+
+my $balance_thismonth = quotemeta('估算总收入');
+my $income_thismonth;
+if ( $google_adsense_thismonth->as_string
+    =~ /$balance_thismonth.*?(\d+\.\d+)/s )
+{
+    $income_thismonth = $1;
+}
+
+my $google_adsense_sincelastpayment
+    = $ua->get(
+    'https://www.google.com/adsense/report/overview?timePeriod=sincelastpayment'
+    );
+
+my $balance_sincelastpayment = quotemeta('估算总收入');
+my $income_sincelastpayment;
+if ( $google_adsense_sincelastpayment->as_string
+    =~ /$balance_sincelastpayment.*?(\d+\.\d+)/s )
+{
+    $income_sincelastpayment = $1;
+}
+
+say "$income/$income_thismonth/$income_sincelastpayment";
+#!/usr/bin/env perl
+#
+# name:      gmail unread count for conky
+# author:    Xu Xiaodong <xxdlhy@gmail.com>
+# license:   GPL
+# created:   2011 Feb  7
+# modified:  2011 Apr 13
+#
+
+use strict;
+use warnings;
+
+use Mail::IMAPClient;
+
+# Account information
+my $user = '';
+my $pass = '';
+
+# Gmail unread count
+my $imap = Mail::IMAPClient->new(
+    Server   => 'imap.gmail.com',
+    User     => $user,
+    Password => $pass,
+    Port     => 993,
+    Ssl      => 1,
+);
+
+my $gmail_count = $imap->unseen_count('Inbox') || 0;
+
+$imap->logout();
+
+# Output result
+print $gmail_count;
+#!/usr/bin/env perl
+#
+# name:      google Reader unread count for conky
+# author:    Xu Xiaodong <xxdlhy@gmail.com>
+# license:   GPL
+# created:   2011 Feb  7
+# modified:  2011 Apr 13
+#
+
+use strict;
+use warnings;
+
+use WebService::Google::Reader;
+
+my $user = '';
+my $pass = '';
+
+my $gr = WebService::Google::Reader->new(
+    username => $user,
+    password => $pass,
+    https    => 1,
+);
+
+my $unread = $gr->unread( count => 1000 );
+my $count = defined $unread ? $unread->entries : 0;
+
+print $count;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.