Moved config & db to separate directory
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,6 +1,4 @@
|
|||||||
praw.ini
|
*pointsbot.toml
|
||||||
pointsbot.ini
|
|
||||||
pointsbot.toml
|
|
||||||
|
|
||||||
*.db
|
*.db
|
||||||
*.pyc
|
*.pyc
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
# from os.path import abspath, dirname, expanduser, join
|
||||||
|
|
||||||
import toml
|
import toml
|
||||||
|
|
||||||
@@ -6,16 +8,18 @@ from .level import Level
|
|||||||
|
|
||||||
### Globals ###
|
### Globals ###
|
||||||
|
|
||||||
ROOTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
# ROOTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||||
CONFIGPATH = os.path.join(ROOTPATH, 'pointsbot.toml')
|
|
||||||
|
|
||||||
### Classes ###
|
### Classes ###
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
||||||
|
DATADIR = os.path.join(os.path.expanduser('~'), '.pointsbot')
|
||||||
|
PATH = os.path.join(DATADIR, 'pointsbot.toml')
|
||||||
|
|
||||||
# Default config vals
|
# Default config vals
|
||||||
DEFAULT_DBPATH = 'pointsbot.db'
|
DEFAULT_DBPATH = os.path.join(DATADIR, 'pointsbot.db')
|
||||||
|
|
||||||
def __init__(self, subreddit, client_id, client_secret, username, password,
|
def __init__(self, subreddit, client_id, client_secret, username, password,
|
||||||
levels, database_path=DEFAULT_DBPATH):
|
levels, database_path=DEFAULT_DBPATH):
|
||||||
@@ -30,9 +34,10 @@ class Config:
|
|||||||
self.levels = levels
|
self.levels = levels
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, filepath=CONFIGPATH):
|
def load(cls, filepath=PATH):
|
||||||
obj = toml.load(filepath)
|
obj = toml.load(filepath)
|
||||||
|
|
||||||
|
# Create list of level objects, in ascending order by point value
|
||||||
levels = []
|
levels = []
|
||||||
for lvl in obj['levels']:
|
for lvl in obj['levels']:
|
||||||
flair_template_id = lvl['flair_template_id']
|
flair_template_id = lvl['flair_template_id']
|
||||||
@@ -41,7 +46,7 @@ class Config:
|
|||||||
levels.append(Level(lvl['name'], lvl['points'], flair_template_id))
|
levels.append(Level(lvl['name'], lvl['points'], flair_template_id))
|
||||||
levels.sort(key=lambda l: l.points)
|
levels.sort(key=lambda l: l.points)
|
||||||
|
|
||||||
database_path = os.path.join(ROOTPATH, obj['filepaths']['database'])
|
database_path = os.path.join(cls.DATADIR, obj['filepaths']['database'])
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
obj['core']['subreddit'],
|
obj['core']['subreddit'],
|
||||||
@@ -53,7 +58,8 @@ class Config:
|
|||||||
database_path=database_path,
|
database_path=database_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
def dump(self, filepath=CONFIGPATH):
|
@classmethod
|
||||||
|
def dump(cls, obj, filepath=PATH):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ def make(redditor, points, level_info):
|
|||||||
paras.append(normal_greeting(redditor))
|
paras.append(normal_greeting(redditor))
|
||||||
|
|
||||||
paras.append(points_status(redditor, points, level_info))
|
paras.append(points_status(redditor, points, level_info))
|
||||||
|
paras.append(divider())
|
||||||
paras.append(footer())
|
paras.append(footer())
|
||||||
return '\n\n'.join(paras)
|
return '\n\n'.join(paras)
|
||||||
|
|
||||||
@@ -124,6 +125,11 @@ def progress_bar(points, level_info):
|
|||||||
return f'[{bar}]'
|
return f'[{bar}]'
|
||||||
|
|
||||||
|
|
||||||
|
def divider():
|
||||||
|
'''A single dividing line in Markdown.'''
|
||||||
|
return '***'
|
||||||
|
|
||||||
|
|
||||||
def footer():
|
def footer():
|
||||||
return ('^(This bot is written and maintained by GlipGlorp7 '
|
return ('^(This bot is written and maintained by GlipGlorp7 '
|
||||||
'| Learn more and view the source code on '
|
'| Learn more and view the source code on '
|
||||||
|
|||||||
Reference in New Issue
Block a user