Surf ID

From Sludgy Terrapin, 2 Weeks ago, written in Plain Text, viewed 3 times. This paste will die in 1 Week.
URL https://paste.afonso.co/view/c15149cd Embed
Download Paste or View Raw
  1. # -*- encoding: utf-8 -*-
  2. from System.IO import File, Path
  3.  
  4. attributesToValidate = ["Firstname", "Lastname", "Name", "Info1"]
  5.  
  6. def __onStart(WorkflowType):
  7.        
  8.         for item in Script.GetIntelliflow().ItemsOnAir:
  9.                 if item.Server.Type.ToString() == "Program" and  item.Scene.Name == Script.Scene.Name:
  10.                         Script.ClearTransition()
  11.                         return False           
  12.  
  13.         if WorkflowType.ToString() != "PreviewToProgram":
  14.                 validTabs = ["last battle", "current heat", "historic"]
  15.                 selectedTab = SurfInfo.GetSelectedTab()
  16.                 if selectedTab.lower() not in validTabs:
  17.                         Core.StatusManager.Add("Select a valid battle or heat")
  18.                         return False   
  19.                
  20.                 surferRow = SurfInfo.GetProfile()
  21.                 if not surferRow or not surferRow.SurferPlayer:
  22.                         Core.StatusManager.Add("No data available.\nPlease import data and/or \nselect a surfers before \nshowing this slide")
  23.                         return False
  24.                
  25.                 invalidAttributes = []
  26.                 for attributeToValidate in attributesToValidate:
  27.                         if not hasattr(surferRow.SurferPlayer, attributeToValidate) or getattr(surferRow.SurferPlayer, attributeToValidate) == None:
  28.                                 invalidAttributes.append(attributeToValidate)
  29.                
  30.                 if invalidAttributes:
  31.                         Core.StatusManager.Add("Surfer Id '%s' has no valid attributes: %s" % (surferRow.SurferPlayer.IdSurfer, ", ".join(invalidAttributes)))
  32.                         return False           
  33.                
  34.                 photosDirectory =  Path.Combine("R:\\", "Projects", wTvisionRE.Project, "Images", "Photos")
  35.                 photoPath = Path.Combine(photosDirectory, "%s.jpg"%surferRow.SurferPlayer.Name)
  36.                 if not File.Exists(photoPath):
  37.                         if str(MsgBox.Show("Missing Photos", "Missing Surfer photo in %s:\n%s\nContinue anyway?" % (photosDirectory, "%s.jpg"%surferRow.SurferPlayer.Name), MsgBox.ButtonsCombo.YesNo)) != "Yes":
  38.                                 return False
  39.                
  40.                 if not ProjectSettings.ContainsKey("SocialNetwork Logo") or not ProjectSettings["SocialNetwork Logo"]:
  41.                         Core.StatusManager.Add("ProjectSettings doesn't contain 'SocialNetwork Logo' key or value")
  42.                         return False
  43.                        
  44.        
  45.        
  46.  
  47. ######################## FILL DATA ########################
  48. def __getData(viewBag):
  49.        
  50.         surferProfile = SurfInfo.GetProfile()
  51.         if not surferProfile or not surferProfile.SurferPlayer:
  52.                 return False
  53.        
  54.         if SurfInfo.GetSelectedTab() == "Historic":
  55.                 result = SurfInfo.GetHeatInfoHistoric()
  56.         else:
  57.                 result = SurfInfo.GetFullHeatResult()
  58.        
  59.         surferPlayer = surferProfile.SurferPlayer
  60.        
  61.         surfer = next((item for item in list(result.HeatInfo.Lines) if item.Player.IdSurfer == surferPlayer.IdSurfer), None)
  62.         if not surfer:
  63.                 Core.StatusManager.Add("Surfer not found")
  64.                 return False
  65.         viewBag.SetImage("lgCompetition", "/Images/CompetitionLogos/%s.png" % ProjectSettings["Competition Logo"])
  66.         photosDirectory =  Path.Combine("R:\\", "Projects", wTvisionRE.Project, "Images", "Photos")
  67.         photoPath = Path.Combine(photosDirectory, "%s.jpg"%surferPlayer.Name)
  68.         if File.Exists(photoPath):
  69.                 viewBag.SetImage("lgPhoto", "/Images/Photos/%s.jpg"%surferPlayer.Name)
  70.         else:
  71.                 viewBag.SetImage("lgPhoto", "/Images/Photos/NoPhoto.png")
  72.        
  73.         viewBag.SetImage("lgShirtColor", "/Images/ShirtColor/" + (surfer.Color if surfer.Color else "vaz") + ".png")
  74.        
  75.         viewBag.SetString("tSurferName", surferPlayer.Firstname.upper())
  76.         viewBag.SetString("tSurferSurname", surferPlayer.Lastname.upper())
  77.        
  78.         viewBag.SetString("tTeam", surferProfile.SurferPlayer.Info1.ToString().upper())
  79.        
  80.         socialNetwork = surferProfile.SurferPlayer.Instagram
  81.         if socialNetwork:
  82.                 viewBag.SetTranslatedText("tSocialNetwork", "{{@}}.{{SocialNetwork}}%s"%socialNetwork)
  83.                 viewBag.SetVisibility("vSocialNetworkVisibility", True)
  84.         else:
  85.                 viewBag.SetString("tSocialNetwork", "")
  86.                 viewBag.SetVisibility("vSocialNetworkVisibility", False)
  87.        
  88.         viewBag.SetImage("lgSocialNetwork", "/Images/SocialNetwork/%s.png" % ProjectSettings["SocialNetwork Logo"])
  89.        

Reply to "Surf ID"

Here you can reply to the paste above