Skip to content

Instantly share code, notes, and snippets.

@ScottSteiner
Last active October 11, 2015 04:13
Show Gist options
  • Save ScottSteiner/4dc279910176c2ebcde9 to your computer and use it in GitHub Desktop.
Save ScottSteiner/4dc279910176c2ebcde9 to your computer and use it in GitHub Desktop.
Gets currently playing show using locatetv.com
#!/usr/bin/env python
from lxml import html
import requests
#Set just for testing purposes. channel value should be set using current channel information
channel = 'wxin-fox'
#Gets the TV listings
content = requests.get('http://www.locatetv.com/listings/{}'.format(channel)).content
tree = html.fromstring(content)
listings = tree.xpath('//ul[@class="onNow clearFix"]')
show_info = listings[0].xpath('//a[@class="pickable"]/text()')
data = {
'channel': channel,
'show_name': show_info[0],
'started': listings[0].xpath('//li[@class="time"]/text()')[0],
'ends': tree.xpath('//ul[@class="nextOn clearFix"]//li[@class="time"]/text()')[0],
'episode_name': show_info[1],
'episode_synopsis': listings[0].xpath('//p/text()')[1],
'episode_link': listings[0].xpath('//a[@class="packshot epi ls mid hvr"]/@href')[0]
}
print('{channel} | {show_name} | {started} | {ends} | {episode_name} | {episode_synopsis} | {episode_link}'.format(**data))
@ScottSteiner
Copy link
Author

Output:

wxin-fox | Animation Domination High-Def | 44 mins ago | in 16 mins | EPISODE: 116 | Installments from 'Axe Cop' and 'Golan the Insatiable.' | /tv/animation-domination-high-def/9428888

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment