def show_events(after='none'): # False uses the reddit sorting afterPost, events = LoLEventVODs.load_events(True, after) items = [] for lolevent in events: date = lolevent.createdOn.strftime('%d/%m/%y') status = PluginUtils.get_string(30005) if (lolevent.status < 99): if (lolevent.status == 1): status = PluginUtils.get_string(30006) if (lolevent.status == 0): status = PluginUtils.get_string(30007) item = { 'label': lolevent.title + " (" + status + ")", 'label2': date, 'path': plugin.url_for('show_event', eventId=lolevent.eventId), 'thumbnail' : lolevent.imageUrl, 'info_type': 'video', 'info' : '{date:' + date +"}" } items.append(item) if (afterPost is not None): item = { 'label': PluginUtils.get_string(30010), 'path': plugin.url_for('show_events', after=afterPost) } items.append(item) return items
def show_events(after='none'): # False uses the reddit sorting afterPost, events = LoLEventVODs.load_events(True, after) items = [] for lolevent in events: date = lolevent.createdOn.strftime('%d/%m/%y') status = PluginUtils.get_string(30005) if (lolevent.status < 99): if (lolevent.status == 1): status = PluginUtils.get_string(30006) if (lolevent.status == 0): status = PluginUtils.get_string(30007) item = { 'label': lolevent.title + " (" + status + ")", 'label2': date, 'path': plugin.url_for('show_event', eventId=lolevent.eventId), 'thumbnail': lolevent.imageUrl, 'info_type': 'video', 'info': '{date:' + date + "}" } items.append(item) if (afterPost is not None): item = { 'label': PluginUtils.get_string(30010), 'path': plugin.url_for('show_events', after=afterPost) } items.append(item) return items
def show_videos(eventId, dayId, gameId): items = [] days = LoLEventVODs.load_event_content(eventId) day = days[int(dayId)] if (day is not None): for match in day.matches: if (match.gameId == gameId): for video in match.videoLinks: if (video is not None): # We can iterate the video links if (video['text'] is not None and video['videoId'] is not None): if (video['videoId'] is not None and video['videoId'] != 'EMPTY'): youtube_url = PluginUtils.get_string( 30100) % video['videoId'] else: youtube_url = "" item = { 'label': video['text'].replace('&', '&') + " @" + video['time'] + "", 'path': youtube_url, 'thumbnail': PluginUtils.get_string(30101) % video['videoId'], 'is_playable': True } items.append(item) return items
def load_events(sortByStatus): response = PluginUtils.do_request(LOLEVENTURL) if (response is None): return None events = [] # Now lets parse results decoded_data = json.load(response) root = decoded_data['data'] LoLEvent = namedtuple('LoLEvent', 'title status eventId imageUrl') # For Each Item in Children for post in root['children']: html = post['data']['selftext_html'] if (html is not None): soup = BeautifulSoup(PluginUtils.unescape(html)) imgUrl = '' link = soup.find('a', href='#EVENT_PICTURE') if (link is not None): imgUrl = link.title status = 99 # Using numbers for status so we can easily sort by this # link_flair_css_class: "ongoing" # link_flair_css_class: "finished" # link_flair_css_class: "twitchongoing" # link_flair_css_class: "featured" # link_flair_css_class: null flair_css = post['data']['link_flair_css_class'] if (flair_css is not None): if (flair_css.lower()== FEATURED_STRING): status = 0 if (flair_css.lower()== ACTIVE_STRING): status = 1 if (flair_css.lower()== FINISHED_STRING): status = 2 childEvent = LoLEvent(title = post['data']['title'], status = status, eventId = post['data']['id'], imageUrl = imgUrl) events.append(childEvent) if (sortByStatus): # sort return sorted(events, key=attrgetter('status')) else: return events
def index(): # Main Menu items = [] item = { 'label': PluginUtils.get_string(30001), 'path': plugin.url_for('show_featured_events'), 'thumbnail' : 'http://c.thumbs.redditmedia.com/QzaSL6tRjZuybp0J.png' } items.append(item) item = { 'label': PluginUtils.get_string(30002), 'path': plugin.url_for('show_learning_center') } items.append(item) item = { 'label': PluginUtils.get_string(30003), 'path':plugin.url_for('open_settings') } items.append(item) return items
def get_lcs_standings(teamName): # This method loads the latest standings from the Gamepedia server url = '' if (teamName in TEAMS_EU): url = PluginUtils.unescape(PluginUtils.get_string(30104)) if (teamName in TEAMS_NA): url = PluginUtils.unescape(PluginUtils.get_string(30103)) if (url != ''): response = PluginUtils.do_request(url) if (response is not None): # Lets process the html # decoded_data = json.load(response) soup = BeautifulSoup(response) tables = soup.findAll('table') if (tables is not None): for table in tables: # We have the table, now lets try and get the right row rows = table.find('tbody').findAll('tr') if (rows is not None): for idx, row in enumerate(rows): columns = row.findAll('td') if (columns is not None): if (columns[2] is not None): if (teamName in TEAMS_EU): if (columns[2].find('a').text.lower() == TEAMS_EU[teamName].lower()): return { 'standing': idx + 1, 'record': columns[3].find('span').text + "W-" + columns[4].find('span').text + "L" } if (teamName in TEAMS_NA): if (columns[2].find('a').text.lower() == TEAMS_NA[teamName].lower()): return { 'standing': idx + 1, 'record': columns[3].find('span').text + "W-" + columns[4].find('span').text + "L" } return None
def show_leaguecraft101(): items = [] for video in LearningCenter.leaguecraft_videos(): youtube_url = PluginUtils.get_string(30100) % video['videoId'] item = { 'label': video['text'], 'path': youtube_url, 'thumbnail' :PluginUtils.get_string(30101) % video['videoId'], 'is_playable': True, 'replace_context_menu': True} items.append(item) return items
def show_learning_center(): items = [] # TODO: Localized strings item = { 'label': PluginUtils.get_string(30009), 'path': plugin.url_for('show_leaguecraft101') } items.append(item) return items
def show_leaguecraft101(): items = [] for video in LearningCenter.leaguecraft_videos(): youtube_url = PluginUtils.get_string(30100) % video['videoId'] item = { 'label': video['text'], 'path': youtube_url, 'thumbnail': PluginUtils.get_string(30101) % video['videoId'], 'is_playable': True, 'replace_context_menu': True } items.append(item) return items
def show_matches(eventId, dayId): items = [] days = LoLEventVODs.load_event_content(eventId) day = days[int(dayId)] if (day is not None): for match in day.matches: recommended = '' # Add spoiler data? if (day.recommended.find(match.gameId) > -1 and plugin.get_setting( 'highlight_recommended_games', bool)): recommended = '*' # Add standings? t1standing = '' t2standing = '' try: if (plugin.get_setting('include_current_lcs_standings', bool)): #Need to make this work using Standings Module standingT1 = LCSStandings.get_lcs_standings(match.team1) standingT2 = LCSStandings.get_lcs_standings(match.team2) if (standingT1 is not None and standingT2 is not None): t1standing = ' [#{0} ({1})]'.format( standingT1['standing'], standingT1['record']) t2standing = ' [#{0} ({1})]'.format( standingT2['standing'], standingT2['record']) except: t1standing = '' t2standing = '' titleFormat = PluginUtils.get_string(30008) title = titleFormat.format(match.gameId, match.team1, match.team2, recommended, t1standing, t2standing) item = { 'label': title, 'path': plugin.url_for('show_videos', eventId=eventId, dayId=dayId, gameId=match.gameId), 'thumbnail': day.imageUrl, 'replace_context_menu': True } items.append(item) return items
def index(): # Main Menu items = [] item = { 'label': PluginUtils.get_string(30001), 'path': plugin.url_for('show_featured_events'), 'thumbnail': 'http://c.thumbs.redditmedia.com/QzaSL6tRjZuybp0J.png' } items.append(item) item = { 'label': PluginUtils.get_string(30002), 'path': plugin.url_for('show_learning_center') } items.append(item) item = { 'label': PluginUtils.get_string(30003), 'path': plugin.url_for('open_settings') } items.append(item) return items
def show_featured_events(): items = show_events() show_items = [] if (items is not None): for item in items: if (item['label'].lower().find('featured') > -1): show_items.append(item) item = { 'label': PluginUtils.get_string(30004), 'path': plugin.url_for('show_events', after='none') } show_items.append(item) return show_items
def get_lcs_standings(teamName): # This method loads the latest standings from the Gamepedia server url='' if (teamName in TEAMS_EU): url = PluginUtils.unescape(PluginUtils.get_string(30104)) if (teamName in TEAMS_NA): url = PluginUtils.unescape(PluginUtils.get_string(30103)) if (url != ''): response = PluginUtils.do_request(url) if (response is not None): # Lets process the html # decoded_data = json.load(response) soup = BeautifulSoup(response) tables = soup.findAll('table') if (tables is not None): for table in tables: # We have the table, now lets try and get the right row rows = table.find('tbody').findAll('tr') if (rows is not None): for idx, row in enumerate(rows): columns = row.findAll('td') if (columns is not None): if (columns[2] is not None): if (teamName in TEAMS_EU): if (columns[2].find('a').text.lower() == TEAMS_EU[teamName].lower()): return {'standing' : idx+1, 'record' : columns[3].find('span').text + "W-" + columns[4].find('span').text +"L" } if (teamName in TEAMS_NA): if (columns[2].find('a').text.lower() == TEAMS_NA[teamName].lower()): return {'standing' : idx+1, 'record' : columns[3].find('span').text + "W-" + columns[4].find('span').text +"L"} return None
def show_videos(eventId, dayId, gameId): items = [] days = LoLEventVODs.load_event_content(eventId) day = days[int(dayId)] if (day is not None): for match in day.matches: if (match.gameId == gameId): for video in match.videoLinks: if (video is not None): # We can iterate the video links if (video['text'] is not None and video['videoId'] is not None): if (video['videoId'] is not None and video['videoId'] != 'EMPTY'): youtube_url = PluginUtils.get_string(30100) % video['videoId'] else: youtube_url = "" item = { 'label': video['text'].replace('&', '&') + " @" + video['time'] + "", 'path': youtube_url, 'thumbnail' : PluginUtils.get_string(30101) % video['videoId'], 'is_playable': True } items.append(item) return items
def show_matches(eventId, dayId): items = [] days = LoLEventVODs.load_event_content(eventId) day = days[int(dayId)] if (day is not None): for match in day.matches: recommended = '' # Add spoiler data? if (day.recommended.find(match.gameId) > -1 and plugin.get_setting('highlight_recommended_games', bool)): recommended = '*' # Add standings? t1standing = '' t2standing = '' try: if (plugin.get_setting('include_current_lcs_standings', bool)): #Need to make this work using Standings Module standingT1 = LCSStandings.get_lcs_standings(match.team1) standingT2 = LCSStandings.get_lcs_standings(match.team2) if (standingT1 is not None and standingT2 is not None): t1standing = ' [#{0} ({1})]'.format(standingT1['standing'], standingT1['record']) t2standing = ' [#{0} ({1})]'.format(standingT2['standing'], standingT2['record']) except: t1standing = '' t2standing = '' titleFormat = PluginUtils.get_string(30008) title = titleFormat.format(match.gameId, match.team1, match.team2, recommended, t1standing, t2standing) item = { 'label': title, 'path': plugin.url_for('show_videos', eventId=eventId, dayId = dayId, gameId = match.gameId), 'thumbnail' : day.imageUrl, 'replace_context_menu': True } items.append(item) return items
def load_event_content(eventId): LoLEventDay = namedtuple('LoLEventDay', 'dayId day matches recommended imageUrl') LoLEventMatch = namedtuple('LoLEventMatch', 'gameId team1 team2 videoLinks') url = LOLMATCHESURL % eventId response = PluginUtils.do_request(url) if (response is None): return None # Now lets parse results decoded_data = json.load(response) selfText = decoded_data[0]['data']['children'][0]['data']['selftext_html'] eventTitle = '' days = [] soup = BeautifulSoup(PluginUtils.unescape(selfText)) # Get all the recommended matches, we add those to the events # We do it like this Game H1_C1_C4 recommended = '' #a href="/spoiler" spoilers = soup.findAll("a", href="/spoiler") if (spoilers is not None): for spoiler in spoilers: # add them to the list games = spoiler.text.replace(',', '_') recommended += games + "_" imgUrl = '' link = soup.find('a', href='#EVENT_PICTURE') if (link is not None): imgUrl = link.title # find all tables tables = soup.findAll("table") for idx, table in enumerate(tables): if (table is not None): titleLink = table.find("a", href="http://www.table_title.com") if (titleLink is not None): eventTitle = titleLink['title'] YouTubeColumns = [] Team1Index = -1 Team2Index = -1 # Investigate the right columns for youtube links rows = table.find("thead").findAll("tr") for row in rows : cols = row.findAll("th") for i, col in enumerate(cols): if (col.text.lower() == "youtube"): YouTubeColumns.append(i) if (col.text.lower() == "team 1"): Team1Index = i if (col.text.lower() == "team 2"): Team2Index = i # matches=[] rows = table.find("tbody").findAll("tr") for row in rows : videos = [] cols = row.findAll("td") if (cols is not None): for yv in YouTubeColumns: if (cols[yv] is not None): if (cols[yv].a is not None): youTubeData = PluginUtils.parse_youtube_url(cols[yv].a['href']) videos.append({'text' : cols[yv].a.text, 'videoId' : youTubeData['videoId'], 'time' : youTubeData['time'] }) matches.append(LoLEventMatch(cols[0].text, cols[Team1Index].text, cols[Team2Index].text, videos)) days.append(LoLEventDay(dayId = idx, day=eventTitle, matches = matches, recommended = recommended, imageUrl = imgUrl)) return days
def load_events(sortByStatus, after): # The reddit api does things like this: # /r/bla.json?limit=pagesize&after=postId # Let's build a URL urlAppend = '?limit=' + str(PAGE_SIZE) if (after is not 'none'): urlAppend += '&after=' + after response = PluginUtils.do_request(LOLEVENTURL + urlAppend) if (response is None): return None events = [] # Now lets parse results decoded_data = json.load(response) root = decoded_data['data'] # after link = afterPost = root['after'] LoLEvent = namedtuple('LoLEvent', 'title status eventId createdOn imageUrl') # For Each Item in Children for post in root['children']: html = post['data']['selftext_html'] if (html is not None): soup = BeautifulSoup(PluginUtils.unescape(html)) imgUrl = '' isEvent = False link = soup.find('a', href='#EVENT_TITLE') if (link is not None): isEvent = True link = soup.find('a', href='#EVENT_PICTURE') if (link is not None): imgUrl = link.title status = 99 # Using numbers for status so we can easily sort by this # link_flair_css_class: "ongoing" # link_flair_css_class: "finished" # link_flair_css_class: "twitchongoing" # link_flair_css_class: "featured" # link_flair_css_class: "finishedfeatured" # link_flair_css_class: null flair_css = post['data']['link_flair_css_class'] if (flair_css is not None): if (flair_css.lower()== FEATURED_STRING): status = 0 if (flair_css.lower()== ACTIVE_STRING): status = 1 if (flair_css.lower()== FINISHED_STRING): status = 2 if (flair_css.lower()== FINISHEDFEATURED_STRING): status = 2 # Some don't have link_flair_css_class but are events if (status == 99 and isEvent): status = 98 childEvent = LoLEvent(title = post['data']['title'], status = status, eventId = post['data']['id'], createdOn = datetime.datetime.fromtimestamp(int(post['data']['created'])), imageUrl = imgUrl) events.append(childEvent) if (sortByStatus): # sort return afterPost, sorted(events, key=attrgetter('status')) else: return afterPost, events
from collections import namedtuple import json import datetime from operator import attrgetter from resources.lib.BeautifulSoup import BeautifulSoup from resources.lib import PluginUtils # CONSTANTS LOLEVENTURL = PluginUtils.unescape(PluginUtils.get_string(30105)) LOLMATCHESURL = PluginUtils.unescape(PluginUtils.get_string(30106)) ACTIVE_STRING = PluginUtils.get_string(30050) FINISHED_STRING = PluginUtils.get_string(30051) FEATURED_STRING = PluginUtils.get_string(30052) FINISHEDFEATURED_STRING = PluginUtils.get_string(30053) PAGE_SIZE = 10 #NOTSTREAMED_STRING = "**Not Streamed**" def load_events(sortByStatus, after): # The reddit api does things like this: # /r/bla.json?limit=pagesize&after=postId # Let's build a URL urlAppend = '?limit=' + str(PAGE_SIZE) if (after is not 'none'): urlAppend += '&after=' + after response = PluginUtils.do_request(LOLEVENTURL + urlAppend) if (response is None):