Archive for the ‘Scripts’ Category

OAuth PHP Twitter Class

Tuesday, June 22nd, 2010

After posting my temporary twitter unfollow script the other week I was reminded that Twitter is supposed to be dumping basic auth (sending user name and password in each request to Twitter) this month in favour of the more secure, widely adopted Open Authentication. It turned out Twitter has postponed what they have dubbed the “oauthcalypse” due to the world cup but if you haven’t already, now is the time to get rid of your neat little one-line curl scripts using basic auth (a shame I know but it’s for the best) and find an OAuth alternative in the language of your choice.

I have created a simple TwitterClient class (available under SVN) based on my previous set of basic auth and curl-using functions from a couple of years back. I have left it with my app key in their on purpose, so tweets from it will appear to come from “Strawp’s PHP lib”. Register your own app if you want and use those instead, of course. On the first use of a method you will be prompted to authenticate the class against your twitter login. The secret keys will then be stored in your home folder.

Example usage:

include( "twitter.class.php" );
$tw = new TwitterClient();
$tw->tweet( "I am using oAuth now!" );

The unfollow script has also been updated to use this class.

Temporary Twitter unfollow script

Thursday, May 27th, 2010

Update: This now uses the oAuth Twitter class, not the basic auth function library.

Do you ever get people you follow on Twitter who, for some reason have suddenly become really spammy? Normally they’re great, but maybe one evening they’ve come back drunk and are vomiting tweets all over their feed, or maybe they’re live-tweeting some inane reality TV show for the opening night or are taking part in an incredibly uninteresting meme hashtag.

Whatever the reason, you don’t want to ditch them entirely, just until they’ve stopped blabbing on about stuff you don’t care about.

So I made a command line script to get around this. If you want to temporarily unfollow someone, write:

unfollow mrspammy for 1 week

or for several users:

unfollow mrspammy,mrsspammy,mrspammystennispartner for 4 days

Due to the genius of of PHP’s strtodate(), the words after “for” can be pretty much any time period phrase that works with the “+” modifier from the current date. You can also specify exact dates:

unfollow mrspammy until next tuesday

or

unfollow mrspammy until 12 july

This then looks at users that were previously unfollowed, checks if you want to re-follow them by now and does so if required. Run it without specifying any unfollows to just get this behaviour. This means you can also put unfollow in cron (or whatever) to run periodically and it will automatically check if users need re-following by now.

This is written for Ubuntu. Any Linux will be OK, Mac too probably if you have the paths set up properly. You might even get it working under Windows.

To get it working, you need

  1. My Twitter library under svn
  2. The unfollow script
  3. PHP installed with libcurl

Put the PHP files in the same folder. You then need to:

  1. Edit $confpath in unfollow
  2. Create twitter.conf.php, containing two define() statements with TWITTER_EMAIL and TWITTER_PASSWORD in. These should contain your username and password.
  3. chmod u+x unfollow
  4. optional: Add unfollow to crontab to run at whatever interval you want
  5. optional: make this folder part of path, symlink to unfollow or in some way make unfollow callable without defining the entire path

And you’re good to go. Easy ;)

Let me know if you end up using this or my twitter library at all.

Geeking out with diagrams in ASCII

Thursday, November 5th, 2009

Last week I discovered ditaa and I can’t quite leave it alone. If you don’t understand why creating flow charts in plain ASCII is awesome, stop reading now.

Basically, you can take something like the Hey Jude flow chart, marked up in ASCII and convert it into a proper version. If your face is doing this: O_o, seriously stop reading now.

I marked that last one up in JavE, which is fine for ASCII art but a bit laborious if you want to build a diagram. On the ditaa home page there’s a link to a screencast of the perl app, Asciio (App::Asciio on CPAN) which is almost perfect. With a couple of tweaks to the /setup/stencils/asciio file, changing all the corners to the ‘+’ character and then another tweak to setup/actions/file.pl to automatically create flat txt and native asciio versions of the diagram, then calling ditaa in the background on the txt file to build a neat PNG version.

I now have a Visio-lite system that can create data flow diagrams suitable for both source code headers and also pasting into more formal documents. So… yeah. How was your week.

If anyone else is this nuts, let me know in the comments.

New Facebook to GCal Greasemonkey script

Thursday, December 11th, 2008

I’ve been using the original Facebook to Google Calendar script since it was first launched but for whatever reason the redesigns of Facebook seemed to run away from the original author and it stopped working properly so I decided to branch my own version.

v1.0.0 is largely untested and in “works for me” stage so try it out and give feedback!

Note that you may need to refresh the event page in order for the script to kick in because of how Facebook now loads pages in using AJAX.

