2017-10-10 14:13:35 +03:00
|
|
|
""" Module for parsing bouquets """
|
|
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
|
|
__BOUQUETS_PATH = "../data/"
|
|
|
|
|
|
|
|
|
|
Bouquet = namedtuple("Bouquet", ["name", "type"])
|
|
|
|
|
Bouquets = namedtuple("Bouquets", ["name", "bouquets"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_bouquets(path):
|
|
|
|
|
return [parse_bouquets(path, "bouquets.tv"), parse_bouquets(path, "bouquets.radio")]
|
|
|
|
|
|
|
|
|
|
|
2017-10-20 19:03:22 +03:00
|
|
|
def write_bouquets(path, channels):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2017-10-10 14:13:35 +03:00
|
|
|
def get_bouquet(path, name, type):
|
2017-10-11 23:22:30 +03:00
|
|
|
with open(path + "userbouquet.{}.{}".format(name, str(type))) as file:
|
|
|
|
|
chs_list = file.read()
|
|
|
|
|
ids = []
|
|
|
|
|
for ch in chs_list.split("#SERVICE")[1:]:
|
|
|
|
|
ch_data = ch.strip().split(":")
|
|
|
|
|
ids.append("{}:{}:{}:{}".format(ch_data[3], ch_data[4], ch_data[5], ch_data[6]))
|
|
|
|
|
return ids
|
2017-10-10 14:13:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_bouquets(path, name):
|
|
|
|
|
with open(path + name) as file:
|
|
|
|
|
lines = file.readlines()
|
|
|
|
|
bouquets = None
|
|
|
|
|
nm_sep = "#NAME"
|
|
|
|
|
for line in lines:
|
|
|
|
|
if nm_sep in line:
|
|
|
|
|
_, _, name = line.partition(nm_sep)
|
|
|
|
|
bouquets = Bouquets(name.strip(), [])
|
|
|
|
|
if bouquets is not None and "#SERVICE" in line:
|
|
|
|
|
bouquets[1].append(line.split(".")[1])
|
|
|
|
|
return bouquets
|
|
|
|
|
|
|
|
|
|
|
2017-10-07 17:33:40 +03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
pass
|