import csv
import sys
from glob import glob
import sqlite3

conn = sqlite3.connect('e621.db')
conn.execute('DELETE FROM post')
csv.field_size_limit(sys.maxsize)

with open(glob('posts-*')[0]) as csvfile:
	posts = csv.reader(csvfile, delimiter=',', quotechar='"')

	i = 0
	for p in posts:

		i += 1
		if i == 1:
			continue

		if i%10000 == 0:
			print(p[0], end='\r')
			conn.commit()

		conn.execute('INSERT INTO post(id, file_id, tags) VALUES (?,?,?)', (int(p[0]), p[3]+'.'+p[11], p[8]))

	conn.commit()
