Ian Sinke

Posts Tagged ‘Programming’

How the Recommended Reading Feature Works

In Internet, Recommended Reading, Software on Thursday, April 10, 2008 at 11:04 am

I recently introduced a new feature: Recommended Reading. My goal for this feature was to be able to take a list of my favorite blog posts from Google Reader and automatically post them to my blog with a python script. The way I eventually implemented this was by ripping the Atom feed from my Google Reader Shared Items Page, take each item in it and format it as a <ul>, and then post it to my blog using XMLRPC/metaWebLog. Here’s the script, commented for your reading pleasure.

# Import a bunch of things we'll need.
# feedparser is from http://www.feedparser.org/
import feedparser
import time
import xmlrpclib
from xml.dom import minidom
from pprint import pprint

# Defines how to post to the blog.
def blogPost( server, username, password, date, title, content ):
datastruct = {'pubDate': date, 'description':content, 'title':title}
returncode = server.metaWeblog.newPost('1',username,password,datastruct,1)
print returncode

# Initialize some details.
# You would need to put your real blog url, username, and password here, though.
servname = xmlrpclib.Server("http://iansinke.wordpress.com/xmlrpc.php")
username = 'xxxxx'
password = 'xxxxx'

# Check to make sure it's working.
pprint(servname.system.listMethods())

# Set up the post data.
Title = "Recommended Reading"
Date = ""
Content = ""

# Parse the feed.
# You would need to replace the URL with your google reader account's \
# shared page URL, or some other RSS or Atom feed.
f = feedparser.parse("http://www.google.com/reader/public/atom/user/15838963114361614548/state/com.google/broadcast")
ontent = Content + '<p>(Every Friday, I post my favorite blog posts of the week under the title "Recommended Reading".)</p>'
Content = Content + '<ul>'
for item in f.entries:
Content = Content + '<li><a href="' + item.link + '">' + item.title + '</a></li>'
Content = Content + '</ul>'
Content = Content + '<p> </p>'

# Post to the blog.
blogPost(servname, username, password, Date, Title, Content)

This took me about two hours to figure out and implement. Feel free to use it however you want.

Google Android Mobile OS Details, SDK released

In Software on Tuesday, November 13, 2007 at 8:47 am

Well, Google has released an SDK and lots, lots, lots of details about its new “Android” Mobile Operating System. (That image is “Hello World” running on the Android emulator.) Check it out! If you’re a developer, like I am, consider entering their contest – there’s going to be lots of cash prizes.

DOTW: Python

In Software on Friday, November 9, 2007 at 8:38 pm

I’ve been programming in Python for a couple of days now, and I love it. The tab-delineated code blocks are extremely easy to use, and everything’s very simple to understand. It’s extremely object-oriented (check this out: you can do things like "string literal".join(x)) It works great on Linux, Windows, and Mac OS X. The error handling is superb – it shows exactly where the error is, right in the console output. Get it today, will you?

What’s your favorite language?

In Software on Thursday, November 8, 2007 at 8:19 am

Programming language, that is. The TIOBE index updates its list of the 50 most popular programming monthly. Check out their website for lots of cool graphs and historical info. Here’s this month’s list.

  1. Java
  2. C
  3. Visual Basic
  4. C++
  5. PHP
  6. Perl
  7. Python
  8. C#
  9. Ruby
  10. Javascript
  11. Delphi
  12. D
  13. PL/SQL
  14. SAS
  15. Lisp/Scheme
  16. Lua
  17. Cobol
  18. ABAP
  19. Pascal
  20. Ada
  21. Fortran
  22. Transact-SQL
  23. Logo
  24. MATLAB
  25. Actionscript
  26. ColdFusion
  27. Prolog
  28. FoxPro/xBase
  29. Awk
  30. Labview
  31. RPG
  32. ML
  33. Haskell
  34. Bash
  35. Groovy
  36. Smalltalk
  37. Natural
  38. Tcl/Tk
  39. Erlang
  40. CL (OS/400)
  41. Forth
  42. Focus
  43. APL
  44. VBScript
  45. Scala
  46. Icon
  47. Factor
  48. IDL
  49. Objective-C
  50. PL/I

Stupid coding mistakes

In Software on Wednesday, November 7, 2007 at 9:16 pm

Ironically, the five mistakes I make the most when coding (this is C#, of course – still my favorite language) are simple, stupid things. Here they are.

5. Forget to close a curly brace.
4. Forget to type the second of the parentheses.
3. Forget to close a set of quotes.
2. Forget to type a semicolon at the end of a line.
1. Use “=” instead of “==”.