comments/ext.py

51 lines
1.1 KiB
Python

# comments/ext.py
# (c) 2020 Derek Stevens <nilix@nilfm.cc>
# this is a helper script to initialize comment threads externally
# move this to the project directory and change the settings imports accordingly
import sys
from django.conf import settings
import nilfm.settings as nilfm_settings
settings.configure(INSTALLED_APPS=nilfm_settings.INSTALLED_APPS, DATABASES=nilfm_settings.DATABASES)
import django
django.setup()
from comments.models import Comment, Thread
def echo(*args):
threads = Thread.objects.all();
for t in threads:
print(t)
c = t.root_comment
print(c)
if c:
c = c.next
print(c)
def create(id):
x = Thread(thread_id=id, )
x.save()
def postTo(**kwargs):
id = kwargs["id"]
name = kwargs["name"]
mail = kwargs["mail"]
data = kwargs["data"]
t = Thread.objects.get(pk=id)
current = t.root_comment
if current:
while current:
current = current.next
current = Comment(comment_author=name, comment_author_email=mail, comment_data=data)
current.save()
options = {
"echo": echo,
"create": create,
"postTo": postTo
}
options[sys.argv[1]](sys.argv[2:])