Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- import sqlite3
- import os
- import re
- conn = sqlite3.connect("Threads.db")
- c = conn.cursor()
- c.execute('''CREATE TABLE IF NOT EXISTS threads(ID INTEGER, Title TEXT, Author TEXT, Date TEXT)''')
- for i in os.listdir('Threads'):
- print('Adding file: Threads/{}'.format(i))
- file = open('Threads/'+i, 'r').read()
- findauthor = re.findall(r"Posted By:</b>[\s\S]*?\w+", file)
- author = findauthor[0].replace("Posted By:</b>","").replace(' ','')
- # print(author)
- findtitle = re.findall(r'<font color="navy">[\s\S]*?</font>', file)
- title = findtitle[0].replace('<font color="navy">','').replace('</font>','')
- # print(title)
- finddate = re.findall(r'Date Posted:</b>[\s\S]*?M<br>', file)
- date = finddate[0].replace('Date Posted:</b>','').replace(' ','').replace('<br>','').replace('\n','')
- date_split = date.split('/')
- month = date_split[0]
- day = int(date_split[1])
- year = int(date_split[2].split(' ')[0])
- time = ' '.join(date_split[2].split(' ')[1:])
- hours = int(time.split(':')[0])
- minutes = int(''.join(time.split(':')[1:]).split(' ')[0])
- am_pm = ''.join(time.split(':')[1:]).split(' ')[1]
- months={
- 'Jan': 1,
- 'Feb': 2,
- 'Mar': 3,
- 'Apr': 4,
- 'May': 5,
- 'Jun': 6,
- 'Jul': 7,
- 'Aug': 8,
- 'Sep': 9,
- 'Oct': 10,
- 'Nov': 11,
- 'Dec': 12
- }
- month = months[month]
- date_final = '{}-{:02d}-{:02d} {:02d}:{:02d} {}'.format(year, month, day, hours, minutes, am_pm)
- c.execute("INSERT INTO threads VALUES (?, ?, ?, ?)", (int(i.replace('.html','')), title, author, date_final))
- conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment