Twitter Weekly Updates for 2010-09-20

Posted in twitter | Tagged , | Comments Off

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, twitter, Web | Tagged , , , , , | Comments Off

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