· 8 years ago · May 28, 2018, 01:22 PM
1# Import database language
2import sqlite3
3# Load in the lines from the datadump we are going to use
4import json
5# Import datetime to output logging information as we are iterating through data dumps
6from datetime import datetime
7
8# Search through the file with this format ('yyyy-mm')
9timeframe = '2015-01'
10# Build up a big transaction of rows in the database and insert all rows at the same time
11sql_transaction = []
12
13'''Connect to SQLite 3 database and make the database have a name consisting of month and year of the Reddit Comment file.
14If the connection to the database fails, the database will be created automatically.'''
15connection = sqlite3.connect('{}.db'.format(timeframe))
16# Define the cursor
17c = connection.cursor()
18
19
20# Store parent ID, comment ID, parent comment, reply comment, subreddit, the time and the scores (votes) for the comment
21def create_table():
22 c.execute(
23 "CREATE TABLE IF NOT EXISTS parent_reply(parent_id TEXT PRIMARY KEY, comment_id TEXT UNIQUE, parent TEXT, comment TEXT, subreddit TEXT, unix INT, score INT)")