Created
March 14, 2011 16:06
-
-
Save meehow/869377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import urllib | |
import libxml2 | |
import sys | |
def product_list(url, kategoria, podkategoria): | |
xml = libxml2.parseDoc(urllib.urlopen(url).read()) | |
products = xml.xpathEval('/oferta/kategoria[@nazwa="%s"]/podkategoria[@nazwa="%s"]/produkt' % (kategoria, podkategoria)) | |
p_list = [] | |
for p in products: | |
p_dict = {} | |
p_dict['nazwa'] = p.xpathEval('@nazwa')[0].content | |
p_dict['id'] = p.xpathEval('@id')[0].content | |
p_dict['dostawca_nazwa'] = p.xpathEval('dostawca/@nazwa')[0].content | |
p_list.append(p_dict) | |
return p_list | |
if __name__ == '__main__': | |
kategoria='Finanse osobiste' | |
podkategoria = 'Konta osobiste' | |
print product_list(sys.argv[1], kategoria, podkategoria) | |
# {% for p in product_list %} | |
# {{ p.nazwa }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment