[pyKoL-users] SF.net SVN: pykol: [13]
Brought to you by:
scelis
From: <mi...@us...> - 2007-04-07 22:10:32
|
Revision: 13 http://pykol.svn.sourceforge.net/pykol/?rev=13&view=rev Author: misza13 Date: 2007-04-07 15:09:38 -0700 (Sat, 07 Apr 2007) Log Message: ----------- Modified the mall searcher into an iterator over the results (using yield). Modified Paths: -------------- mall.py test.py Modified: mall.py =================================================================== --- mall.py 2007-04-07 20:54:13 UTC (rev 12) +++ mall.py 2007-04-07 22:09:38 UTC (rev 13) @@ -11,10 +11,24 @@ def searchItem(self, what, limit=None): formdata = {'whichitem' : what} if limit: - formdata['cheaponly'] = 1 - formdata['shownum'] = limit + formdata['cheaponly'] = '1' + formdata['shownum'] = str(limit) response, data = self.Site.postForm('searchmall.php',formdata) - print response.status - print response.getheaders() - print data + offset = re.search('Price:',data).start() + itemRX = re.compile(r'<b>(?P<itemname>.+?)</b> \((?P<itemcount>\d+)\)(?: \((?P<limit>\d+) / day\))?.*?mallstore.php\?whichstore=(?P<whichstore>\d+).*?>(?P<shopname>.+)</a>.*?>(?P<price>[0-9,]+) ') + for itemM in itemRX.finditer(data,offset): + result = {} + for v in ['itemname','itemcount','limit','whichstore','shopname','price']: + if v == 'itemcount': + result[v] = int(itemM.group('itemcount').replace(',','')) + elif v == 'limit' and itemM.group('limit'): + result[v] = int(itemM.group('limit').replace(',','')) + elif v == 'price': + result[v] = int(itemM.group('price').replace(',','')) + elif v == 'whichstore': + result[v] = int(itemM.group('whichstore').replace(',','')) + else: + result[v] = itemM.group(v) + yield result + Modified: test.py =================================================================== --- test.py 2007-04-07 20:54:13 UTC (rev 12) +++ test.py 2007-04-07 22:09:38 UTC (rev 13) @@ -18,12 +18,13 @@ Site = KoLSite() Site.doLogin(config['nick'],config['password']) - response, data = Site.getPage('main.html') - print response.status - print data + #response, data = Site.getPage('main.html') + #print response.status + #print data M = Mall(Site) - M.searchItem('tiny plastic sword') + for s in M.searchItem('tiny plastic sword'): + print s if __name__ == '__main__': main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |