Posts Tagged ‘twitter’

How to create a Twitter API proxy using nginx in Cloud Foundry

Sunday, November 18th, 2018

In this post, Iโ€™ll describe how to run nginx in Cloud Foundry to provide a Twitter API proxy that includes authentication and caching.

First, I want to talk a bit about why I wanted this, but if you donโ€™t care about any of that, you can just skip to the code at the end of the post. ๐Ÿ™‚

Iโ€™ve wanted for a while to enable projects in Machine Learning for Kids that use tweets. Using live tweets is a great way to make text analytics real for students, and a good example of how natural language processing is used in the real world.

The question was how to enable this from Scratch in a way that would be easy to use by schools.

The title of this post gives away the answer I ended up with, but I’ll describe why.

(more…)

Annotating photos with tweets

Sunday, September 11th, 2011

I have a lot of digital photos.

An insane amount – something like 40,000 photos that go back over a dozen years since I first got a digital camera at University.

I store them based on the date that they were taken, using a folder structure like this:

screenshot of folder structure where I store photos

For a while, I used to drop a readme.txt text file into some of the folders saying where the photos were taken or what I was doing. This was partly so that when I look at the photos ten years later I’ve got something to remind me what is going on, but mainly to make it possible for me to search for photos of something when I can’t remember the date it happened.

But in recent years, I’ve been too lazy to keep that up, and rarely ever add a readme file.

I thought that my tweets might be a good alternative. There is a reasonable chance that if I took a photo of something interesting, that I might have tweeted sometime that day about where I am or what I’m doing.

I wanted to populate each of my folders with a day’s photos in it with a tweets.txt text file containing tweets posted on that day.

(more…)

Where did I meet you?

Tuesday, May 31st, 2011

a vcard importer for AndroidOverview

A bit of Android code to add comments to contacts imported from vCards to remind you how you know the person behind the vCard.

Background

Remember poken? (Actually, “remember” isn’t fair, because they’re still around. I’ve just not seen them in an age.)

If you don’t, they were key-fob-sized gadgets. When you met someone, you tapped your poken against theirs, and it would handle exchanging contact details. They were a geeky way to exchange business cards.

They suffered from a bootstrap problem, in that, finding anyone else with a poken to tap against often proved a challenge. But I digress…

What I loved about them was that it didn’t only store the contact details, but details about when you met.

(more…)

An API for twitter hashtags for TV programmes

Friday, December 31st, 2010

Overview
Hacking together an API that returns commonly-used hashtags for the programme you’re watching on the TV

Background
tweets on TVLast April, I wrote a quick-and-dirty Python script that displays tweets for a given hashtag on my TV screen so that I could follow the twitter backchannel about a programme that I watched.

Considering that it was a random idea that was hacked together in a few minutes, I’ve used it a lot since then: it’s made watching a bunch of programmes much more entertaining – Eurovision is probably the best example (the commentary on twitter is hysterical), but there are many others.

But I never made any changes to the script since I first wrote it. If I’m watching something on TV that I know has a hashtag, I ssh to my set-top box and run my hashtags script, giving it the hashtag to filter on in the command.

I was thinking – it’d be much better if it was all automatic. It’d be better if my set-top box automatically showed tweets with the hashtag for whatever programme I’m watching.

To do this, I needed some way of knowing what was the right hashtag for the programme currently on a given TV channel. I could’ve hacked this into my existing script, but I thought it might be a feature that people might find other uses for, so instead I’ve made a stand-alone thing, available as a web-service.

What it does
I’ve made a web feed that returns a blob of either JSON or XML. You can get either:

  • the commonly-used hashtag for the programme currently on a specified channel (e.g. “what is the hashtag for the programme that’s on BBC 1 now?”)
  • the next programme on TV that has a commonly-used hashtag (e.g. “what are the next five programmes on TV that have hashtags?”)

(more…)

Following twitter hashtags on TV

Tuesday, April 6th, 2010

DSC06104As a lot of other people, I’m watching the debate of the Digital Economy Bill on BBC Parliament tonight. I’m also trying to follow along with some of the #debill back-channel on twitter.

With such a heated and interesting commentary on twitter, it reminded me of Roo’s “Second screen” idea of having tweets with a specific hashtag next to the TV during live TV events, when following the twitter backchannel during ‘The Apprentice’.

Unfortunately, I don’t have a spare laptop kicking around to show tweets on. But I do have a hackable TV. ๐Ÿ™‚

With that in mind, in just a few minutes I hacked together the following script to flash up tweets with the #debill tag on the TV:

# run me using:
#       python twittertv.py debill 1

import twython
import subprocess
import sys
from time import sleep

twitterKeyword = sys.argv[1]
twitterSearchRateLimitMins = int(sys.argv[2])

