vvvvget/db_to_html.py

49 lines
1.6 KiB
Python
Raw Permalink Normal View History

2018-05-21 17:22:14 +02:00
import os
import sqlite3
vvvvidb = "vvvvidb.sqlite3"
2018-10-17 23:43:44 +02:00
if not os.path.isfile(vvvvidb):
2018-05-21 17:22:14 +02:00
print("{} file not found. Scrape the DB first using vvvvget.py".format(vvvvidb))
exit(1)
con = sqlite3.connect(vvvvidb)
cur = con.cursor()
out = open('index.html', 'w')
out.write('''<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Anime | lsd.cat</title>
<link rel="icon" sizes="16x16" type="image/png" href="/icon.png" />
<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>
</head>
<body>
2018-08-27 14:53:04 +02:00
<a href="''' + vvvvidb + '''">Source Database</a><br/><br/>''')
2018-05-21 17:22:14 +02:00
2018-10-17 23:43:44 +02:00
# Select all the series
2018-05-21 17:22:14 +02:00
# cur.execute("SELECT * FROM series;")
2018-10-17 23:43:44 +02:00
# Selecy only series with at least one episodes
2018-05-21 17:22:14 +02:00
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;")
series = cur.fetchall()
for s in series:
serie = (str(s[0]), str(s[2]))
out.write("\t<h3>{}: {} - Id Serie: {} - Tipo: {}</h3>\n\t<ul>\n".format(s[0], s[1], s[2], s[3]))
2018-10-17 23:43:44 +02:00
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 = ? AND e.cdn_url != '';", serie)
2018-05-21 17:22:14 +02:00
episodes = cur.fetchall()
[out.write("\t\t<li><a href=\"player.html#{0}\">{0}</a></li>\n".format(e[0])) for e in episodes]
out.write('\t</ul>\n')
out.write('\n</body>\n</html>')
out.close()
2018-10-17 23:43:44 +02:00
con.commit()
2018-05-21 17:22:14 +02:00
con.close()