2016-11-26 23:09:12 -06:00
|
|
|
from ..model import User, Category, Forum, Board, Post, Thread
|
2016-11-27 02:04:54 -06:00
|
|
|
from ..util import sanitize_title
|
2016-11-26 23:09:12 -06:00
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
|
|
|
def output (data, destination):
|
|
|
|
if isinstance(data, Forum):
|
|
|
|
output_forum(data, destination)
|
|
|
|
elif isinstance(data, Board):
|
|
|
|
output_board(data, destination)
|
|
|
|
elif isinstance(data, Thread):
|
|
|
|
output_thread(data, destination)
|
|
|
|
|
|
|
|
def output_forum (data, destination):
|
|
|
|
os.makedirs(destination)
|
2016-11-26 23:54:05 -06:00
|
|
|
|
|
|
|
with open(os.path.join(destination, "index.json"), "w") as out_file:
|
2016-11-27 21:14:49 -06:00
|
|
|
out_file.write(json.dumps({"title": data.title}, indent=4))
|
2016-11-26 23:54:05 -06:00
|
|
|
|
2016-11-26 23:09:12 -06:00
|
|
|
for category in data.categories:
|
2016-11-27 21:15:39 -06:00
|
|
|
os.makedirs(os.path.join(destination, sanitize_title(category.title)))
|
2016-11-26 23:09:12 -06:00
|
|
|
for board in category.children:
|
2016-11-27 21:15:39 -06:00
|
|
|
output_board(board, os.path.join(destination, sanitize_title(category.title), sanitize_title(board.title)))
|
2016-11-26 23:09:12 -06:00
|
|
|
|
|
|
|
def output_board (data, destination):
|
|
|
|
os.makedirs(destination)
|
2016-11-26 23:54:05 -06:00
|
|
|
os.makedirs(os.path.join(destination, "threads"))
|
|
|
|
with open(os.path.join(destination, "index.json"), "w") as out_file:
|
2016-11-27 01:21:07 -06:00
|
|
|
out_file.write(json.dumps({
|
|
|
|
"title": data.title,
|
|
|
|
"description": data.description
|
|
|
|
}, indent=4))
|
2016-11-26 23:54:05 -06:00
|
|
|
|
2016-11-26 23:09:12 -06:00
|
|
|
for thread in data.children:
|
2016-11-27 02:04:54 -06:00
|
|
|
output_thread(thread, os.path.join(destination, "threads", sanitize_title(thread.title)))
|
2016-11-26 23:09:12 -06:00
|
|
|
|
|
|
|
def output_thread (data, destination):
|
|
|
|
with open(destination, "w") as out_file:
|
|
|
|
out_file.write(json.dumps(data, default=vars, indent=4))
|