Sunday, September 26th, 2004

An Amazon Web Services (AWS) 4.0 application in just a few lines

Filed under: Science and Technology — Daniel Lemire @ 19:01

I have somewhat of a debate with my friend Yuhong about the correct way to use a Web Service. Yuhong seems to prefer SOAP. I much prefer REST. What is a REST Web Service? For the most part, a REST Web Service is really, really simple. You simply follow a URL and magically, you get back an XML file which is the answer to your query. One benefit of REST is that you can easily debug it and write quick scripts for it. What is a SOAP Web Service? I don’t know. I really don’t get it. It seems to be a very complicated way to do the same thing: instead of sending the query as a URL, you send the query as a XML file. The bad thing about it is that if it breaks, then you have no immediate way to debug it: you can’t issue a SOAP request using your browser (or maybe you can, but I just don’t know how).

Now, things never break, do they? Well, that is the problem, they break often because either I’m being stupid or I don’t know what I’m doing or the people on the other side don’t know what they are doing or the people on the other side are experimenting a bit or whatever else. I find that being able to quickly debug my code is the primary feature any IT technology should have. The last thing I want from a technology is for it to be hard to debug.

Here is the problem that I solved this week-end. I have this list of artists and I want to get a list of all corresponding music albums so I can put it all into a relational (SQL) database. Assuming that your list of artists are in a file called artists_big.txt and that you want the result to be in a file called amazonresults.sql, the following does a nice job thanks to the magic of Amazon Web Services:

Yes: the code goes over because I cannot allow HTML to wrap lines (Python allows wrapping lines, but not arbitrarily so, white space is significant in Python). There is just no way around it that I know: suggestions with sample HTML code are invited.

