Skip to content

Commit

Permalink
fix(contact): add matching regex logic (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
delphox60 committed Oct 29, 2023
1 parent 0a334fc commit dcdbba6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions content_generator/_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from os import remove, listdir
import re
from typing import List

GoogleSheetResult = List[List[str]]
Expand Down Expand Up @@ -295,16 +296,18 @@ def make_contacts(contact_us: GoogleSheetResult, faq: GoogleSheetResult) -> None
}
_faqs.append(_faq)

content_file_pattern = re.compile("[0-9]+\.json")

for filename in listdir("./content/contacts"):
if filename.endswith(".json"):
if content_file_pattern.match(filename):
remove(f"./content/contacts/{filename}")

for idx, _contact in enumerate(_contacts):
with open(f"./content/contacts/{idx}.json", mode="w", encoding="utf-8") as f:
f.write(json.dumps(_contact, ensure_ascii=False, indent=2))

for filename in listdir("./content/contacts/faq"):
if filename.endswith(".json"):
if content_file_pattern.match(filename):
remove(f"./content/contacts/faq/{filename}")

for idx, _faq in enumerate(_faqs):
Expand Down

0 comments on commit dcdbba6

Please sign in to comment.