Best Python code snippet using avocado_python
__init__.py
Source:__init__.py
...316 if doAdult:317 self.set_cookies(cookie_id, cookie_uu)318 else:319 self.urlOpener.del_header('Cookie')320 def _retrieve(self, url, size=-1, _noCookies=False):321 """Retrieve the given URL."""322 # print url323 _cookies = None324 # XXX: quite obscene, but in some very limited325 # cases (/ttXXXXXXX/epdate) if the cookies326 # are set, a 500 error is returned.327 if _noCookies:328 _cookies = self.urlOpener.get_header('Cookie')329 self.del_cookies()330 self._http_logger.debug('fetching url %s (size: %d)', url, size)331 try:332 ret = self.urlOpener.retrieve_unicode(url, size=size)333 finally:334 if _noCookies and _cookies:335 self.urlOpener.set_header('Cookie', _cookies)336 return ret337 def _get_search_content(self, kind, ton, results):338 """Retrieve the web page for a given search.339 kind can be 'tt' (for titles), 'nm' (for names),340 or 'co' (for companies).341 ton is the title or the name to search.342 results is the maximum number of results to be retrieved."""343 params = 'q=%s&s=%s&mx=%s' % (quote_plus(ton, safe=''), kind, str(results))344 if kind == 'ep':345 params = params.replace('s=ep&', 's=tt&ttype=ep&', 1)346 cont = self._retrieve(self.urls['find'] % params)347 # print 'URL:', imdbURL_find % params348 if cont.find('Your search returned more than') == -1 or \349 cont.find("displayed the exact matches") == -1:350 return cont351 # The retrieved page contains no results, because too many352 # titles or names contain the string we're looking for.353 params = 'q=%s&ls=%s&lm=0' % (quote_plus(ton, safe=''), kind)354 size = 131072 + results * 512355 return self._retrieve(self.urls['find'] % params, size=size)356 def _search_movie(self, title, results):357 cont = self._get_search_content('tt', title, results)358 return self.smProxy.search_movie_parser.parse(cont, results=results)['data']359 def _search_episode(self, title, results):360 t_dict = analyze_title(title)361 if t_dict['kind'] == 'episode':362 title = t_dict['title']363 cont = self._get_search_content('ep', title, results)364 return self.smProxy.search_movie_parser.parse(cont, results=results)['data']365 def get_movie_main(self, movieID):366 cont = self._retrieve(self.urls['movie_main'] % movieID + 'reference')367 return self.mProxy.movie_parser.parse(cont, mdparse=self._mdparse)368 def get_movie_full_credits(self, movieID):369 cont = self._retrieve(self.urls['movie_main'] % movieID + 'fullcredits')370 return self.mProxy.full_credits_parser.parse(cont)371 def get_movie_plot(self, movieID):372 cont = self._retrieve(self.urls['movie_main'] % movieID + 'plotsummary')373 ret = self.mProxy.plot_parser.parse(cont, getRefs=self._getRefs)374 ret['info sets'] = ('plot', 'synopsis')375 return ret376 def get_movie_awards(self, movieID):377 cont = self._retrieve(self.urls['movie_main'] % movieID + 'awards')378 return self.mProxy.movie_awards_parser.parse(cont)379 def get_movie_taglines(self, movieID):380 cont = self._retrieve(self.urls['movie_main'] % movieID + 'taglines')381 return self.mProxy.taglines_parser.parse(cont)382 def get_movie_keywords(self, movieID):383 cont = self._retrieve(self.urls['movie_main'] % movieID + 'keywords')384 return self.mProxy.keywords_parser.parse(cont)385 def get_movie_alternate_versions(self, movieID):386 cont = self._retrieve(self.urls['movie_main'] % movieID + 'alternateversions')387 return self.mProxy.alternateversions_parser.parse(cont, getRefs=self._getRefs)388 def get_movie_crazy_credits(self, movieID):389 cont = self._retrieve(self.urls['movie_main'] % movieID + 'crazycredits')390 return self.mProxy.crazycredits_parser.parse(cont, getRefs=self._getRefs)391 def get_movie_goofs(self, movieID):392 cont = self._retrieve(self.urls['movie_main'] % movieID + 'goofs')393 return self.mProxy.goofs_parser.parse(cont, getRefs=self._getRefs)394 def get_movie_quotes(self, movieID):395 cont = self._retrieve(self.urls['movie_main'] % movieID + 'quotes')396 return self.mProxy.quotes_parser.parse(cont, getRefs=self._getRefs)397 def get_movie_release_dates(self, movieID):398 cont = self._retrieve(self.urls['movie_main'] % movieID + 'releaseinfo')399 ret = self.mProxy.releasedates_parser.parse(cont)400 ret['info sets'] = ('release dates', 'akas')401 return ret402 get_movie_akas = get_movie_release_dates403 get_movie_release_info = get_movie_release_dates404 def get_movie_vote_details(self, movieID):405 cont = self._retrieve(self.urls['movie_main'] % movieID + 'ratings')406 return self.mProxy.ratings_parser.parse(cont)407 def get_movie_trivia(self, movieID):408 cont = self._retrieve(self.urls['movie_main'] % movieID + 'trivia')409 return self.mProxy.trivia_parser.parse(cont, getRefs=self._getRefs)410 def get_movie_connections(self, movieID):411 cont = self._retrieve(self.urls['movie_main'] % movieID + 'movieconnections')412 return self.mProxy.connections_parser.parse(cont)413 def get_movie_technical(self, movieID):414 cont = self._retrieve(self.urls['movie_main'] % movieID + 'technical')415 return self.mProxy.tech_parser.parse(cont)416 def get_movie_locations(self, movieID):417 cont = self._retrieve(self.urls['movie_main'] % movieID + 'locations')418 return self.mProxy.locations_parser.parse(cont)419 def get_movie_soundtrack(self, movieID):420 cont = self._retrieve(self.urls['movie_main'] % movieID + 'soundtrack')421 return self.mProxy.soundtrack_parser.parse(cont)422 def get_movie_reviews(self, movieID):423 cont = self._retrieve(self.urls['movie_main'] % movieID + 'reviews?count=9999999&start=0')424 return self.mProxy.reviews_parser.parse(cont)425 def get_movie_critic_reviews(self, movieID):426 cont = self._retrieve(self.urls['movie_main'] % movieID + 'criticreviews')427 return self.mProxy.criticrev_parser.parse(cont)428 def get_movie_external_reviews(self, movieID):429 cont = self._retrieve(self.urls['movie_main'] % movieID + 'externalreviews')430 return self.mProxy.externalrev_parser.parse(cont)431 def get_movie_external_sites(self, movieID):432 cont = self._retrieve(self.urls['movie_main'] % movieID + 'externalsites')433 ret = self.mProxy.externalsites_parser.parse(cont)434 ret['info sets'] = ('external sites', 'misc sites', 'sound clips',435 'video sites', 'photo sites', 'official sites')436 return ret437 def get_movie_official_sites(self, movieID):438 cont = self._retrieve(self.urls['movie_main'] % movieID + 'officialsites')439 ret = self.mProxy.officialsites_parser.parse(cont)440 ret['info sets'] = ('external sites', 'misc sites', 'sound clips',441 'video sites', 'photo sites', 'official sites')442 return ret443 def get_movie_misc_sites(self, movieID):444 cont = self._retrieve(self.urls['movie_main'] % movieID + 'miscsites')445 ret = self.mProxy.misclinks_parser.parse(cont)446 ret['info sets'] = ('external sites', 'misc sites', 'sound clips',447 'video sites', 'photo sites', 'official sites')448 return ret449 def get_movie_sound_clips(self, movieID):450 cont = self._retrieve(self.urls['movie_main'] % movieID + 'soundsites')451 ret = self.mProxy.soundclips_parser.parse(cont)452 ret['info sets'] = ('external sites', 'misc sites', 'sound clips',453 'video sites', 'photo sites', 'official sites')454 return ret455 def get_movie_video_clips(self, movieID):456 cont = self._retrieve(self.urls['movie_main'] % movieID + 'videosites')457 ret = self.mProxy.videoclips_parser.parse(cont)458 ret['info sets'] = ('external sites', 'misc sites', 'sound clips',459 'video sites', 'photo sites', 'official sites')460 return ret461 def get_movie_photo_sites(self, movieID):462 cont = self._retrieve(self.urls['movie_main'] % movieID + 'photosites')463 ret = self.mProxy.photosites_parser.parse(cont)464 ret['info sets'] = ('external sites', 'misc sites', 'sound clips',465 'video sites', 'photo sites', 'official sites')466 return ret467 def get_movie_news(self, movieID):468 cont = self._retrieve(self.urls['movie_main'] % movieID + 'news')469 return self.mProxy.news_parser.parse(cont, getRefs=self._getRefs)470 def _purge_seasons_data(self, data_d):471 if '_current_season' in data_d['data']:472 del data_d['data']['_current_season']473 if '_seasons' in data_d['data']:474 del data_d['data']['_seasons']475 return data_d476 def get_movie_episodes(self, movieID):477 cont = self._retrieve(self.urls['movie_main'] % movieID + 'episodes')478 data_d = self.mProxy.season_episodes_parser.parse(cont)479 if not data_d and 'data' in data_d:480 return {}481 _current_season = data_d['data'].get('_current_season', '')482 _seasons = data_d['data'].get('_seasons') or []483 data_d = self._purge_seasons_data(data_d)484 data_d['data'].setdefault('episodes', {})485 nr_eps = len(data_d['data']['episodes'].get(_current_season) or [])486 for season in _seasons:487 if season == _current_season:488 continue489 other_cont = self._retrieve(490 self.urls['movie_main'] % movieID + 'episodes?season=' + str(season)491 )492 other_d = self.mProxy.season_episodes_parser.parse(other_cont)493 other_d = self._purge_seasons_data(other_d)494 other_d['data'].setdefault('episodes', {})495 if not (other_d and other_d['data'] and other_d['data']['episodes'][season]):496 continue497 nr_eps += len(other_d['data']['episodes'].get(season) or [])498 data_d['data']['episodes'][season] = other_d['data']['episodes'][season]499 data_d['data']['number of episodes'] = nr_eps500 return data_d501 def get_movie_faqs(self, movieID):502 cont = self._retrieve(self.urls['movie_main'] % movieID + 'faq')503 return self.mProxy.movie_faqs_parser.parse(cont, getRefs=self._getRefs)504 def get_movie_airing(self, movieID):505 cont = self._retrieve(self.urls['movie_main'] % movieID + 'tvschedule')506 return self.mProxy.airing_parser.parse(cont)507 get_movie_tv_schedule = get_movie_airing508 def get_movie_synopsis(self, movieID):509 return self.get_movie_plot(movieID)510 def get_movie_parents_guide(self, movieID):511 cont = self._retrieve(self.urls['movie_main'] % movieID + 'parentalguide')512 return self.mProxy.parentsguide_parser.parse(cont)513 def _search_person(self, name, results):514 cont = self._get_search_content('nm', name, results)515 return self.spProxy.search_person_parser.parse(cont, results=results)['data']516 def get_person_main(self, personID):517 cont = self._retrieve(self.urls['person_main'] % personID)518 ret = self.pProxy.maindetails_parser.parse(cont)519 ret['info sets'] = ('main', 'filmography')520 return ret521 def get_person_filmography(self, personID):522 return self.get_person_main(personID)523 def get_person_biography(self, personID):524 cont = self._retrieve(self.urls['person_main'] % personID + 'bio')525 return self.pProxy.bio_parser.parse(cont, getRefs=self._getRefs)526 def get_person_awards(self, personID):527 cont = self._retrieve(self.urls['person_main'] % personID + 'awards')528 return self.pProxy.person_awards_parser.parse(cont)529 def get_person_other_works(self, personID):530 cont = self._retrieve(self.urls['person_main'] % personID + 'otherworks')531 return self.pProxy.otherworks_parser.parse(cont, getRefs=self._getRefs)532 def get_person_publicity(self, personID):533 cont = self._retrieve(self.urls['person_main'] % personID + 'publicity')534 return self.pProxy.publicity_parser.parse(cont)535 def get_person_official_sites(self, personID):536 cont = self._retrieve(self.urls['person_main'] % personID + 'officialsites')537 return self.pProxy.person_officialsites_parser.parse(cont)538 def get_person_news(self, personID):539 cont = self._retrieve(self.urls['person_main'] % personID + 'news')540 return self.pProxy.news_parser.parse(cont)541 def get_person_genres_links(self, personID):542 cont = self._retrieve(self.urls['person_main'] % personID + 'filmogenre')543 return self.pProxy.person_genres_parser.parse(cont)544 def get_person_keywords_links(self, personID):545 cont = self._retrieve(self.urls['person_main'] % personID + 'filmokey')546 return self.pProxy.person_keywords_parser.parse(cont)547 def _search_company(self, name, results):548 cont = self._get_search_content('co', name, results)549 url = self.urlOpener._last_url550 return self.scompProxy.search_company_parser.parse(cont, url=url,551 results=results)['data']552 def get_company_main(self, companyID):553 cont = self._retrieve(self.urls['company_main'] % companyID)554 ret = self.compProxy.company_main_parser.parse(cont)555 return ret556 def _search_keyword(self, keyword, results):557 # XXX: the IMDb web server seems to have some serious problem with558 # non-ascii keyword.559 # E.g.: http://www.imdb.com/keyword/fianc%E9/560 # will return a 500 Internal Server Error: Redirect Recursion.561 try:562 cont = self._get_search_content('kw', keyword, results)563 except IMDbDataAccessError:564 self._http_logger.warn('unable to search for keyword %s', keyword,565 exc_info=True)566 return []567 return self.skProxy.search_keyword_parser.parse(cont, results=results)['data']568 def _get_keyword(self, keyword, results):569 try:570 cont = self._retrieve(self.urls['keyword_main'] % keyword)571 except IMDbDataAccessError:572 self._http_logger.warn('unable to get keyword %s', keyword,573 exc_info=True)574 return []575 return self.skProxy.search_moviekeyword_parser.parse(cont, results=results)['data']576 def _get_top_bottom_movies(self, kind):577 if kind == 'top':578 parser = self.topBottomProxy.top250_parser579 url = self.urls['top250']580 elif kind == 'bottom':581 parser = self.topBottomProxy.bottom100_parser582 url = self.urls['bottom100']583 else:584 return []585 cont = self._retrieve(url)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!