Mashup Korea
FrontPage|FindPage|TitleIndex|RecentChanges|UserPreferences E D R S I M H RSS

# -*- coding: cp949 -*-

if __name__ == '__main__':
	daumUrl = "http://apis.daum.net/search/book?%s"
	naverUrl = "http://openapi.naver.com/search?%s"

	daumParams = {
	"apikey" : "9382530ef3abb0588bb463e07259644917e2dd45",
	"target" : "meta",
	}
	naverParams = {
	"key" : "6f4ad5dbec8f118d6869767b9fbcefe4",
	"target" : "book"
	}

	print '°Ë»öÇÒ Á¦¸ñÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä'
	title = raw_input()

	daumParams['q'] = title
	naverParams['query'] = title.decode('cp949').encode('utf-8')

	import urllib
	daumResult = urllib.urlopen(daumUrl % urllib.urlencode(daumParams)).read()
	naverResult = urllib.urlopen(naverUrl % urllib.urlencode(naverParams)).read()

	import BeautifulSoup
	daumBook = BeautifulSoup.BeautifulSoup(daumResult)
	naverBook = BeautifulSoup.BeautifulSoup(naverResult)

	allResult = [] # ( ['Daum'/'Naver'], title, price ) ...

	for it in daumBook.findAll('item'):
		allResult.append( ('Daum', 
			it.find('title').contents[0].encode('cp949'), 
			it.find('sale_price').contents[0].encode('cp949'))
		)

	for it in naverBook.findAll('item'):
		allResult.append( ('Naver', 
			it.find('title').contents[0].encode('cp949'), 
			it.find('price').contents[0].encode('cp949'))
		)

	allResult.sort(key=lambda d: int(d[2])) # ,reverse=True) 
	for r in allResult:
		print r[0], '[ °¡°Ý:', r[2], ']', r[1]
		

EditText|FindPage|DeletePage|LikePages| Valid XHTML 1.0! Valid CSS! powered by MoniWiki