Skip to content

Instantly share code, notes, and snippets.

@RafaAguilar
Last active August 29, 2015 14:27
Show Gist options
  • Save RafaAguilar/b6c2f99bdc4ab6c036ca to your computer and use it in GitHub Desktop.
Save RafaAguilar/b6c2f99bdc4ab6c036ca to your computer and use it in GitHub Desktop.
def dump_sitemap(site_name,products):
frmt = 'csv'
logger.debug("Monkey #" + str(os.getpid()) + " Writing Sitemap to " + site_name + "." + frmt)
if frmt == 'json':
site_map_file = open(site_name + ".json","w")
site_map_file.write(json.dumps(products['urlset']))
elif frmt == 'csv':
site_map_file = open(site_name + ".csv","w")
products = products['urlset']['url']
for p_index in range(1,len(products)):
#for p_index in range(1,10):
current_product = products[p_index]
for vid in current_product['variant_ids']:
if 'image:image' in current_product.keys():
line = str(vid) + "," + str(current_product['image:image']['image:title']) + '\n'
try:
site_map_file.write(line)
except:
continue
else:
logger.error("Monkey #" + str(os.getpid()) + " Unhanded format: " + frmt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment