How to use get_list method in autotest

Best Python code snippet using autotest_python

api.py

Source:api.py Github

copy

Full Screen

1import xbmc2import xbmcgui3from resources.lib.addon.cache import CACHE_EXTENDED4from resources.lib.api.request import RequestAPI5from resources.lib.container.listitem import ListItem6from resources.lib.addon.plugin import ADDON, viewitems, get_language7from resources.lib.addon.setutils import del_empty_keys8from resources.lib.addon.decorators import busy_dialog9from resources.lib.addon.parser import try_int10# from resources.lib.addon.decorators import timer_report11API_URL = 'http://webservice.fanart.tv/v3'12ARTWORK_TYPES = {13 'movies': {14 'clearart': ['hdmovieclearart', 'movieclearart'],15 'clearlogo': ['hdmovielogo', 'movielogo'],16 'discart': ['moviedisc'],17 'poster': ['movieposter'],18 'fanart': ['moviebackground'],19 'landscape': ['moviethumb'],20 'banner': ['moviebanner']},21 'tv': {22 'clearart': ['hdclearart', 'clearart'],23 'clearlogo': ['hdtvlogo', 'clearlogo'],24 'characterart': ['characterart'],25 'poster': ['tvposter'],26 'fanart': ['showbackground'],27 'landscape': ['tvthumb'],28 'banner': ['tvbanner']}}29def add_extra_art(source, output={}):30 if not source:31 return output32 output.update({u'fanart{}'.format(x): i['url'] for x, i in enumerate(source, 1) if i.get('url')})33 return output34class FanartTV(RequestAPI):35 def __init__(36 self,37 api_key='fcca59bee130b70db37ee43e63f8d6c1',38 client_key=ADDON.getSettingString('fanarttv_clientkey'),39 language=get_language(),40 cache_only=False,41 cache_refresh=False):42 super(FanartTV, self).__init__(43 req_api_name='FanartTV',44 req_api_url=API_URL,45 req_api_key=u'api_key={}'.format(api_key))46 self.req_api_key = u'api_key={0}'.format(api_key) if api_key else self.req_api_key47 self.req_api_key = u'{0}&client_key={1}'.format(self.req_api_key, client_key) if client_key else self.req_api_key48 self.language = language[:2] if language else 'en'49 self.cache_only = cache_only50 self.cache_refresh = cache_refresh51 self.req_strip.append(('&client_key={}'.format(client_key), ''))52 def get_artwork_request(self, ftv_id, ftv_type):53 """54 ftv_type can be 'movies' 'tv'55 ftv_id is tmdb_id|imdb_id for movies and tvdb_id for tv56 """57 if not ftv_type or not ftv_id:58 return59 return self.get_request(60 ftv_type, ftv_id,61 cache_force=7, # Force the cache to save a dummy dict for 7 days so that we don't bother requesting 404s multiple times62 cache_fallback={'dummy': None},63 cache_days=CACHE_EXTENDED,64 cache_only=self.cache_only,65 cache_refresh=self.cache_refresh)66 def _get_artwork_type(self, ftv_id, ftv_type, artwork_type):67 if not artwork_type:68 return69 response = self.get_artwork_request(ftv_id, ftv_type)70 if not response:71 return72 return response.get(artwork_type) or []73 def get_artwork_type(self, ftv_id, ftv_type, artwork_type):74 return self._cache.use_cache(75 self._get_artwork_type, ftv_id, ftv_type, artwork_type,76 cache_name=u'FanartTV.type.{}.{}.{}.{}'.format(self.language, ftv_id, ftv_type, artwork_type),77 cache_only=self.cache_only,78 cache_refresh=self.cache_refresh)79 def _get_best_artwork(self, ftv_id, ftv_type, artwork_type):80 artwork = self.get_artwork_type(ftv_id, ftv_type, artwork_type)81 best_like = -182 best_item = None83 for i in artwork:84 if i.get('lang', '') == self.language:85 return i.get('url', '')86 if (i.get('lang', '') == 'en' or not i.get('lang')) and try_int(i.get('likes', 0)) > try_int(best_like):87 best_item = i.get('url', '')88 best_like = i.get('likes', 0)89 return best_item90 def get_best_artwork(self, ftv_id, ftv_type, artwork_type):91 return self._cache.use_cache(92 self._get_best_artwork, ftv_id, ftv_type, artwork_type,93 cache_name=u'FanartTV.best.{}.{}.{}.{}'.format(self.language, ftv_id, ftv_type, artwork_type),94 cache_only=self.cache_only,95 cache_refresh=self.cache_refresh)96 def _get_artwork_func(self, ftv_id, ftv_type, artwork_type, get_list=False):97 func = self.get_best_artwork if not get_list else self.get_artwork_type98 return func(ftv_id, ftv_type, artwork_type)99 def get_movies_clearart(self, ftv_id, get_list=False):100 artwork = self._get_artwork_func(ftv_id, 'movies', 'hdmovieclearart', get_list=get_list)101 return artwork or self._get_artwork_func(ftv_id, 'movies', 'movieclearart', get_list=get_list)102 def get_movies_clearlogo(self, ftv_id, get_list=False):103 artwork = self._get_artwork_func(ftv_id, 'movies', 'hdmovielogo', get_list=get_list)104 return artwork or self._get_artwork_func(ftv_id, 'movies', 'movielogo', get_list=get_list)105 def get_movies_discart(self, ftv_id, get_list=False):106 return self._get_artwork_func(ftv_id, 'movies', 'moviedisc', get_list=get_list)107 def get_movies_poster(self, ftv_id, get_list=False):108 return self._get_artwork_func(ftv_id, 'movies', 'movieposter', get_list=get_list)109 def get_movies_fanart(self, ftv_id, get_list=False):110 return self._get_artwork_func(ftv_id, 'movies', 'moviebackground', get_list=get_list)111 def get_movies_landscape(self, ftv_id, get_list=False):112 return self._get_artwork_func(ftv_id, 'movies', 'moviethumb', get_list=get_list)113 def get_movies_banner(self, ftv_id, get_list=False):114 return self._get_artwork_func(ftv_id, 'movies', 'moviebanner', get_list=get_list)115 def get_tv_clearart(self, ftv_id, get_list=False):116 artwork = self._get_artwork_func(ftv_id, 'tv', 'hdclearart', get_list=get_list)117 return artwork or self._get_artwork_func(ftv_id, 'tv', 'clearart', get_list=get_list)118 def get_tv_clearlogo(self, ftv_id, get_list=False):119 artwork = self._get_artwork_func(ftv_id, 'tv', 'hdtvlogo', get_list=get_list)120 return artwork or self._get_artwork_func(ftv_id, 'tv', 'clearlogo', get_list=get_list)121 def get_tv_banner(self, ftv_id, get_list=False):122 return self._get_artwork_func(ftv_id, 'tv', 'tvbanner', get_list=get_list)123 def get_tv_landscape(self, ftv_id, get_list=False):124 return self._get_artwork_func(ftv_id, 'tv', 'tvthumb', get_list=get_list)125 def get_tv_fanart(self, ftv_id, get_list=False):126 return self._get_artwork_func(ftv_id, 'tv', 'showbackground', get_list=get_list)127 def get_tv_poster(self, ftv_id, get_list=False):128 return self._get_artwork_func(ftv_id, 'tv', 'tvposter', get_list=get_list)129 def get_tv_characterart(self, ftv_id, get_list=False):130 return self._get_artwork_func(ftv_id, 'tv', 'characterart', get_list=get_list)131 def get_tv_all_artwork(self, ftv_id):132 if self.get_artwork_request(ftv_id, 'tv'): # Check we can get the request first so we don't re-ask eight times if it 404s133 return add_extra_art(self.get_tv_fanart(ftv_id, get_list=True), del_empty_keys({134 'clearart': self.get_tv_clearart(ftv_id),135 'clearlogo': self.get_tv_clearlogo(ftv_id),136 'banner': self.get_tv_banner(ftv_id),137 'landscape': self.get_tv_landscape(ftv_id),138 'fanart': self.get_tv_fanart(ftv_id),139 'characterart': self.get_tv_characterart(ftv_id),140 'poster': self.get_tv_poster(ftv_id)}))141 def get_movies_all_artwork(self, ftv_id):142 if self.get_artwork_request(ftv_id, 'movies'): # Check we can get the request first so we don't re-ask eight times if it 404s143 return add_extra_art(self.get_movies_fanart(ftv_id, get_list=True), del_empty_keys({144 'clearart': self.get_movies_clearart(ftv_id),145 'clearlogo': self.get_movies_clearlogo(ftv_id),146 'banner': self.get_movies_banner(ftv_id),147 'landscape': self.get_movies_landscape(ftv_id),148 'fanart': self.get_movies_fanart(ftv_id),149 'poster': self.get_movies_poster(ftv_id),150 'discart': self.get_movies_discart(ftv_id)}))151 def get_all_artwork(self, ftv_id, ftv_type):152 if ftv_type == 'movies':153 return self.get_movies_all_artwork(ftv_id)154 if ftv_type == 'tv':155 return self.get_tv_all_artwork(ftv_id)156 def refresh_all_artwork(self, ftv_id, ftv_type, ok_dialog=True, container_refresh=True):157 self.cache_refresh = True158 with busy_dialog():159 artwork = self.get_all_artwork(ftv_id, ftv_type)160 if ok_dialog and not artwork:161 xbmcgui.Dialog().ok('FanartTV', ADDON.getLocalizedString(32217).format(ftv_type, ftv_id))162 if ok_dialog and artwork:163 xbmcgui.Dialog().ok('FanartTV', ADDON.getLocalizedString(32218).format(164 ftv_type, ftv_id, ', '.join([k.capitalize() for k, v in viewitems(artwork) if v])))165 if artwork and container_refresh:166 xbmc.executebuiltin('Container.Refresh')167 xbmc.executebuiltin('UpdateLibrary(video,/fake/path/to/force/refresh/on/home)')168 return artwork169 def get_artwork(self, ftv_id, ftv_type, artwork_type, get_list=False):170 if ftv_type == 'movies':171 if artwork_type == 'clearart':172 return self.get_movies_clearart(ftv_id, get_list=get_list)173 if artwork_type == 'clearlogo':174 return self.get_movies_clearlogo(ftv_id, get_list=get_list)175 if artwork_type == 'banner':176 return self.get_movies_banner(ftv_id, get_list=get_list)177 if artwork_type == 'landscape':178 return self.get_movies_landscape(ftv_id, get_list=get_list)179 if artwork_type == 'fanart':180 return self.get_movies_fanart(ftv_id, get_list=get_list)181 if artwork_type == 'poster':182 return self.get_movies_poster(ftv_id, get_list=get_list)183 if ftv_type == 'tv':184 if artwork_type == 'discart':185 return self.get_tv_discart(ftv_id, get_list=get_list)186 if artwork_type == 'clearart':187 return self.get_tv_clearart(ftv_id, get_list=get_list)188 if artwork_type == 'clearlogo':189 return self.get_tv_clearlogo(ftv_id, get_list=get_list)190 if artwork_type == 'banner':191 return self.get_tv_banner(ftv_id, get_list=get_list)192 if artwork_type == 'landscape':193 return self.get_tv_landscape(ftv_id, get_list=get_list)194 if artwork_type == 'fanart':195 return self.get_tv_fanart(ftv_id, get_list=get_list)196 if artwork_type == 'poster':197 return self.get_tv_poster(ftv_id, get_list=get_list)198 if artwork_type == 'characterart':199 return self.get_tv_characterart(ftv_id, get_list=get_list)200 def select_artwork(self, ftv_id, ftv_type, container_refresh=True, blacklist=[]):201 if ftv_type not in ['movies', 'tv']:202 return203 with busy_dialog():204 artwork = self.get_artwork_request(ftv_id, ftv_type)205 if not artwork:206 return xbmcgui.Dialog().notification('FanartTV', ADDON.getLocalizedString(32217).format(ftv_type, ftv_id))207 # Choose Type208 _artwork_types = ['poster', 'fanart', 'clearart', 'clearlogo', 'landscape', 'banner']209 _artwork_types.append('discart' if ftv_type == 'movies' else 'characterart')210 artwork_types = [i for i in _artwork_types if i not in blacklist] # Remove types that we previously looked for211 choice = xbmcgui.Dialog().select(xbmc.getLocalizedString(13511), artwork_types)212 if choice == -1:213 return214 # Get artwork of user's choosing215 artwork_type = artwork_types[choice]216 artwork_items = self.get_artwork(ftv_id, ftv_type, artwork_type, get_list=True)217 # If there was not artwork of that type found then blacklist it before re-prompting218 if not artwork_items:219 xbmcgui.Dialog().notification('FanartTV', ADDON.getLocalizedString(32217).format(ftv_type, ftv_id))220 blacklist.append(artwork_types[choice])221 return self.select_artwork(ftv_id, ftv_type, container_refresh, blacklist)222 # Choose artwork from options223 items = [224 ListItem(225 label=i.get('url'),226 label2=ADDON.getLocalizedString(32219).format(i.get('lang', ''), i.get('likes', 0), i.get('id', '')),227 art={'thumb': i.get('url')}).get_listitem() for i in artwork_items if i.get('url')]228 choice = xbmcgui.Dialog().select(xbmc.getLocalizedString(13511), items, useDetails=True)229 if choice == -1: # If user hits back go back to main menu rather than exit completely230 return self.select_artwork(ftv_id, ftv_type, container_refresh, blacklist)231 # Cache our choice as the best artwork forever since it was selected manually232 # Some types have have HD and SD variants so set cache for both233 for i in ARTWORK_TYPES.get(ftv_type, {}).get(artwork_type, []):234 success = self._cache.set_cache(235 artwork_items[choice].get('url'),236 cache_name=u'FanartTV.best.{}.{}.{}.{}'.format(self.language, ftv_id, ftv_type, i),237 cache_days=10000)238 if success and container_refresh:239 xbmc.executebuiltin('Container.Refresh')240 xbmc.executebuiltin('UpdateLibrary(video,/fake/path/to/force/refresh/on/home)')241 def manage_artwork(self, ftv_id=None, ftv_type=None):242 if not ftv_id or not ftv_type:243 return244 choice = xbmcgui.Dialog().contextmenu([245 ADDON.getLocalizedString(32220),246 ADDON.getLocalizedString(32221)])247 if choice == -1:248 return249 if choice == 0:250 return self.select_artwork(ftv_id=ftv_id, ftv_type=ftv_type)251 if choice == 1:...

