api_sitemap.py 1.6 KB

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