import libxml2, urllib2, urllib, sys, re, traceback
ID=""# please enter your own ID here
uri="http://webservices.amazon.com/AWSECommerceService/2004-10-19"
url="http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=%s&Operation=ItemSearch&SearchIndex=Music&Artist=%s&ItemPage=%i&ResponseGroup=Request,ItemIds,SalesRank,ItemAttributes,Reviews"
outputcontent = ["ASIN","Artist","Title","Amount","NumberOfTracks","SalesRank","AverageRating","ReleaseDate"]
input = open(”artists_big.txt”)
output = open(”amazonresults.sql”, “w”)
log = open(”amazonlog.txt”, “w”)
output.write(”DROP TABLE music;nCREATE TABLE music (ASIN TEXT, Artist TEXT, Title TEXT, Amount INT, NumberOfTracks INT, SalesRank INT, AverageRating NUMERIC, ReleaseDate DATE);n”)
def getNodeContentByName(node, name):
for i in node:
if (i.name==name): return i.content
return None
for artist in input:#go through all artists
print “Recovering albums for artist : “, artist
page = 1
while(True):# recover all pages
resturl = url %(ID,urllib.quote(artist),page)
log.write(”Issuing REST request: “+resturl+”n”)
try :
data = urllib2.urlopen(resturl).read()
except urllib2.HTTPError,e:
log.write(”n”)
log.write(str(traceback.format_exception(*sys.exc_info())))
log.write(”n”)
log.write(”could not retrieve :n”+resturl+”n”)
continue
try :
doc = libxml2.parseDoc(data)
except libxml2.parserError,e:
log.write(”n”)
log.write(str(traceback.format_exception(*sys.exc_info())))
log.write(”n”)
log.write(”could not parse (is valid XML?):n”+data+”n”)
continue
ctxt=doc.xpathNewContext()
ctxt.xpathRegisterNs(”aws”,uri)
isvalid = (ctxt.xpathEval(”//aws:Items/aws:Request/aws:IsValid”)[0].content == “True”)
if not isvalid :
log.write(”The query %s failed ” % (resturl))
errors = ctxt.xpathEval(”//aws:Error/aws:Message”)
for message in errors: log.write(message.content+”n”)
continue
for itemnode in ctxt.xpathEval(”//aws:Items/aws:Item”):
attr = {}
for nodename in outputcontent:
content = getNodeContentByName(itemnode,nodename)
if(content <> None):
content = re.sub(”‘”,”‘”,content)
if(nodename == “SalesRank”):
content = re.sub(”,”,”",content)
attr[nodename] = content
columns = “(”
keys = attr.keys()
for i in range(len(keys)-1):
columns += keys[i]+”,”
columns+=keys[len(keys)-1]+”)”
row = “(”
values = attr.values()
for i in range(len(values)-1):
row+=”‘”+str(values[i])+”‘,”
row+=”‘”+str(values[len(values)-1])+”‘)”
command = “INSERT INTO music “+columns+” VALUES “+row+”;n”
output.write(command)
NumberOfPages = int(ctxt.xpathEval(”//aws:Items/aws:TotalPages”)[0].content)
if(page >= NumberOfPages): break
page += 1
input.close()
output.close()
log.close()
print “You should now be able to run the file in postgresql. Start the postgres client doing psql, and using i amazonresults.sql in the postgresql shell.”

Update : this was updated to take into account these comments from Amazon following the upgrade of AWS 4.0 from beta to release:

Service Name change: You will need to modify the Service Name parameter in your application from AWSProductData to AWSECommerceService. We realize that it may take some time to implement this change in your applications. In order to make this transition as easy as possible, we will continue supporting AWSProductData for a short time.

2) REST/WSDL Endpoints: You will need to modify your application to connect to webservices.amazon.com instead of aws-beta.amazon.com. For other locales, the new endpoints are webservices.amazon.co.uk, webservices.amazon.de and webservices.amazon.co.jp.

Saturday, September 25th, 2004

Lunch with Anna

Filed under: Academia/Research — Daniel Lemire @ 16:34

Today, I had lunch with Anna Maclachlan (my ex-colleague from NRC now working for Idialia). The lunch she prepared was magnificent: peanut chicken, rice, pastry… She has a beautiful appartment in Chinatown. We talked about the last AILIA meeting and the fact that Alis was acquired. We also talked about how tough it can be to start your working life in your thirties, when everyone else has already figured out what they are and what they do. We talked about how universities are maybe too eager to train more Ph.D.s than needed. We talked about the “universities are not about job training” and “university professors could not offer job training if their lives depended on it” topics, covered elsewhere on my blog. Finally, we talked about some (secret) research we did together… more on this later…

Wednesday, September 22nd, 2004

AILIA 2004 Annual Meeting

Filed under: Business / Economics / Politics — Daniel Lemire @ 9:04

I was an invited speaker at the AILIA (Canadian Langage Industry Association) Annual Meeting. I was talking about Semantic Web and RDF. I met some pretty fantastic people like Pierre Coulombe from Lingua Technologies and Fred Popowich from Axonwave.

I learned about a nice project by RALI called TransCheck. It is a computer-assisted revision tool to help automatically improve the quality of translations by checking for some common errors made by translators.

Sunday, September 19th, 2004

Academic life: a balancing act

Filed under: Academia/Research — Daniel Lemire @ 11:00

Today, I realized that the life of a researcher/professor is really a balancing act. A professor…

  • has a rich personal life;
  • gives great courses;
  • gets a lot of funding;
  • has many students;
  • publishes a lot papers each year;
  • consults on industrial/governmental projects;
  • manages something (departement, project, program).

It is no surprise that many professors end up being overworked. I think you simply cannot pull all these things at once. Maybe 2 or 3 from the list. You have to choose or life will choose for you.

Does your university think that “Jobs are for the little people”?

Filed under: Academia/Research — Daniel Lemire @ 9:15

Tall, Dark, and Mysterious is a Math. professor somewhere in Canada, possibly in British Columbia. She graduated from a big school and now teaches at a smaller (lesser?) school.

Well, is it a lesser school? That’s where her tale becomes interesting. Myself, I attended UofT. I don’t know if the rule is true, probably not, but it seem that the larger the school, the more it suffers from the jobs-are-for-little-people syndrome as documented in a post by Tall, Dark, and Mysterious. Here is an insightful quote:

University isn’t job training, because universities are adamant about university not being job training. And it’s not because they’re too busy enriching students’ lives and fostering a love of learning Underneath all of the cheap idealism - trumpeted by gainfully employed people, many of whom haven’t learned how to play a musical insturment, how to speak a foreign language, or how to play a new sport because none of those things are related to their jobs and because they’re too old to be doing that sort of thing - about learning for the sake of learning is a willful inability to confront the fact that students are not at universities to learn for the sake of learning.

Friday, September 17th, 2004

Some insight from John Travolta

Filed under: Academia/Research — Daniel Lemire @ 19:38

This morning, I was chatting with a colleague, Richard Hotte, and we were discussing research, funding, and the relation between the two. I’ve also had these discussions with Martin Brooks. Richard pointed out that John Travolta has figured it out all some years ago when he received a prize at Cannes for the movie Pulp Fiction. According to Richard, Travolta was asked then about how it felt to finally win a prize that he surely coveted for many years. John Travolta answered that his goal was never to win a prize, but rather to grow as an actor. The prize was nice, but not his goal.

This echoes my own feeling about funding for research. If your goal is funding, you’ll probably get some, maybe a lot, but unfortunately, you may never become a great researcher.

Thursday, September 16th, 2004

CBC has an article about nouse

Filed under: Science and Technology — Daniel Lemire @ 19:24

The Canadian Broadcast Corporation has an article about a nose-controlled pointer. Basically, you can get rid of your mouse and replace it by a webcam. I’ve seen this life and the inventor was a colleague of mine not long ago. They do some fantastic things at NRC, you know.

« Previous PageNext Page »
5 Sep News - Order Now Ultram 50mg, tramadol in us pharmacy pay by, buy tramadol online consultation us, Cheap tramadol NO RX, cheap tramadol overnight free, cheapest tramadol available online, buy tramadol cheap medication, buy cheap tramadol, Tramadol orders C.O.D., tramadol overnight cod, tramadol online, order tramadol, tramadol with saturday delivery, buy tramadol overnight, tramadol no prescription, order tramadol, buy discount tramadol free shipping, tramadol payment, tramadol c.o.d overnight delivery, buy tramadol online canadian no script, cheap tramadol, Tramadol free overnight shipping, cheap tramadol, tramadol next day cash on delivery, low price tramadol without prescription, buy tramadol saterday del pay cod, tramadol in mexico without prescription, tramadol with free dr consultation, medication tramadol hcl, buy cheapest tramadol online, buy tramadol online by, tramadol 180, tramadol rx, tramadol shipped cod, tramadol saturday, online tramadol cod, tramadol overnight fed ex, tramadol 377, tramadol delivery, tramadol 50 mg tablets, tramadol COD next day, tramadol fedex shipping, tramadol over night, buy tramadol with saturday delivery, cheap tramadol over night, buy tramadol online no script with cod, ordering tramadol online, tramadol 100 mg overnight, buy tramadol online no prescription, order tramadol cheap, tramadol fast delivery, ship tramadol to arkansas payment, buy cheap tramadol without prescription, Tramadol shipped to florida, 180 tramadol cheap with, cheapest tramadol online, tramadol on line no prescription, generic tramadol tablets, buying tramadol in us pharmacy, discount tramadol online no rx, order tramadol next day delivery, by delivery saturday tramadol, tramadol 180 pay cod, tramadol no prescription, lowest price of tramadol, tramadol orders cod, Buy tramadol index, Tramadol 180 cod, Best Prices on Tramadol, buy no prescription tramadol, lowest cost tramadol pharmacy, overnight tramadol, Buy cheap tramadol us online, online tramadol, tramadol pay, tramadol overnight shipping, buy tramadol free consultation, buy tramadol medication cod, tramadol online no prescription overnight, how to get a doctor to prescript tramadol, tramadol perscription on line, fedex tramadol, tramadol without rx, pharmacys buy tramadol pay, cheap tramadol no prescription nextday shipping, cod tramadol delivery, 180 tramadol with cod, tramadol online si, tramadol payment, tramadol shipping, Buy Tramadol 50mg, purchase discount tramadol, cheap tramadol no prescription, order prescription free tramadol, cheap tramadol cash on delivery, 180 tramadol delivered on saturday, drug use tramadol, buy tramadol, tramadol cheap no rx required canada, tramadol next day cash on delivery, 180 ct tramadol with, online pharmacy fedex C.O.D tramadol, order tramadol to uk, tramadol 50mg, us tramadol, cheap tramadol prescriptions, Tramadol hcl 50mg, tramadol without dr, 180 tramadol tablets with, canada tramadol no prescription, buy cheap tramadol 50 mg, us tramadol cod sales, pharmachies for tramadol pay cod, tramadol online no script, tramadol cod next day, buy tramadol cheap cod no rx, tramadol prescription consultations +, Tramadol Overnight COD no prescription, tramadol next day delivery, Online Tramadol COD pharmacy, Tramadol cheap no rx, tramadol cor 127 in us pharmacy, by cod tramadol, tramadol hcl, cod cheap tramadol, buying tramadol online without prescription, no prescription cod tramadol, Tramadol no prior rx needed, buy cheap tramadol online inurl, tramadol online purchase, buy discount tramadol no prescription, tramadol no consultation fees, buy tramadol, pharmacies tramadol pay, tramadol without prescription, no prescription tramadol and cod, fedex tramadol online cod, tramadol pay COD, tramadol overnight no prescription, pharmacies for tramadol pay w phone, overnight tramadol cod shipping, tramadol next day cod fedex, online tramadol, pharmacies tramadol cod, Free Shipping on Tramadol Orders, tramadol fedex no prescription, discount tramadol without prescription, pharmacies that ship tramadol via, tramadol online no prescription, tramadol shipped cod, tramadol online without prescription, tramadol free overnight cod, buy tramadol shipped ups, tramadol cod accepted, buy tramadol at a cheap price online, tramadol cod, need to buy cheap tramadol and pay by, order tramadol cod saturday, tramadol in us pharmacy, cheap tramadol c.o.d., how to get prescription of tramadol, tramadol prescription drug, buy payment tramadol, buy tramadol cheap, tramadol no doctors consult, tramadol cod overnight delivery, buy cheap tramadol online with cod, buy discount tramadol now, by money order order tramadol, tramadol pay by, tramadol free fedex shipping, how to get tramadol without, by tramadol online for cod, Buy tramadol with american express, cheap tramadol without prescription overnight delivery, cheap tramadol online, buy cheap tramadol overnight, buying tramadol without a prescription, cod tramadol no prescription, cheap tramadol free fedex, online pharmacy fedex cod tramadol, tramadol without prescription overnight shipping, tramadol ultram, buy tramadol order cod, free shipping tramadol, tramadol overnight COD, tramadols overnighted cod, tramadol with cash on delivery, cheap tramadol next day delivery, cheap tramadol without prescription, no prescription required for tramadol, cheap tramadol no rx, buy cheap tramadol no Prescription, tramadol free overnight fedex delivery, 180 ct tramadol payment with, tramadol fedex overnight, us tramadol fedex, 180 ct tramadol, tramadol fedex, generic tramadol no prescription overnight, buy tramadol overnight cod, tramadol without a presciption, Tramadol no prescription pharmacy discounter, tramadol cod saturday delivery, buy tramadol online overseas, ordering tramadol online no membership overnight delivery, order tramadol online with cod, discount tramadol online, pharmacy tramadol no prescrption, order tramadol online without prescription, tramadol overnight fedex, no prescription next day delivery tramadol, tramadol free consultation, online tramadol with delivery, tramadol shipped COD on saturday delivery, tramadol medication online, tramadol without a prescription, tramadol shipped, discount tramadol, buy discount tramadol, cheap tramadol no prescription next day delivery, online prescription for tramadol, Tramadol oral, tramadol on delivery, buy tramadol cod, tramadol overnight, tramadol overnight no script mastercard accepted, low price tramadol, tramadol online cash on delivery, tramadol overnight, 100 mg tramadol, tramadol no prescription drug, order tramadol cod next day delivery, tramadol xr buy online cheap, tramadol online fed ex, get discount tramadol now, buy tramadol tablets without prescription, only tramadol free consult, tramadol cod online, very cheap tramadol, tramadol pharmacy cod saturday delivery, order tramadol hcl with cod, real tramadol in us pharmacy, tramadol prescription from doctors online, order tramadol online, buying tramadol without a script, buy tramadol no prescription, Tramadol cheap no rx free from india, buy discount tramadol online, tramadol buy in UK, cheap tramadol cod, tramadol next day delivery, order discount tramadol, tramadol hcl 50 mg, tramadol ultracet, Tramadol on sale, overnight buy tramadol, buy cod guestbook.html inurl tramadol, Tramadol prescription, 180 tramadol cod, tramadol 120, buy tramadol online cash on delivery, tramadol without a prescription and cod delivery, purchase tramadol shipping, tramadol online no perscription, tramadol india, online pharmacies tramadol, purchase tramadol cod, tramadol for sale cod, tramadol without presciption, Tramadol and description, tramadol with next day delivery without prescription with free shipping, pharmacies tramadol pay by, tramadol pay by cod, tramadol cheap, buy tramadol overnight delivery, tramadol saturday delivery, tramadol overnight without prescription, tramadol, buy tramadol online cod, buy tramadol, tramadol cheap next day, tramadol medicine pay, tramadol pay COD, shipping tramadol, tramadol online next day, tramadol with, tramadol withdraw, tramadol fed ex, pharmacy tramadol, Cash on deliver Tramadol overnight, online doctor consultation for tramadol, tramadol no rx, cod tramadol 120, buy tramadol and pay by cod, Tramadol great buy, tramadol cod delivery next day, buy tramadol online, order tramadol online by fedex, buy cheapest tramadol, order tramadol cod, buy tramadol without a prescription overnight delivery, cod delivery tramadol, no prescription cod tramadol, buy tramadol pay, tramadol no prescription required, tramadol with free fedex overnight, TRAMADOL ONLINE FEDEX COD FREE CONSULT, order tramadol online pharmacies cash on delivery, pharmacies pay by cod tramadol, tramadol no prescription overnight cod delivery, next day tramadol, tramadol cash on delivery, Order Now Ultram, where to buy tramadol, tramadol hydrochloride, cod delivery tramadol, tramadol sales, tramadol online cheap, tramadol cheap, 180 ct tramadol payment options, tramadol cod shipping, no prescription tramadol fedex delivery, discount tramadol fast delivery, tramadol shipped on saturday, buying tramadol cod, tramadol ship to 50 states, buy tramadol with cod, order tramadol by, buy tramadol overnight via electronic check or, tramadol no prescription cash on delivery, buy tramadol online without dr approval, cheap tramadol overnight delivery, tramadol shipped with, buy tramadol no rx, tramadol without a rx, buy cheap tramadol online, cheapest tramadol, tramadol overnight delivery cheap, cheap tramadol, online pharmacy tramadol, cheap tramadol fedex overnight, overnight tramadol cod, TRAMADOL ONLINE FEDEX COD FREE CONSULT, tramadol med pay cod, Tramadol medication, cod tramadol, no prescription tramadol, tramadol cash delivery, tramadol next day, tramadol online with no prescription or membership, buy tramadol for saturday delivery, order tramadol online no prescription, pharmacies for tramadol pay, tramadol overnight online, tramadol ups, tramadol fedex delivery, buy tramadol overnight cod, buy tramadol cash on delivery, tramadol drug, More News wholesale phentermine, phentermine no prescription, phentermine without prescription, extra cheap phentermine, cheap phentermine no prescription, phentermine no prescription fast delivery, no prescription phentermine, Buy Phentermine Adipex 37.5mg, cheapest phentermine, cheap phentermine, phentermine hydrochloride, discount phentermine, phentermine no rx, order phentermine online, phentermine very cheap, phentermine 37 5mg, phentermine 30mg, cheap 37 5 phentermine, generic phentermine, phentermine 37.5 mg, phentermine diet pills, phentermine cod, cheap phentermine without a prescription, phentermine 37 5mg online, phentermine at discount prices, order phentermine online no prescription, phentermine order cheap, Buy phentermine online, where to buy phentermine, phentermine hcl,

37 queries. 0.442 seconds. Valid XHTML

Powered by WordPress

Subscribe to this blog in a reader or by Email.