api_sitemap.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from .tool.func import *
  2. def api_sitemap_2(conn):
  3. curs = conn.cursor()
  4. if admin_check(None, 'make sitemap') == 1:
  5. data = '' + \
  6. '<?xml version="1.0" encoding="UTF-8"?>\n' + \
  7. '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + \
  8. ''
  9. domain = load_domain()
  10. curs.execute(db_change("select title from data"))
  11. all_data = curs.fetchall()
  12. len_all_data = len(all_data)
  13. count = int(len_all_data / 30000)
  14. other_count = len_all_data % 30000
  15. for i in range(count + 1):
  16. data += '<sitemap><loc>' + domain + 'sitemap_' + str(i) + '.xml</loc></sitemap>\n'
  17. data += '' + \
  18. '</sitemapindex>' + \
  19. ''
  20. f = open("sitemap.xml", 'w')
  21. f.write(data)
  22. f.close()
  23. e = 0
  24. for i in range(count + 1):
  25. data = '' + \
  26. '<?xml version="1.0" encoding="UTF-8"?>\n' + \
  27. '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + \
  28. ''
  29. if count == i:
  30. for x in all_data[30000 * i:]:
  31. data += '<url><loc>' + domain + 'w/' + url_pas(x[0]) + '</loc></url>\n'
  32. else:
  33. for x in all_data[30000 * i:30000 * (i + 1)]:
  34. data += '<url><loc>' + domain + 'w/' + url_pas(x[0]) + '</loc></url>\n'
  35. data += '' + \
  36. '</urlset>' + \
  37. ''
  38. f = open("sitemap_" + str(i) + ".xml", 'w')
  39. f.write(data)
  40. f.close()
  41. return redirect('/sitemap.xml')
  42. else:
  43. return re_error('/ban')