Commit 88bb2e3d authored by Haj Rezvan's avatar Haj Rezvan

Optimized the functions.

parent d2249df1
...@@ -13,51 +13,42 @@ def file_open(): ...@@ -13,51 +13,42 @@ def file_open():
__processor(file) __processor(file)
def __writer(doc_id, title, content, url): def __writer(doc_id, title, content, url, tags, date, category):
file = open(f"docs/{doc_id}.json", "w") file = open(f"docs/{doc_id}.json", "w")
dictionary = { dictionary = {
"doc_id": doc_id, "doc_id": doc_id,
"title": title, "title": title,
"content": content, "content": content,
"url": url "tags": tags,
"date": date,
"url": url,
"category": category
} }
json.dump(dictionary, file) json.dump(dictionary, file)
def __object_clear(lst): def __retrieval(data, i, tag):
lst.clear() try:
obj_cnt = ''
lst = list()
for characters in data[f"{i}"][tag]:
lst.append(characters)
obj_cnt = ''.join(lst)
return obj_cnt
except Exception as ignore:
print(f"We have a Exception!! {ignore.with_traceback}")
def __processor(file): def __processor(file):
data = json.load(file) data = json.load(file)
for i in tqdm(range(14000), desc="Splatted: "): for i in tqdm(range(14000), desc="Splatted: "):
obj_cnt = '' title = __retrieval(data, i, "title")
lst = list() content = __retrieval(data, i, "content")
url = __retrieval(data, i, "url")
try: tags = __retrieval(data, i, "tags")
for characters in data[f"{i}"]["title"]: date = __retrieval(data, i, "date")
lst.append(characters) category = __retrieval(data, i, "category")
obj_cnt = ''.join(lst)
__writer(i, title, content, url, tags, date, category)
title = obj_cnt
__object_clear(lst)
for characters in data[f"{i}"]["content"]:
lst.append(characters)
obj_cnt = ''.join(lst)
content = obj_cnt
__object_clear(lst)
for characters in data[f"{i}"]["url"]:
lst.append(characters)
obj_cnt = ''.join(lst)
url = obj_cnt
__object_clear(lst)
__writer(i, title, content, url)
except Exception as ignore:
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment