Advertisement
Zalati

XMLTV time offset

Jul 1st, 2021
1,299
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from lxml import etree
  2. import sys
  3. import requests
  4.  
  5. while True:
  6.     try:
  7.         URL = 'http://example.com'
  8.  
  9.         response = requests.get(URL)
  10.         with open('xmltv-utc.xml', 'wb') as file:
  11.             file.write(response.content)
  12.  
  13.         xml_file = "xmltv-utc.xml"
  14.         xml_file_output = 'xmltv-france.xml'
  15.  
  16.         parser = etree.XMLParser(remove_comments=False)
  17.         tree = etree.parse(xml_file, parser)
  18.         root = tree.getroot()
  19.  
  20.         for programme in root.iter("programme"):
  21.             replaced_time_offset_start = programme.get("start").replace("+0000", "+0200")
  22.             replaced_time_offset_stop = programme.get("stop").replace("+0000", "+0200")
  23.             programme.set("start", replaced_time_offset_start)
  24.             programme.set("stop", replaced_time_offset_stop)
  25.  
  26.         tree.write(xml_file_output)
  27.         raise SystemExit
  28.     except SystemExit:
  29.         exit()
  30.     except:
  31.         pass
  32.  
  33.  
Advertisement
RAW Paste Data Copied
Advertisement