Tweeting MythTV events in the new OAuth era

The mythtv wiki has a few scripts for tweeting MythTV stuff to twitter; although they all relied upon Basic Auth. until recently.

Taking a leaf out of Twitter Tools‘ book it’s possible to convert the LWP::UserAgent-based code to do OAuth.

Before:

#!/usr/bin/perl
use LWP::UserAgent;
my $output = shift;
my $browser = LWP::UserAgent->new;
my $url = 'http://twitter.com/statuses/update.json';
$browser->credentials('twitter.com:80', 'Twitter API', 'username', 'password');
$response = $browser->get("http://twitter.com/account/verify_credentials.json");
my $response = $browser->post($url, {status => $output});

First step is registering an App. at dev.twitter.com, so that you’ve got the necessary authentication keys to do OAuth directly with an access token.

See also: http://wphelpcenter.com/plugins/twitter-tools/

Secondly, you’ll need a means of performing OAuth in perl, I chose Net::Twitter:OAuth, the 0.02 version page‘s example forming the basis for the simplest twitter.pl upgrade.

After:

#!/usr/bin/perl
use Net::Twitter::OAuth;
my $client = Net::Twitter::OAuth->new(
consumer_key => "",
consumer_secret => "",
);
my $output = shift @ARGV;
# $client->oauth_token('', '');
# DEPRECATED: use access_token and access_token_secret instead at ./oauth-mtv-tweet.pl line X
$client->access_token('');
$client->access_token_secret('');
my $res = $client->update({ status => $output });

The more complex twitter.pl script can be upgraded in much the same way:

