db_to_html.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import os
  2. import sqlite3
  3. vvvvidb = "vvvvidb.sqlite3"
  4. if not os.path.isfile(vvvvidb):
  5. print("{} file not found. Scrape the DB first using vvvvget.py".format(vvvvidb))
  6. exit(1)
  7. con = sqlite3.connect(vvvvidb)
  8. cur = con.cursor()
  9. out = open('index.html', 'w')
  10. out.write('''<!DOCTYPE html>
  11. <html>
  12. <head>
  13. <meta charset="utf-8">
  14. <meta name="viewport" content="width=device-width, initial-scale=1">
  15. <title>Anime | lsd.cat</title>
  16. <link rel="icon" sizes="16x16" type="image/png" href="/icon.png" />
  17. <style type="text/css">body{margin:40px auto;max-width:740px;line-height:1.6;color:#444;padding:0 10px}h1,h2,h3{line-height:1.2;font-size:18px;}li{font-size:12px;}</style>
  18. </head>
  19. <body>
  20. <a href="''' + vvvvidb + '''">Source Database</a><br/><br/>''')
  21. # select all the series
  22. # cur.execute("SELECT * FROM series;")
  23. # selecy only series with at least one episodes
  24. cur.execute("SELECT s.* FROM series as s INNER JOIN episodes as e ON e.serie_id = s.id AND e.season_id = s.season_id GROUP BY s.id, s.season_id;")
  25. series = cur.fetchall()
  26. for s in series:
  27. serie = (str(s[0]), str(s[2]))
  28. out.write("\t<h3>{}: {} - Id Serie: {} - Tipo: {}</h3>\n\t<ul>\n".format(s[0], s[1], s[2], s[3]))
  29. cur.execute("SELECT e.cdn_url FROM episodes AS e JOIN series AS s ON e.serie_id = s.id AND e.season_id = s.season_id WHERE s.id = ? AND s.season_id = ?;", serie)
  30. episodes = cur.fetchall()
  31. [out.write("\t\t<li><a href=\"player.html#{0}\">{0}</a></li>\n".format(e[0])) for e in episodes]
  32. out.write('\t</ul>\n')
  33. out.write('\n</body>\n</html>')
  34. out.close()
  35. con.commit()
  36. con.close()