twitter = twython.core.setup()

showOnTVCommand = ['svdrpsend', 'mesg', 'messagetodisplay']

lasttweetid = 1

while True:
    search_results = twitter.searchTwitter(twitterKeyword, since_id=lasttweetid, show_user=True)

    numtweets = len(search_results["results"])
    for tweetnum in reversed(range(0, numtweets)):
        lasttweetid = search_results["results"][tweetnum]["id"]

        user = search_results["results"][tweetnum]["from_user"]
        tweet = search_results["results"][tweetnum]["text"]
        showOnTVCommand[2] = user + " : " + tweet

        subprocess.Popen(showOnTVCommand)
        sleep(20)

    sleep(twitterSearchRateLimitMins * 60)

DSC06127

It’s a quick-and-dirty hack, but I wanted to get something that would work before the debate was finished. ๐Ÿ™‚

And it seems to do the trick.

Why I haven’t written TwitToday for Android

Thursday, February 25th, 2010

(or “looking at the limitations of the Android home screen widgets framework”)

Twitter client for Windows MobileA couple of years ago, I wrote a Windows Mobile app called TwitToday : a Twitter widget for the “Today screen” (the default screen when the phone is on, with all apps closed or minimised).

The rationale was that it was useful to have a way to post a tweet quickly when you don’t want to have to wait for a full-blown client to start.

Or if you don’t want to incur the battery or memory cost of leaving a client running all the time.


A widget that doesn't work on AndroidAndroid has a “Home screen”, which is similar to the Today screen on Windows Mobile. And it has support for widgets. This led several people to ask me why I never ported TwitToday to Android.

The short answer is that I did try, but the current state of the widgets framework made it impossible.

I tried to write a TwitToday widget back when the Android widgets framework was first introduced in Android 1.5.

It all started quite well:

  1. I wrote the Android Service that would carry out the background task of posting a tweet. No problems there – it worked fine.
  2. I wrote the widget XML to define the GUI. This is what you can see running in the screenshot. And it works… sort of. It has a text box that you can type up to 140 characters into. And if you press the button, it causes a chunk of code to get invoked.

The problem came when I tried to link the two together: to get the Service that posts tweets to obtain the String from the text box in my widget.

This isn’t possible. Android’s widget framework as it currently stands is geared around displaying information to the user, not collecting user input.

(more…)

What happened to the integration?

Tuesday, November 17th, 2009

A bunch of social networking updates arrived tonight for the Xbox 360. There has been talk of twitter integration in the Xbox 360 since E3 last summer. And after all the wait… I was a little disappointed.

Because it isn’t integration.

It’s a simple stand-alone twitter client app, that you can run on the Xbox. It joins the main menu becoming something else you can run, instead of play a game or media.

That’s not integration.

If they’d added the ability to receive replies/mentions and direct messages through the Xbox messaging platform while you’re in a game (as it does already with MSN Messenger messages)… that would be integrated.

If they’d built it in to Xbox’s Achievements system, so that when you complete an achievement it offered the chance to let your followers know what you’ve achieved… say by popping up a text box prefilled with a message and a link to more info about the game you’re playing… that would be integrated.

If they’d added the ability to capture a screenshot of what you’re doing, upload it to twitpic (or some similar service) and tweet to show your followers something cool… that would be integrated.

If they’d added the chance to see compare your twitter friends list with your Xbox friends list, and add any that aren’t on both… that would be integrated.

If they’d included a twitterfone-type service to let you tweet without typing, just by talking into the Xbox headset… that would be integrated.

I’m not saying that any of these are good ideas (they’re just the first few things off the top of my head), but the point is that this sort of thing would make twitter feel like it has been integrated into the “Xbox Experience“.

(more…)

Improvements to TwitToday

Wednesday, June 10th, 2009

I’ve been doing too much Java at work recently, so in the interest of keeping my hand in with some low-level C++, I picked up the code for my mobile twitter client, TwitToday, again.

I originally wrote it at a hackday, but I’ve since come back to tweak it a couple of times to get it to spawn background worker threads, add SIP on-screen keyboard support, and improve support for sending special and accented characters.

After another evening of tweaking, I’ve added a few new minor features:

Transparent text box

When not in use, the text box is now transparent. When it has focus, it is coloured in white as usual.

A few people commented that a bright white text box could dominate a dark Today screen too much, so this is hopefully a nice aesthetic improvement.

I did this by creating a custom windows procedure for the text box.

The windows procedure needed to handle a couple of events:

Handling WM_PAINT by using SetBkMode to make the text box TRANSPARENT

Handling WM_ERASEBKGND by using TODAYM_DRAWWATERMARK to draw the background over the text control’s rectangle.

(more…)