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:
def __processor(file):
data = json.load(file)
for i in tqdm(range(14000), desc="Splatted: "):
obj_cnt = '' obj_cnt = ''
lst = list() lst = list()
for characters in data[f"{i}"][tag]:
try:
for characters in data[f"{i}"]["title"]:
lst.append(characters) lst.append(characters)
obj_cnt = ''.join(lst) obj_cnt = ''.join(lst)
return obj_cnt
except Exception as ignore:
print(f"We have a Exception!! {ignore.with_traceback}")
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 def __processor(file):
__object_clear(lst) data = json.load(file)
__writer(i, title, content, url) for i in tqdm(range(14000), desc="Splatted: "):
except Exception as ignore: title = __retrieval(data, i, "title")
pass content = __retrieval(data, i, "content")
url = __retrieval(data, i, "url")
tags = __retrieval(data, i, "tags")
date = __retrieval(data, i, "date")
category = __retrieval(data, i, "category")
__writer(i, title, content, url, tags, date, category)
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