#!/usr/bin/python3 # # Program to dump a MediaProcessor DB into a folder of html files # # This will create an index.html file that has links to all files # produced by this program. Each file is named by the IPFS hash # for the media content. It contains all of the metadata and as a # hidden set of name/value pairs with a few visible lines for use # in a web browser. # import datetime import sqlite3 import time import sys import os def usage(): cmd = sys.argv[0] str = "\nCreates a file for each row of the target SQLite database.\n" str += "Usage: " + cmd + " <-d sqlite DB file> <-f folder> [-s since]\n\n" print(str) exit(0) HTML1 = "\n\t\n\t\t
\n\t\t\t\n") sql = "SELECT vhash FROM IPFS_HASH_INDEX ORDER BY grupe, sqlts" rows = (conn.cursor().execute(sql)).fetchall() for row in range(0, len(rows)): vhash = rows[row]['vhash'] if vhash and len(vhash) == 46: idx.write(f"{vhash} ") if (row + 1) % 3 == 0: idx.write('\n') idx.write(HTML3) # Create the files, with contents being all metadata fields & values. # Display a few items at top of file and leave most hidden. sql = "SELECT * FROM IPFS_HASH_INDEX " rows = conn.cursor().execute(sql + "limit 1;") for col in rows.description: # First get column names cols.append(col[0]) if since: sql += f"WHERE sqlts >= '{since}' " sql += "ORDER BY grupe, sqlts" rows = (conn.cursor().execute(sql)).fetchall() # Now get the column values fiveSpaces = " " for row in rows: vhash = row['vhash'] if not vhash or len(vhash) < 46: continue file = folder + '/' + row['vhash'] + ".html" with open(file, 'w') as f: f.write(HTML1 + row['title'] + HTML2) ipfs = f"http://127.0.0.1:8080/ipfs/{row['vhash']}" url = f"{row['webpage_url']}" f.write(f"\t\t\tOpen on IPFS
\n") f.write(f"\t\t\tTitle:{fiveSpaces} {row['title']}
\n") f.write(f"\t\t\tSource:{fiveSpaces} {url}
\n") f.write(f"\t\t\tDescription:\n") f.write(f"\t\t\t{row['description']}
\n") # Remainder of columns will only be visible with "show page source" f.write(f"