home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Products
TV-Server
Zap2it free TV listings XML is no more.
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="smnsparty" data-source="post: 1302366" data-attributes="member: 172316"><p>This is one of the top search results for WMC having stopped working; thanks everyone for the useful information!</p><p></p><p>My shell scripting skills are very rusty these days, so for those like me who are still rocking Windows 7's (or some later version of) WMC, I thought I'd post the (rather hacky) Python script I'm using as a drop-in replacement for updating the hosts file and then launching a batch script to download and process the TV guide. In order to run this script, the following assumptions need to be met.</p><ol> <li data-xf-list-type="ol">User has Administrator privileges</li> <li data-xf-list-type="ol">Python is installed on the system</li> <li data-xf-list-type="ol">A batch file named [ICODE]refresh_epg.bat[/ICODE] exists in the same folder as the Python script, and the former calls [ICODE]zap2xml.exe[/ICODE], etc., and updates the TV guide</li> <li data-xf-list-type="ol">The working folder for the Python script and [ICODE]refresh_epg.bat[/ICODE] can be written to, for storing a temporary text file</li> <li data-xf-list-type="ol">The [ICODE]hosts[/ICODE] file already has an existing entry to redirect from [ICODE]tvlistings.zap2it.com[/ICODE]</li> <li data-xf-list-type="ol">User creates another small batch script which launches the Python script below, and can execute this batch file as Administrator</li> </ol><p><em>IMPORTANT</em>:</p><ul> <li data-xf-list-type="ul">Please back up your hosts file before trying to run this script, just in case it messes up; use at your own risk</li> </ul><p>[CODE=python]import subprocess</p><p></p><p>hosts_path = 'C:/Windows/System32/drivers/etc/hosts'</p><p>search_text = '\t\ttvlistings.zap2it.com'</p><p></p><p># Look up the current IP addresses, and save them to a text file</p><p>subprocess.run(['nslookup', 'tvlistings.gracenote.com', '>', 'temp.txt'], shell=True)</p><p>with open('./temp.txt', 'r') as temp_file:</p><p> lines = temp_file.readlines()</p><p>temp_file.close()</p><p>for line in lines:</p><p> if 'Addresses: ' in line:</p><p> # Note one of the addresses</p><p> ip_address = line[len('Addresses: '):-1]</p><p> break</p><p># Load the hosts file</p><p>with open(hosts_path, 'r') as target_file:</p><p> lines = target_file.readlines()</p><p>target_file.close()</p><p>new_text = ''</p><p>for line in lines:</p><p> if search_text in line:</p><p> # Replace the old IP address with the new one</p><p> new_text += line.replace(line[:line.find(search_text)], ip_address)</p><p> else:</p><p> new_text += line</p><p># Now open the hosts file for writing and update it</p><p>with open(hosts_path, 'w') as target_file:</p><p> target_file.write(new_text)</p><p>target_file.close()</p><p># Finally, proceed with downloading the fresh TV Guide information</p><p>subprocess.run(['refresh_epg.bat'], shell=True)[/CODE]</p><p>NOTE:</p><ul> <li data-xf-list-type="ul">Lines 3, 4 and 32 may need to be tweaked for your particular use case</li> <li data-xf-list-type="ul">My hosts file has tab characters for indentation, so they appear within the string on line 4 (others may need to either use spaces or just remove them)</li> </ul><p>The 'wrapper' batch script would be pretty simple; it would just need to have a command like [ICODE]python update_tv-guide.py[/ICODE] (an example name of the above script).</p><p></p><p>Last but not least, the Task Scheduler entry would need to be updated to point to the wrapper batch script and to have the 'Run with highest privileges' option ticked (Windows will ask for the Administrator password prior to saving the changes).</p></blockquote><p></p>
[QUOTE="smnsparty, post: 1302366, member: 172316"] This is one of the top search results for WMC having stopped working; thanks everyone for the useful information! My shell scripting skills are very rusty these days, so for those like me who are still rocking Windows 7's (or some later version of) WMC, I thought I'd post the (rather hacky) Python script I'm using as a drop-in replacement for updating the hosts file and then launching a batch script to download and process the TV guide. In order to run this script, the following assumptions need to be met. [LIST=1] [*]User has Administrator privileges [*]Python is installed on the system [*]A batch file named [ICODE]refresh_epg.bat[/ICODE] exists in the same folder as the Python script, and the former calls [ICODE]zap2xml.exe[/ICODE], etc., and updates the TV guide [*]The working folder for the Python script and [ICODE]refresh_epg.bat[/ICODE] can be written to, for storing a temporary text file [*]The [ICODE]hosts[/ICODE] file already has an existing entry to redirect from [ICODE]tvlistings.zap2it.com[/ICODE] [*]User creates another small batch script which launches the Python script below, and can execute this batch file as Administrator [/LIST] [I]IMPORTANT[/I]: [LIST] [*]Please back up your hosts file before trying to run this script, just in case it messes up; use at your own risk [/LIST] [CODE=python]import subprocess hosts_path = 'C:/Windows/System32/drivers/etc/hosts' search_text = '\t\ttvlistings.zap2it.com' # Look up the current IP addresses, and save them to a text file subprocess.run(['nslookup', 'tvlistings.gracenote.com', '>', 'temp.txt'], shell=True) with open('./temp.txt', 'r') as temp_file: lines = temp_file.readlines() temp_file.close() for line in lines: if 'Addresses: ' in line: # Note one of the addresses ip_address = line[len('Addresses: '):-1] break # Load the hosts file with open(hosts_path, 'r') as target_file: lines = target_file.readlines() target_file.close() new_text = '' for line in lines: if search_text in line: # Replace the old IP address with the new one new_text += line.replace(line[:line.find(search_text)], ip_address) else: new_text += line # Now open the hosts file for writing and update it with open(hosts_path, 'w') as target_file: target_file.write(new_text) target_file.close() # Finally, proceed with downloading the fresh TV Guide information subprocess.run(['refresh_epg.bat'], shell=True)[/CODE] NOTE: [LIST] [*]Lines 3, 4 and 32 may need to be tweaked for your particular use case [*]My hosts file has tab characters for indentation, so they appear within the string on line 4 (others may need to either use spaces or just remove them) [/LIST] The 'wrapper' batch script would be pretty simple; it would just need to have a command like [ICODE]python update_tv-guide.py[/ICODE] (an example name of the above script). Last but not least, the Task Scheduler entry would need to be updated to point to the wrapper batch script and to have the 'Run with highest privileges' option ticked (Windows will ask for the Administrator password prior to saving the changes). [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Products
TV-Server
Zap2it free TV listings XML is no more.
Contact us
RSS
Top
Bottom