I finally *get* Yahoo Pipes

Thursday, October 30th, 2008
Yahoo Pipes screenshot

Creating pipes is a bit of a mental leap from traditional programming.

I noticed Yahoo Pipes pretty soon after it launched nearly two years ago but other than aggregating RSS feeds I couldn’t really get into it. The visual psuedo-flow-diagram programming didn’t gel with me at all and I just found myself thinking I could have more easily achieved the same results in less time in PHP.

Well, after chatting with the Yahoo Developers booth at FOWA the other week and this week failing to find a decent UK Xbox 360 release calendar in iCal format I decided to have another crack using the messy data on Gamestation’s website as a source. The result: Gamestation XBox 360 releases. I’ve also created a conversion script in PHP to make that data iCal compatible and therefore importable into pretty much any calendaring system you’d care to mention.

If you’re used to writing screen scraping software in a real programming language there are a few mental barriers you have to clear in order to get anywhere:

  1. There is no regexp “match” function. You have to use substitute if you want to extract a term and make sure you “.*” at either end of it to remove unwanted text.
  2. You have to program loops one after the other instead of nesting logic all inside one big loop. Makes it a very odd thing to read.
  3. Multiline regexps are a headache to write because you have a single-line regexp input. I got around this by making a multi-line string single line with “s/[\r\n]/” before doing proper regexp operations
  4. It’s really quite buggy. Under Firefox in windows drag and drop operations would stop working after a while and under Firefox in Ubuntu after a while the whole edit area would turn into a bit of a mess. Save frequently.

Anyway, it’s pretty good once you get your head around it and it outsources some of the heavy lifting involved in screen-scraping to Yahoo instead of your own site. I’d like to see the ability to export in iCal format as standard in future updates.

New SVN repo: PHP Libraries

Wednesday, September 10th, 2008

Just added a new repository to the site: PHP Libraries. Currently in there are working classes or functions for:

  • Firefly Media Server – a class for direct access to the songs database
  • Roku Client – a client for Roku music players like the Soundbridge. Allows remote scripting etc
  • twitter – a bunch of functions for posting to, or getting info from a twitter account
  • Delicious – a class for (currently only) getting delicious bookmarks. Will add other methods if/when they’re needed for other scripts.

And there’s a ping.fm class in there that I might work on if I can be bothered to get an App key for it.

Head to svn.strawp.net/lib to browse them, svn co http://svn.strawp.net/lib to check the lot out.

Update: Just added svn.strawp.net/scripts/ which currently just has my twitter command line client in it.

My Twitter client available for download

Thursday, June 26th, 2008

Somebody out there wants it, so here it is

Update: I’ve moved this to the SVN server. To get them:

  1. svn co http://svn.strawp.net/scripts/tw
  2. svn co http://svn.strawp.net/lib/twitter.php
  3. chmod u+wrx tw
  4. make sure TWITTER_EMAIL and TWITTER_PASSWORD are defined

“tw h” for help text.

My CLI client gets its own ascii Fail Whale

Thursday, June 26th, 2008

I’ve been using my own PHP-based CLI Twitter client pretty much since signing up (the Twitter API is so simple). You can view your timeline, tweet, view replies and view and send direct messages all via the command line, and I’ve just added the now-famous Fail Whale image to the error output, see this screenshot for an example.

The source isn’t published at the moment, but if you want it I’ll clean it up (take out my hard-coded username and password) and upload it – just leave a comment.

The whale is based on this one which I turned into my own version reversed with added twitter birdies.

DRM, shmee-RM

Monday, June 9th, 2008

Looks like I overestimated the file encryption entirely on the last BBC update. Fortunately some people still had their own “clear” versions of some programs which they could compare directly with the newly encrypted downloads, noticing that what some of us thought was a DRM scheme was actually just a simple XOR of the video stream with two repeating bytes. A quick perl script later and P Lewis, posting on Paul’s blog had a working video file just like the old scripts produced.

P Lewis has since incorporated this update into a really nice full featured script for browsing and downloading video from iPlayer.

I really hope this update wasn’t what the iPlayer team were doing for the last couple of months. Bloody waste of license payer’s cash if it was.

iPhone iPlayer hole gets DRM’d (no, properly this time)

Friday, June 6th, 2008

It’s looking like files downloaded from the iPhone iPlayer interface are now unplayable on devices other than the iPhone. Previously this was wide open to allow anyone to download Quicktime (H.264) video over HTTP directly from the site, but it now appears that although the video can still be downloaded it is encrypted (probably with Fairplay DRM).

More technical details on the Wiki as they come in.

(See also Paul Battley’s blog)