-
-
Save kasper93/624de047e9403904b90c14f9ddb5eca9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bs4 | |
import calendar | |
import requests | |
import time | |
def get_list(url, time): | |
r = requests.get(url) | |
soup = bs4.BeautifulSoup(r.text, "html.parser") | |
streams = [] | |
for it in soup.select('span[data-redir]'): | |
if int(it["data-broadcast-end"]) >= time: | |
info_dict = { | |
'url': it["data-redir"], | |
'title': it.findChild("span", {"class": "title"}), | |
'time': it.findChild("span", {"class": "time"}), | |
"category": it.findChild("span", {"class": "category"}) | |
} | |
streams.append(info_dict) | |
return streams | |
def main(): | |
cur_time = calendar.timegm(time.gmtime()) * 1000 | |
url1 = "http://www.api.v3.tvp.pl/shared/listing.php?portal_name=rio2016.tvp.pl&portal_id=19369963&parent_id=24035157&type=directory_standard©=false&direct=true&order=position%2C1&count=-1&epg_start=" + str(cur_time) + "&epg_end=" + str(cur_time) + "&template=epg%2Fdisciplines-listing.html" | |
url2 = "http://www.api.v3.tvp.pl/shared/listing.php?portal_name=rio2016.tvp.pl&portal_id=19369963&parent_id=25851771&type=virtual_channel©=false&direct=true&order=position%2C1&count=-1&epg_start=" + str(cur_time) + "&epg_end=" + str(cur_time) + "&template=epg%2Fchannels-listing.html" | |
streams = get_list(url1, cur_time) | |
streams += get_list(url2, cur_time) | |
streams = [dict(p) for p in set(tuple(i.items()) for i in streams)] | |
streams = sorted(streams, key=lambda k: k['title'].text) | |
for s in streams: | |
if s["category"]: | |
print ("%s: %s (%s)\n%s\n" % (s["title"].text, s["category"].text, s["time"].text, s["url"])) | |
else: | |
print ("%s (%s)\n%s\n" % (s["title"].text, s["time"].text, s["url"])) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment