<commit_before>import sys, urllib.request, xmltv, xml.etree.ElementTree as ET
from datetime import datetime, date, time, timedelta

BASE_URL = "https://appletv-v2.redbull.tv/views/tv"
request = urllib.request.Request(BASE_URL, headers={"Accept" : "application/xml"})
response = urllib.request.urlopen(request)
xml = ET.parse(response)
items = xml.findall('.//twoLineMenuItem')

for element in items:
    label = ''
    if element.find('.//label') is not None:
        label = element.find('.//label').text
    label2 = ''
    if element.find('.//label2') is not None:
        label2 = element.find('.//label2').text
    start = ''
    if element.find('.//rightLabel') is not None:
        start = element.find('.//rightLabel').text
        if start is not None:
            start = datetime.utcfromtimestamp(float(start)).strftime('%Y%m%d%H%M%S%z')
    summary = ''
    if element.find('.//summary') is not None:
        summary = element.find('.//summary').text
    print(label + ' - ' + label2)
    print(start)<commit_msg>calc end time<commit_after>import sys, re, urllib.request, xmltv, xml.etree.ElementTree as ET
from datetime import datetime, date, time, timedelta

BASE_URL = "https://appletv-v2.redbull.tv/views/tv"
request = urllib.request.Request(BASE_URL, headers={"Accept" : "application/xml"})
response = urllib.request.urlopen(request)
xml = ET.parse(response)
items = xml.findall('.//twoLineMenuItem')

for element in items:
    label = ''
    if element.find('.//label') is not None:
        label = element.find('.//label').text
    label2 = ''
    if element.find('.//label2') is not None:
        label2 = element.find('.//label2').text
    start = ''
    if element.find('.//rightLabel') is not None:
        start = element.find('.//rightLabel').text
        if start is not None:
            start = datetime.utcfromtimestamp(float(start))#.strftime('%Y%m%d%H%M%S%z')
        else:
            start = datetime.utcnow()#.strftime('%Y%m%d%H%M%S%z')

    # Set end has start to calculate duration from
    end = ''
    if element.find('.//footnote') is not None:
        end = element.find('.//footnote').text
        if end is not None:
            duration = end.replace('Duration: ', '')
            duration = duration.split(',')
            totalDuration = start
            for i in duration:
                if 'hour' in i:
                    totalDuration = totalDuration + timedelta(hours=int(re.sub(r' hours?', "",i)))
                elif 'minute' in i:
                    totalDuration = totalDuration + timedelta(minutes=int(re.sub(r' minutes?', "", i)))
                elif 'second' in i:
                    totalDuration = totalDuration + timedelta(seconds=int(re.sub(r' seconds?', "", i)))
            end = totalDuration

    summary = ''
    if element.find('.//summary') is not None:
        summary = element.find('.//summary').text
   # print(duration)
    print(label + ' - ' + label2)
    print(start)
    print(end)
{'fraction_non_alphanumeric': 0.16025641025641027, 'fraction_numerical': 0.004048582995951417, 'mean_word_length': 2.5895883777239708, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3996877', 'n_tokens_mistral': 925, 'n_tokens_neox': 901, 'n_words': 211}