Full Screen

Full Screen

const_functions.py

Source:const_functions.py Github

copy

Full Screen

1# - *- coding: utf- 8 - *-2import time3from datetime import datetime456# Очистка текста от HTML тэгов7def clear_html(get_text):8 if get_text is not None:9 if "<" in get_text: get_text = get_text.replace("<", "*")10 if ">" in get_text: get_text = get_text.replace(">", "*")1112 return get_text131415# Получение текущего unix времени16def get_unix(full=False):17 if full:18 return time.time_ns()19 else:20 return int(time.time())212223# Получение текущей даты24def get_date():25 this_date = datetime.today().replace(microsecond=0)26 this_date = this_date.strftime("%d.%m.%Y %H:%M:%S")2728 return this_date293031# Разбив списка по количеству переданных значений32def split_messages(get_list, count):33 return [get_list[i:i + count] for i in range(0, len(get_list), count)]343536# Очистка мусорных символов из списка37def clear_list(get_list: list):38 while "" in get_list: get_list.remove("")39 while " " in get_list: get_list.remove(" ")40 while "," in get_list: get_list.remove(",")41 while "\r" in get_list: get_list.remove("\r")4243 return get_list444546# Конвертация дней47def convert_day(day):48 day = int(day)49 days = ['день', 'дня', 'дней']5051 if day % 10 == 1 and day % 100 != 11:52 count = 053 elif 2 <= day % 10 <= 4 and (day % 100 < 10 or day % 100 >= 20):54 count = 155 else:56 count = 25758 return f"{day} {days[count]}"596061# Удаление отступов у текста62def ded(get_text: str):63 if get_text is not None:64 split_text = get_text.split("\n")65 if split_text[0] == "": split_text.pop(0)66 if split_text[-1] == "": split_text.pop(-1)67 save_text = []6869 for text in split_text:70 while text.startswith(" "):71 text = text[1:]7273 save_text.append(text)74 get_text = "\n".join(save_text)7576 return get_text777879# Проверка числа на вещественное80def is_number(get_number):81 if str(get_number).isdigit():82 return False83 else:8485 try:86 int(get_number)87 return False88 except ValueError: ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful