newtheme #4
|
@ -3,6 +3,7 @@ import dotenv
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import ujson
|
import ujson
|
||||||
|
import frontmatter
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
|
@ -11,6 +12,38 @@ def cli():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.option("--folder", type=click.Path(dir_okay=True, file_okay=False), required=True)
|
||||||
|
@click.option("--old_type", type=str, required=True)
|
||||||
|
@click.option("--new_type", type=str, required=True)
|
||||||
|
def fix_post_types(folder: str, old_type: str, new_type: str):
|
||||||
|
"""Fix post type metadata"""
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(folder):
|
||||||
|
|
||||||
|
for file in files:
|
||||||
|
if file.endswith(".md"):
|
||||||
|
full_path = os.path.join(root,file)
|
||||||
|
data = frontmatter.load(full_path)
|
||||||
|
|
||||||
|
print(f"Analysing... {full_path}")
|
||||||
|
|
||||||
|
if 'type' not in data:
|
||||||
|
print(f"Skipping {full_path} due to incomplete frontmatter")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if(data['type'] == old_type):
|
||||||
|
print(f"Update type for {full_path}: {old_type}->{new_type}")
|
||||||
|
data['type'] = new_type
|
||||||
|
|
||||||
|
with open(full_path,'wb') as f:
|
||||||
|
frontmatter.dump(data, f)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option("--mentions-file", type=click.Path(file_okay=True), required=True)
|
@click.option("--mentions-file", type=click.Path(file_okay=True), required=True)
|
||||||
def fetch_mentions(mentions_file: str):
|
def fetch_mentions(mentions_file: str):
|
||||||
|
|
|
@ -100,6 +100,21 @@ python-versions = ">=3.5"
|
||||||
[package.extras]
|
[package.extras]
|
||||||
cli = ["click (>=5.0)"]
|
cli = ["click (>=5.0)"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "python-frontmatter"
|
||||||
|
version = "1.0.0"
|
||||||
|
description = "Parse and manage posts with YAML (or other) frontmatter"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
PyYAML = "*"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
docs = ["sphinx"]
|
||||||
|
test = ["pytest", "toml", "pyaml"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyyaml"
|
name = "pyyaml"
|
||||||
version = "6.0"
|
version = "6.0"
|
||||||
|
@ -186,7 +201,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.7"
|
python-versions = "^3.7"
|
||||||
content-hash = "e29e6aa9b8aa53841b7b54c35483d1ae5ca4179793ce600d3cf96be58136d303"
|
content-hash = "37f6b249fc390c867f7f098d6b2a25155384e22a69faa6bb1276e93d559f3450"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
beautifulsoup4 = []
|
beautifulsoup4 = []
|
||||||
|
@ -219,6 +234,7 @@ python-dotenv = [
|
||||||
{file = "python-dotenv-0.19.2.tar.gz", hash = "sha256:a5de49a31e953b45ff2d2fd434bbc2670e8db5273606c1e737cc6b93eff3655f"},
|
{file = "python-dotenv-0.19.2.tar.gz", hash = "sha256:a5de49a31e953b45ff2d2fd434bbc2670e8db5273606c1e737cc6b93eff3655f"},
|
||||||
{file = "python_dotenv-0.19.2-py2.py3-none-any.whl", hash = "sha256:32b2bdc1873fd3a3c346da1c6db83d0053c3c62f28f1f38516070c4c8971b1d3"},
|
{file = "python_dotenv-0.19.2-py2.py3-none-any.whl", hash = "sha256:32b2bdc1873fd3a3c346da1c6db83d0053c3c62f28f1f38516070c4c8971b1d3"},
|
||||||
]
|
]
|
||||||
|
python-frontmatter = []
|
||||||
pyyaml = [
|
pyyaml = [
|
||||||
{file = "PyYAML-6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53"},
|
{file = "PyYAML-6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53"},
|
||||||
{file = "PyYAML-6.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c"},
|
{file = "PyYAML-6.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c"},
|
||||||
|
|
|
@ -15,6 +15,7 @@ PyYAML = "^6.0"
|
||||||
click = "^8.0.3"
|
click = "^8.0.3"
|
||||||
python-dotenv = "^0.19.2"
|
python-dotenv = "^0.19.2"
|
||||||
markdownify = "^0.11.6"
|
markdownify = "^0.11.6"
|
||||||
|
python-frontmatter = "^1.0.0"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue