-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_common_reposts.py
58 lines (40 loc) · 1.45 KB
/
update_common_reposts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import datetime
import json
import praw
import re
import sqlite3
import time
from sqlite3 import Connection, Error
from process_comment import decode_blob, encode_blob
config = json.load(open('config.json'))
print(datetime.datetime.fromtimestamp(int(time.time()), tz=datetime.UTC).strftime("%b %d, %Y %I:%M %p"))
print(str(b'test', 'utf-8'))
def create_connection(path: str) -> Connection:
connection = None
try:
connection = sqlite3.connect(path)
print("Connected to the posts database")
except Error as e:
print(f"The error '{e}' occurred")
raise Exception("Failed to connect to posts database")
return connection
# Script to clean up all old posts. Run if posts gets cluttered somehow.
conn = create_connection('posts.db')
c = conn.cursor()
reddit = praw.Reddit(client_id=config['id'],
client_secret=config['secret'],
user_agent=config['agent'],
username=config['username'],
password=config['password'])
print("Connected to reddit")
subreddit = reddit.subreddit("wholesomehentai")
subreddit_wiki = subreddit.wiki
content = subreddit_wiki['commonreposts'].content_md
matcher = re.compile(r'https?://nhentai\.net/g/\d{1,6}/')
items = matcher.findall(content)
for item in items:
c.execute('SELECT * FROM commonreposts WHERE source=?', (item,))
if not c.fetchone():
print(f"Found URL: {item}")
c.execute('INSERT INTO commonreposts VALUES (?)', (item,))
conn.commit()