-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
59 lines (47 loc) · 2.17 KB
/
models.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
from config import cfg_file
# Configure the database and access layer
from sqlalchemy import create_engine
from sqlalchemy import Boolean, Column, DateTime, Enum, Integer, String, Text
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
if cfg_file.get('database', 'system').lower() == 'sqlite':
engine = create_engine(
cfg_file.get('database', 'system')+':///'+\
cfg_file.get('database', 'database'))
else:
engine = create_engine(
cfg_file.get('database', 'system')+'://'+\
cfg_file.get('database', 'username')+':'+\
cfg_file.get('database', 'password')+'@'+\
cfg_file.get('database', 'host')+'/'+\
cfg_file.get('database', 'database'))
# initialize connection and session object
Base = declarative_base()
Session = sessionmaker(bind=engine, expire_on_commit=False)
session = Session()
# Initial setup:
# $ python
# >>> from models import *
# >>> Base.metadata.create_all(engine)
class Subreddit(Base):
"""Subreddits for the bot to monitor.
name - The subreddit's name. "gaming", not "/r/gaming".
enabled - Subreddit will not be checked if False
conditions_yaml - YAML definition of the subreddit's conditions
last_submission - The newest unfiltered submission the bot has seen
last_comment - The newest comment the bot has seen
last_spam - The newest filtered submission the bot has seen
# unused; template for mirroring other subreddit configuration options
exclude_banned_modqueue - Should mirror the same setting's value on the
subreddit. Used to determine if it's necessary to check whether
submitters in the modqueue are shadowbanned or not.
"""
__tablename__ = 'subreddits'
id = Column(Integer, primary_key=True)
name = Column(String(100), nullable=False, unique=True)
enabled = Column(Boolean, nullable=False, default=True)
conditions_yaml = Column(Text, nullable=False, default='')
last_submission = Column(DateTime, nullable=False)
last_comment = Column(DateTime, nullable=False)
last_spam = Column(DateTime, nullable=False)
# exclude_banned_modqueue = Column(Boolean, nullable=False, default=False)