After:
#!/usr/bin/perl
#use LWP::UserAgent;
use Net::Twitter::OAuth;
my $client = Net::Twitter::OAuth->new(
consumer_key => "xxxxxxxxxxxxxxxxxx",
consumer_secret => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
);
$client->access_token('xxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$client->access_token_secret("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
#
use DBI;
use DBD::mysql;
use MythTV;
#
my $connect;
my $debug = 0;
my $title="";
my $subtitle="";
my $newsubtitle="";
my $starttime="";
my $chanid="";
#
##################################
# #
# Main code starts here !! #
# #
##################################
#
my $usage = "\nHow to use twitter.pl \n\ twitter.pl starttime=%STARTTIME% chanid=%CHANID% debug\n"
."\n%CHANID% = channel ID associated with the recording\n"
."%STARTTIME% = recording start time in either 'yyyy-mm-dd hh:mm:ss' or 'yyyymmddhhmmss' format\n"
."debug = enable debugging information - outputs which commands would be run etc\n";
#
# get this script's ARGS
#
#
my $num = @ARGV;
#
# if user hasn't passed enough arguments, die and print the usage info
#
if ($num le "1") {
die "$usage";
}
#
#
# Get all the arguments
#
#
foreach (@ARGV){
if (/debug/) {
$debug = 1;
}
elsif (/starttime/) {
$starttime = (split(/=/))[1];
}
elsif (/chanid/) {
$chanid = (split(/=/))[1];
}
}
#
# connect to backend
my $myth = MythTV->new;
# connect to database
my $connect = $myth->{dbh};
#
my $query = "SELECT name FROM channel WHERE chanid=$chanid";
my $query_handle = $connect->prepare($query);
$query_handle->execute or die "Unable to query channel table";
#
my ($channame) = $query_handle->fetchrow_array;
#
$query = "SELECT title, subtitle, endtime FROM recorded WHERE chanid=$chanid and starttime='$starttime'";
$query_handle = $connect->prepare($query);
$query_handle->execute or die "Unable to query settings table";
#
$query_handle->bind_columns(undef, \$title, \$subtitle, \$endtime);
$query_handle->fetch;
#
if ($subtitle)
{
$newsubtitle = " - ".$subtitle;
}
#
my $output = "Finished recording $title $newsubtitle from $channame at $endtime";
print "Chanid $chanid \n";
print "Starttime $starttime \n";
print "$output \n";
#
unless ($debug)
{
#
my $res = $client->update({ status => $output });
#
}

Posted in MythTV, Web, twitter | Tagged , , , , , | Leave a comment

Yes, this IS getting boring

Upgraded most of the short linking I’ve been doing outside wordpress/la-petite-url to use yourls; except, of course, that a quick bit of sql didn’t translate everything.

The MySQL

insert into yourls_url select key1, target, timestamp(concat(year, '-', month, '-',day, ' 12:00:00')), '10.0.0.1', clicks from shorty_shorties;

The Problem
One shorty link was hyphenated, not something yourls allows.

So, some .htaccess hackery required, again …

RewriteRule ^([0-9A-Za-z-]+)-([0-9A-Za-z-]+)?/?$ /yourls-go.php?id=$1$2 [L]

Posted in Web | Tagged , , | Comments Off

“Fix”ing WordPress database tables

After restoring tables from a WP mu backup (an incomplete one as it turned out) various issues presented themselves, not least an inability to submit posts (HTTP 500 not informative).
A little searching revealed a likely cause (http://discuss.joyent.com/viewtopic.php?id=19116): missing auto_increment on wp_{n}_posts; not only was auto_increment missing, indexes and keys were too. Later I found a hiccup in tagging, again wp_{n}_terms and related tables had missing metadata.

Fixes

Removing erroneous entries added by admin-ajax.php

delete from wp_{n}_posts where ID = 0 and post_modified = 'YYYY-MM-DD hh:mm:ss';

Add primary index before restoring auto_increment

alter table wp_{n}_posts add primary key (ID);
alter table wp_{n}_posts change ID `ID` bigint(20) unsigned NOT NULL auto_increment;

Add remaining keys

alter table wp_{n}_posts add key post_name (post_name);
alter table wp_{n}_posts add key type_status_date (post_type, post_status, post_date, ID);
alter table wp_{n}_posts add key post_parent (post_parent);

Future backups

mysqldump --opt wordpress > wordpress.sql

Just using –add-drop-table insufficent in some cases.

Posted in Web | Tagged , , | Comments Off

Moo!

From sxc.hu - Marijnvb - Cow portrait

This blog and shopping.chrs.nl are now running as sub-blogs of a WordPress MU install, if there’s anything wonky going on here, that’s why.
Talking of moo; moo.com ( UK | US ) do very nice printing.

Posted in Web | Tagged | Comments Off

Vanity: A “no, this blog isn’t just about shorturls” post on shorturls

Last Saturday, I woke up with a seemingly brilliant idea, a dot-st domain name for use by my online postage half-site Print My Postage, mypo.st was subsequently registered. However, this isn’t about that; I was on skype telling Brian (King) about this and mused that bri.ks would be a good vanity shortener for briks.si his mozilla software development collective. Unfortunately, Kosovo’s dot-ks doesn’t actually exist; fortunately Kazakhstan’s dot-kz does. I proposed that Brian and briks.si should have their own shortener under bri.kz, with briks.si/! as the install location; why use one of the virtual servers of the hosting account purely for bri.kz, when it’s all the same server.

Now on cdn: How not to register a dot-kz domain.

The fun really started after YOURLS was installed to handle the shortener system, first question: “where to register bri.kz?”, I went down the list of registrars at KazNIC (nic.kz) trying to find one with English as a language option (Cyrillic is bewildering), I settled on http://www.regtime.net/ (.kz 550 rubels per year roughly $20 in Jan 2010), although their https certificate turned out to be webnames.ru (Firefox mismatch warning good for your sanity).

Find your own dot-kz domain(s):

www.

It turned out, that to pay the registration fee to webnames.ru I needed to use a web currency; I chose WebMoney’s WMZ [USD equivalent], signed up for an account (wmtransfer.com) only to find that I needed another account elsewhere to fund the WMZ purse at WebMoney from my credit card.

Note: this is past midnight, so now early Sunday morning.

Off to savechange.ru, signup, login, fill in WMZ purse number.

Liqpay using Ukrainian bank with MasterCard SecureCode whatsit for verification still wanted to verify me, pending micropayments to card no good since only tracked in GBP what with Liqpay wanting USD, so I talked to Liqpay who eventually talked to my card bank, Liqpay authorised payment, savechange converted it from USD to WMZ and I was able to pay the webnames invoice

Technical

root .htaccess sends bri.kz traffic to briks.si/! which sends it to YOURLS to handle

/.htaccess, mod_rewrite [P] no good all referrers briks.si itself; basic redirect, again no good, no referrers at all; solution [E ..] set environment variable between redirects.

RewriteCond %{HTTP_HOST} ^bri\.kz$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) http://briks.si/!/$1 [E=HTTP_REFERER:%{HTTP_REFERER}]

Posted in Web, twitter | Tagged , , , , , , , , , , , , | Leave a comment

Migrants

This [short] blog post should be coming to you from a Shared Accelerator at Joyent running Solaris; rather than the obsolescent FreeBSD server it used to be served from … there was no rush for a Golden Ticket – let everyone else find all the problems first :)

Posted in Uncategorized, Web | Tagged , | Leave a comment

Twitter Weekly Updates for 2009-10-19

Powered by Twitter Tools

Posted in twitter | Tagged , | Leave a comment

Twitter Weekly Updates for 2009-10-12

Powered by Twitter Tools

Posted in twitter | Tagged , | Leave a comment

Twitter Weekly Updates for 2009-09-27

Powered by Twitter Tools

Posted in twitter | Tagged , | Leave a comment

la petite url 1.5.1

Seems changes like mine have ended up in la petite url, github didn’t have them last time I looked, it was still at 1.5…

Posted in Web, twitter | Tagged , , , , , , , | Leave a comment