Best Python code snippet using pyatom_python
backend.py
Source:backend.py  
...19    def __init__( self ):20        threading.Thread.__init__( self )21        self._stop = False22        self.current_actor = None23    def clearProperties( self ):24        window = xbmcgui.Window( self.windowID )25        for prt in [ "name", "biography", "biooutline", "birthday", "deathday", "placeofbirth", "alsoknownas", "homepage", "adult", "age", "deathage", "agelong", "deathagelong", "fanart", "icon", "extrafanart", "extrathumb", "happybirthday" ][ ::-1  ]:26            window.clearProperty( "current.actor." + prt )27    def setProperties( self ):28        self.clearProperties()29        if not self.current_actor: return30        #( "idactor", "id", "name", "biography", "biooutline", "birthday", "deathday", "placeofbirth", "alsoknownas", "homepage", "adult", "cachedthumb" )31        window = xbmcgui.Window( self.windowID )32        birthday = self.current_actor[ 5 ] or ""33        window.setProperty( "current.actor.name",         self.current_actor[ 2 ]  or "" )34        window.setProperty( "current.actor.biography",    metautils.clean_bio( self.current_actor[ 3 ] or "" ) )35        window.setProperty( "current.actor.biooutline",   self.current_actor[ 4 ]  or "" )36        window.setProperty( "current.actor.birthday",     birthday )37        window.setProperty( "current.actor.deathday",     self.current_actor[ 6 ]  or "" )38        window.setProperty( "current.actor.placeofbirth", self.current_actor[ 7 ]  or "" )39        window.setProperty( "current.actor.alsoknownas",  self.current_actor[ 8 ]  or "" )40        window.setProperty( "current.actor.homepage",     self.current_actor[ 9 ]  or "" )41        window.setProperty( "current.actor.adult",        self.current_actor[ 10 ] or "" )42        if birthday and BIRTH_MONTHDAY in birthday:43            window.setProperty( "current.actor.happybirthday", "true" )44        actuel_age, dead_age, dead_since = metautils.get_ages( birthday, self.current_actor[ 6 ] )45        window.setProperty( "current.actor.age",      actuel_age )46        window.setProperty( "current.actor.deathage", dead_age )47        if actuel_age: window.setProperty( "current.actor.agelong",      STR_AGE_LONG % actuel_age )48        if dead_since: window.setProperty( "current.actor.deathagelong", STR_DEAD_SINCE % dead_since )49        elif dead_age: window.setProperty( "current.actor.deathagelong", STR_DEATH_AGE_LONG % dead_age )50        fanart = TBN.get_fanarts( self.current_actor[ 2 ] )[ 0 ]51        window.setProperty( "current.actor.fanart", fanart )52        icon = "".join( TBN.get_thumb( self.current_actor[ 2 ] ) )53        window.setProperty( "current.actor.icon",   icon )54        # check exist to prevent multiple ERROR: XFILE::CDirectory::GetDirectory - Error getting special://thumbnails/Actors/[ACTOR NAME]/foo/55        cached_actor_thumb = "special://thumbnails/Actors/" + self.current_actor[ 2 ] + "/"56        for extra in [ "extrafanart", "extrathumb" ]:57            #if xbmcvfs.exists( cached_actor_thumb + extra ):58            window.setProperty( "current.actor." + extra, cached_actor_thumb + extra )59    def stop( self ):60        print self.strEnd61        self.clearProperties()62        self._stop = True63    def autoStop( self, hrs=2 ):64        # get auto stop to prevent 24/7 running :D65        # http://forum.xbmc.org/showthread.php?tid=129473&pid=1082117#pid108211766        return xbmc.getGlobalIdleTime() > ( hrs*60**2 )67class Dialog( Backend ):68    def __init__( self ):69        Backend.__init__( self )70        self.strEnd = "Actor dialog backend ended!"71        self.windowID = 1200372        # get actors from actors1.db73        self.get_actors()74        # start thread75        self.start()76    def get_actors( self ):77        xbmcgui.Window( 10025 ).clearProperty( "reload.actors.backend" )78        self.ACTORS = get_actors_for_backend( xbmc )79    def run( self ):80        try:81            print "Actor dialog backend started!"82            while not self._stop:83                if not xbmc.getCondVisibility( "Window.IsVisible(12003)" ) or self.autoStop(): self.stop()84                if xbmc.getCondVisibility( "![Window.IsVisible(progressdialog) | Window.IsVisible(selectdialog)]" ):85                    if xbmcgui.Window( 10025 ).getProperty( "reload.actors.backend" ) == "1": self.get_actors()86                    temp_actor = self.ACTORS.get( unicode( xbmc.getInfoLabel( "Container(50).ListItem.Label" ), "utf-8" ) )87                    if temp_actor != self.current_actor:88                        self.current_actor = temp_actor89                        self.setProperties()90                time.sleep( .25 )91        except SystemExit:92            print "SystemExit!"93            self.stop()94        except:95            print_exc()96            self.stop()97class Window( Backend ):98    def __init__( self ):99        Backend.__init__( self )100        self.strEnd = "Actor backend ended!"101        self.windowID = 10025102        # get actors from actors1.db103        self.get_actors()104        # start thread105        self.start()106    def get_actors( self ):107        xbmcgui.Window( 10025 ).clearProperty( "reload.actors.backend" )108        self.ACTORS = get_actors_for_backend( None )109    def run( self ):110        try:111            print "Actor backend started!"112            while not self._stop:113                if not xbmc.getCondVisibility( "Window.IsVisible(10025)" ) or self.autoStop(): self.stop()114                if xbmc.getCondVisibility( "Container.Content(Actors) | Container.Content(Directors) | Container.Content(Artists)" ):115                    if xbmcgui.Window( 10025 ).getProperty( "reload.actors.backend" ) == "1": self.get_actors()116                    temp_actor = self.ACTORS.get( unicode( xbmc.getInfoLabel( "ListItem.Label" ), "utf-8" ) )117                    if temp_actor != self.current_actor:118                        self.current_actor = temp_actor119                        self.setProperties()120                else:121                    self.clearProperties()122                    self.current_actor = None123                time.sleep( .25 )124        except SystemExit:125            print "SystemExit!"126            self.stop()127        except:128            print_exc()129            self.stop()130if __name__=="__main__":131    args = ",".join( sys.argv[ 1: ] )132    if "dialogbackend" in args.lower():133        Dialog()134    else:135        Window()PlayerAPI.py
Source:PlayerAPI.py  
...40				if desiredPrprty in valDict.keys():41					tmpProperties[valDict[desiredPrprty]] = self.getText(node.childNodes).rstrip().lstrip()42					#print properties43		return tmpProperties44	def clearProperties(self):45		del self.properties[:]46		self.properties = []47	def getPlayersByTeam(self,teamID):48		self.url = 'http://www.xmlsoccer.com/FootballDataDemo.asmx/GetPlayersByTeam?ApiKey='+self.API_KEY+'&teamId='+str(teamID)49		self.makeAPICall()50		xmlPlayers = self.xmldoc.getElementsByTagName('XMLSOCCER.COM')[0].getElementsByTagName('Player')51		52		self.clearProperties()53		valDict = {'Id':'ID', 'Name':'Name', 'Height':'Height', 'Weight':'Weight', 'Nationality':'Nationality', 'Position':'Position', 'Team_Id':'TeamID', 'PlayerNumber':'JerseyNumber', 'DateOfBirth':'Birthday', 'DateOfSigning':'SignDate', 'Signing':'Signing'}54		for xmlPlayer in xmlPlayers:55			self.properties.extend([self.parseProperties(xmlPlayer.childNodes, valDict)])56		#print properties57		return self.properties58	def getPlayerById(self, playerID):59		self.url =  'http://www.xmlsoccer.com/FootballDataDemo.asmx/GetPlayerById?ApiKey='+self.API_KEY+'&playerId='+str(playerID)60		self.makeAPICall()61		xmlPlayers = self.xmldoc.getElementsByTagName('XMLSOCCER.COM')[0].getElementsByTagName('Player')62		self.clearProperties()63		valDict = {'Id':'ID', 'Name':'Name', 'Height':'Height', 'Weight':'Weight', 'Nationality':'Nationality', 'Position':'Position', 'Team_Id':'TeamID', 'PlayerNumber':'JerseyNumber', 'DateOfBirth':'Birthday', 'DateOfSigning':'SignDate', 'Signing':'Signing'}64		for xmlPlayer in xmlPlayers:65			return self.parseProperties(xmlPlayer.childNodes,valDict)66	67	def setRosterInTeam(self, teamID):68		self.clearProperties()69		players = self.getPlayersByTeam(teamID)70		return {'roster': players}71#p = Player()72#print p.getPlayerById(11510)73#print p.setRosterInTeam(1)...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!!
