def fillScorers(stat, team, viewBag): idx = 1 count = 0 lines = 0 tagsDict = {} font = Font("Arial", 12) for item in stat: player = item[-1] name = player.ShortName goalTimes = [] previousGoalTimes = [] translate = False for i, goal in enumerate(item[1]): isPen = item[7][i] isOG = item[6][i] appendValue = "" if goal.Contains("+") and goal[-1] == "'": goal = goal.rstrip(goal[-1]) if isPen: translate = True appendValue = ("%s {{(P)}}" % goal) elif isOG: translate = True appendValue = ("%s {{(OG)}}" % goal) else: appendValue = (goal) goalTimes.append(appendValue) tempTimes = " ".join(goalTimes) tempTotalStr = name + " " + tempTimes if idx in tagsDict: tempTotalStr = tagsDict[idx][1].TrimEnd() + ", " + tempTotalStr width = measure_text_width(tempTotalStr.replace("{","").replace("}",""), font) if width > lineLen: if previousGoalTimes: times = " ".join(previousGoalTimes) if idx in tagsDict: tagsDict[idx] = (translate or tagsDict[idx][0], "%s, %s %s " % (tagsDict[idx][1].TrimEnd(), name, times)) else: tagsDict[idx] = (translate, "%s %s " % (name, times)) goalTimes = [] previousGoalTimes = [] goalTimes.append(appendValue) idx += 1 elif idx in tagsDict: idx += 1 previousGoalTimes = goalTimes[:] times = " ".join(goalTimes) totalStr = name + " " + times.replace("{","").replace("}","") width2 = measure_text_width(totalStr, font) count += width2 if count > lineLen: idx += 1 count = width2 if idx in tagsDict: tagsDict[idx] = (translate or tagsDict[idx][0], "%s %s %s " % (tagsDict[idx][1].TrimEnd() + ", ", name, times)) else: tagsDict[idx] = (translate, "%s %s " % (name, times)) total = len(tagsDict) if team == "Home": i = 1 for ignore, value in tagsDict.items(): lines += 1 translate, name = value if translate: viewBag.SetTranslatedText("tHomeTeamScorer%02d" % i, name) else: viewBag.SetString("tHomeTeamScorer%02d" % i, name) i += 1 if team == "Away": i = 1 for ignore, value in tagsDict.items(): lines += 1 translate, name = value if translate: viewBag.SetTranslatedText("tAwayTeamScorer%02d" % i, name) else: viewBag.SetString("tAwayTeamScorer%02d" % i, name) i+= 1 return lines