pythonaro.com

Pythonaro blog

11 October 2008

Notes on Google Finance API

I recently started dabbling in shares (yeah, I know, I like swimming against the flow), and so I looked around for good stock-price trackers for KDE3. To my surprise, I couldn't find anything apart from the usual KMyMoney (which I like and use, but it's not really something you can keep open all day on your desktop). I had already put my stock info on Google Finance, and lo, the service has a GData API, so I decided to write a small script in Python to retrieve my portfolio and the daily variations.

The good thing about GData APIs is that they are all the same at a basic level, so even when client libraries don't explicitly expose new features (like in this case, as Finance is quite a new service), you can still use the APIs to get easy authentication and feed-parsing. So I went and downloaded the official (and excellent) gdata-python-client package, which is dead-easy to use:

from gdata.service import GDataService

client = GDataService()
client.email = 'your_email@gmail.com'
client.password = 'your_password'
client.service = 'finance'

client.ProgrammaticLogin()

baseURL = "http://finance.google.com/finance/feeds/%(email)s/" % {'email':client.email}

# to get all data in one go:
#  bigFeed = client.GetFeed(baseURL + "portfolios?positions=true&returns=true")
# and then positionsFeed is included in each Entry
#  positionsFeed = gdata.GDataFeedFromString(bigfeed.entry[0].FindExtensions('feedLink')[0].children[0].ToString())

# ... but I really just want the first portfolio
positionsFeed = client.GetFeed(baseURL + "portfolios/1/positions?returns=true")

for entry in positionsFeed.entry:
 details = entry.FindExtensions('symbol')[0] 
 symbol = details.attributes['symbol']
 name = details.attributes['fullName']
 
 data = entry.FindExtensions('positionData')[0]
 totalReturn = round(float(data.attributes['returnOverall']) * 100,2)
 gainPerc = round(float(data.attributes['gainPercentage']) * 100,2)
 
 print name + " (" + symbol + ") Return: " + str(totalReturn) + "% - Gain: " + str(gainPerc) + "%" 

One should really make an applet or something for KDE, but I'm leaving for Japan in about six hours so I can't be bothered...

Labels: , , ,

posted by GiacomoL @ 9:31 PM   0 comments links to this post

08 April 2008

Google App Engine

Google App Engine. Write applications in Python using a WSGI-compatible application framework, then host them on Google’s highly scalable infrastructure.
(via Simon Willison's Links)

"Holy s**t" was Ryan Tomayko's comment, and my first thought as well. Google is realising the promises of WSGI, and what a sight it is.
On one hand, this is fantastic; it made me think of "J2EE done right". On the other hand, if you use GAE, you are handing your entire infrastructure and data (!) over to Google, which might not be the smartest move for lots of companies (any FTSE100 for example, and probably any NASDAQ-listed as well).

Anyway, Python rocks.

Labels: , , , , ,

posted by GiacomoL @ 12:04 PM   0 comments links to this post

17 November 2007

Google spamming LinkedIn profiles?

I just got a message from somebody on LinkedIn who (apparently) works for Google, saying they have an "engineering opportunity" and to reply with my word or pdf CV. While I'm flattered, I'm not sure I should reply to the message. Call me paranoid, but I don't see how I'd ever be Google-material (no strong academical background, no open-source fame...); maybe I ended up in some strange list (maybe matching LinkedIn profiles with emails on Monster?), maybe something worse.

Labels: , ,

posted by GiacomoL @ 10:23 PM   0 comments links to this post