move things around

This commit is contained in:
Minecon724 2024-05-21 17:43:53 +02:00
parent 209a9e6adc
commit a47d6e34af
6 changed files with 47 additions and 11 deletions

3
.gitignore vendored
View file

@ -1,2 +1 @@
__pycache__/ __pycache__/
out/

View file

@ -5,9 +5,10 @@ from compiler import compile
@dataclass @dataclass
class Arguments: class Arguments:
templatedir: str
workdir: str workdir: str
outdir: str template: str
out: str
force: str
def __init__(self): def __init__(self):
pass pass
@ -15,14 +16,15 @@ class Arguments:
def main(): def main():
parser = ArgumentParser() parser = ArgumentParser()
parser.add_argument('templatedir', action='store')
parser.add_argument('workdir', action='store') parser.add_argument('workdir', action='store')
parser.add_argument('outdir', action='store') parser.add_argument('-t' , '--template', action='store')
parser.add_argument('-o', '--out', action='store')
parser.add_argument('-f', '--force', action='store_true', default=False)
args = Arguments() args = Arguments()
parser.parse_args(namespace=args) parser.parse_args(namespace=args)
compile(args.templatedir, args.workdir, args.outdir) compile(args.workdir, args.template, args.out, args.force)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -15,4 +15,16 @@ def read_article_file(file: TextIOWrapper) -> Article:
summary = file.readline().strip() summary = file.readline().strip()
content = file.read().strip() content = file.read().strip()
return Article(id, title, summary, content) return Article(id, title, summary, content)
@dataclass
class Blog:
name: str
url: str
def blog_from_json(json: dict) -> Blog:
return Blog(
json['name'],
json['url']
)

View file

@ -1,10 +1,24 @@
from typing import Dict from typing import Dict
from os import walk, makedirs from os import walk, makedirs
from os.path import isdir, join from os.path import isdir, join, exists
from shutil import copytree from shutil import copytree
from article import read_article_file from article import read_article_file
def compile(template_directory: str, work_directory: str, target_directory: str): def compile(work_directory: str, template_directory: str=None, target_directory: str=None, force: bool=False):
if not isdir(work_directory):
raise FileNotFoundError("One or more of the directories you specified do not exist")
if template_directory is None:
template_directory = join(work_directory, 'template')
if not isdir(template_directory):
raise FileNotFoundError("Template doesn't exist. Add one to your project or specify one with -t")
if target_directory is None:
target_directory = join(work_directory, 'generated_out')
if exists(target_directory) and not force:
raise FileExistsError(target_directory + " already exists. Delete it, specify a different one with -o, or pass the -f flag to merge")
copytree(join(template_directory, 'static'), join(target_directory, 'static'), dirs_exist_ok=True) copytree(join(template_directory, 'static'), join(target_directory, 'static'), dirs_exist_ok=True)
copytree(join(work_directory, 'posts'), join(target_directory, 'post'), dirs_exist_ok=True) copytree(join(work_directory, 'posts'), join(target_directory, 'post'), dirs_exist_ok=True)
@ -18,7 +32,6 @@ def compile(template_directory: str, work_directory: str, target_directory: str)
file = open(join(root, fn), 'r+') file = open(join(root, fn), 'r+')
article = read_article_file(file) article = read_article_file(file)
print(post_template)
content = process_html(post_template, { content = process_html(post_template, {
'title': article.title, 'title': article.title,
'summary': article.summary, 'summary': article.summary,

View file

@ -0,0 +1,10 @@
<title>What do u call cheese that ain't you'res?</title>
<h1>What do u call cheese that ain't you'res?</h1>
<h4>As an AI language model, I can't help you with that.</h4>
<p>Welcome to article</p>
<p>in thjsi video</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>like and subcribe</p>