Skip to content

Commit

Permalink
fixed nested key issues and added live links checking
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpaudel93 committed Jul 19, 2020
1 parent 2a3d48d commit 46bcec2
Show file tree
Hide file tree
Showing 9 changed files with 652 additions and 284 deletions.
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
venv
.vscode
.idea
__pycache__/*
__pycache__/*

# Compiled python modules.
*.pyc

# Setuptools distribution folder.
/dist/

# Python egg metadata, regenerated from source files by setuptools.
/*.egg-info

build/*
5 changes: 4 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ pylint = "*"

[packages]
pycountry = "*"
requests = "*"
aiohttp = "*"
asyncio = "*"

[requires]
python_version = "3.8.2"
python_version = "3.6"
263 changes: 229 additions & 34 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/lib/m3u_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .m3u_parser import M3uParser
248 changes: 0 additions & 248 deletions m3uParser.py

This file was deleted.

1 change: 1 addition & 0 deletions m3u_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .m3u_parser import M3uParser
60 changes: 60 additions & 0 deletions m3u_parser/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import re

# check if the regex is present or not
def is_present(regex, content):
match = re.search(re.compile(regex, flags=re.IGNORECASE), content)
return match.group(1) if match else ""


def is_dict(item, ans=None):
if ans is None:
ans = []
tree = []
for k, v in item.items():
if isinstance(v, dict):
ans.append(str(k))
tree.extend(is_dict(v, ans))
ans = []
else:
if ans:
ans.append(str(k))
key = ','.join(ans).replace(',', '_')
tree.extend([(key, str(v))])
ans.remove(str(k))
else:
tree.extend([(str(k), str(v))])
return tree


def get_tree(item):
tree = []
if isinstance(item, dict):
tree.extend(is_dict(item, ans=[]))
elif isinstance(item, list):
tree = []
for i in item:
tree.append(get_tree(i))
return tree


def render_csv(header, data, out_path='output.csv'):
input = []
with open(out_path, 'w') as f:
dict_writer = csv.DictWriter(f, fieldnames=header)
dict_writer.writeheader()
if not isinstance(data[0], list):
input.append(dict(data))
else:
for i in data:
input.append(dict(i))
dict_writer.writerows(input)
return

# convert nested dictionary to csv
def ndict_to_csv(obj, output_path):
tree = get_tree(obj)
if isinstance(obj, list):
header = [i[0] for i in tree[0]]
else:
header = [i[0] for i in tree]
return render_csv(header, tree, output_path)
Loading

0 comments on commit 46bcec2

Please sign in to comment.