2020-08-05 18:47:29 -07:00
|
|
|
import os
|
|
|
|
import sqlite3
|
|
|
|
import subprocess
|
2019-07-23 15:49:57 -07:00
|
|
|
|
2020-03-27 17:08:03 -07:00
|
|
|
RPI_IMDB_DATABASE = "/var/lib/rpiWebApp/"
|
|
|
|
RPI_TSV_DIRECTORY = "/var/lib/imdb-rename/"
|
2019-07-23 15:49:57 -07:00
|
|
|
RPI_CSV_DIRECTORY = "/home/matt/"
|
|
|
|
|
2020-03-19 19:25:44 -07:00
|
|
|
MC_IMDB_DATABASE = "***REMOVED***"
|
|
|
|
MC_TSV_DIRECTORY = "***REMOVED***"
|
|
|
|
MC_CSV_DIRECTORY = "***REMOVED***"
|
2019-07-23 15:49:57 -07:00
|
|
|
|
|
|
|
|
|
|
|
IMDB_DATABASE = RPI_IMDB_DATABASE if os.path.exists(RPI_IMDB_DATABASE) else MC_IMDB_DATABASE
|
|
|
|
TSV_DIRECTORY = RPI_TSV_DIRECTORY if os.path.exists(RPI_TSV_DIRECTORY) else MC_TSV_DIRECTORY
|
|
|
|
CSV_DIRECTORY = RPI_CSV_DIRECTORY if os.path.exists(RPI_CSV_DIRECTORY) else MC_CSV_DIRECTORY
|
|
|
|
|
|
|
|
|
|
|
|
def create_csv_files():
|
2020-08-05 18:47:29 -07:00
|
|
|
print("start create csv")
|
|
|
|
subprocess.run(
|
|
|
|
["xsv", "input", "-d", "\t", "--no-quoting", "{}title.akas.tsv".format(TSV_DIRECTORY), "-o", "{}title_akas.csv".format(CSV_DIRECTORY)]
|
|
|
|
)
|
|
|
|
subprocess.run(
|
|
|
|
["xsv", "input", "-d", "\t", "--no-quoting", "{}title.basics.tsv".format(TSV_DIRECTORY), "-o", "{}title_basics.csv".format(CSV_DIRECTORY)]
|
|
|
|
)
|
|
|
|
subprocess.run(
|
|
|
|
["xsv", "input", "-d", "\t", "--no-quoting", "{}title.episode.tsv".format(TSV_DIRECTORY), "-o", "{}title_episode.csv".format(CSV_DIRECTORY)]
|
|
|
|
)
|
|
|
|
print("end create csv")
|
2019-07-23 15:49:57 -07:00
|
|
|
|
|
|
|
|
|
|
|
def import_csv_files():
|
2020-08-05 18:47:29 -07:00
|
|
|
print("start import csv")
|
|
|
|
f = open("import_csv.sql").read()
|
|
|
|
sql_script = f.format(CSV_DIRECTORY)
|
|
|
|
subprocess.run(["sudo", "-u", "http", "sqlite3", IMDB_DATABASE + "imdb.db"], input=sql_script.encode("utf8"))
|
|
|
|
print("end import csv")
|
2019-07-23 15:49:57 -07:00
|
|
|
|
|
|
|
|
|
|
|
create_csv_files()
|
|
|
|
import_csv_files()
|