Posts Tagged ‘python’

Of limited utility

Saturday, February 6th, 2010

But it’s been amusing me in the airport, so have if you want it:

Python script that’ll grab a random message from your Gmail account

If you have an account that’s all old archived mail, it’s probably more entertaining.

Marking your new messages as read without having to go to Gmail in a browser

Friday, February 20th, 2009

I use Gmail Notifier. It absolves people of the need to constantly go to mail.google.com in a browser to see if they have new mail. If I have new mail, the mail icon in the menu bar will turn red, so I can forget about it.

The thing is, sometimes you get new mail that’s just not worth the effort of opening a browser tab. (Gmail Notifier gives you a summary of your new mail.) Yet if you don’t actually go into Gmail, those messages will still be considered new, and the Gmail Notifier icon in the menu bar will stay red.

It does not have a command that lets you tell it to ignore the recent new messages and change its icon back to gray. The red active notifier is surprisingly hard to ignore. So much so that I usually end up going to Gmail and clicking on each new message just so it won’t be counted as new, and the red icon will go away.
 

Well, not anymore. I put together a simple Python script that uses IMAP to log in and mark the new messages as read. If you want to use it and have Python installed, all you need to do is enable IMAP in your Gmail settings, edit the script to use your username and password, and then execute it whenever you want Gmail Notifier’s red icon to stop glaring at you.
 

markasread.py (Right-click to download.)
 
 

Sidebloggin’!

Monday, September 22nd, 2008

Well, the automated posting is back. I just couldn’t stay away from it. Except this time:
 

  • I’ve kept the link posts from del.icio.us and the Flickr posts out of the main weblog. They show up on the side.
  • They update every hour instead of each day.
  • Each link or picture is its own post, upon which you can comment.
  • They stay out of the main RSS feed, too. However, you can subscribe to a separate feed just for the sidebloggin’! If you’re into that kind of thing.

 
Because WordPress (understandably) as a really clunky way of posting by email (you have to send the email, then hit Wordpress to make it POP into the email account) and no documented REST interface, I ended up doing this using the Python mechanize module. It seemed hacky, but then I got over it.

Mechanize is pretty smooth, but unfortunately, the current nature of web forms is going to make it less useful, unless it extends to be able to execute javascript. Forms are generated now, and what’s generated is often pretty messy, with a lot of unnamed elements. That can be gotten around, though. The real problem is that, instead of having the form do the POST, submit buttons on forms are often just javascript triggers, and some javascript function creates the actual POST request.

This is what stopped me from extending my autoposting script to also drop the links into Facebook “Posted Items,” which also have no explicit API support. Then, even more people could have seen my links and my important opinions about them! I actually started to try to determine what kind of POST request the javascript in their “share on Facebook” bookmarklet generated, but then I thought: Wait. Why the hell am I doing this? And then, I stopped.