2
0

api_sitemap.py 1.8 KB

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