def test_get_channels(self): m = member.Member() m.add_channel("asd") self.assertEqual(m.get_channels(), ["asd"]) m.add_channels(["asd1", "asd2"]) self.assertEqual(m.get_channels(), ["asd", "asd1", "asd2"]) m = member.Member() m.add_channel("asd") self.assertEqual(m.get_channels(), ["asd"]) m.add_channels(["asd1", "asd2"]) self.assertEqual(m.get_channels(), ["asd", "asd1", "asd2"])
def test_get_time(self): m = member.Member() m.set_time("12:00", "13:00") self.assertEqual(m.get_start_time(), "12:00") self.assertEqual(m.get_end_time(), "13:00") self.assertRaises(Exception, m.set_time, "22:22", "11:11") m = member.Member() m.set_time("12:00", "13:00") self.assertEqual(m.get_start_time(), "12:00") self.assertEqual(m.get_end_time(), "13:00") self.assertRaises(Exception, m.set_time, "22:22", "11:11")
def parse_xml_member(xml_file): mem = member.Member() with open(xml_file) as f: file = f.read() r = ET.fromstring(file) for ch in r.getchildren(): if ch.tag == "region": for child in ch.getchildren(): startTime = None endTime = None if child.tag == "name": mem.set_region(child.text) if child.tag == "date": mem.set_date(child.text) if child.tag == "startTime": startTime = child.text if child.tag == "endTime": endTime = child.text if (startTime is not None) and (endTime is not None): print(startTime + "\n" + endTime) mem.set_time(startTime, endTime) return mem
def test_get_date(self): m = member.Member() m.set_date("29.11.1233") self.assertEqual(m.get_date(), "29.11.1233")
def test_get_region(self): m = member.Member() m.set_region("test") self.assertEqual(m.get_region(), "test")
items = ET.SubElement(result, 'items') for elem in responseData: channel = ET.SubElement(items, 'сhannel') channel.set("name", elem[0]) for programm in elem[1]: pr = ET.SubElement(channel, 'tmp') pr.text = programm et = ET.tostring(result, 'utf-8') parsed = minidom.parseString(et) pretty = parsed.toprettyxml(indent="\t") with open(xml_result_file, "w") as f: f.write(pretty) # parse_xml('./channels.xml') m = member.Member('US', '2018-03-13', '00:00', '22:00') with open('./channels.xml') as f: xml = f.read() root = etree.fromstring(xml) for ch in root.getchildren(): for f in ch.getchildren(): if f.tag == "channels": for channel in f.getchildren(): m.add_channel(channel.text) r = request.Request() r.set_date(m.get_date()) r.set_region(m.get_region()) r.set_time(m.get_start_time(), m.get_end_time())