poirot.html
001| from os import path
002|
003| BasePath = r"C:\CJS\prj\Python\ws"
004|
005| TheList = """\
005| S1 The Adventure of the Clapham Cook (20)
005| S1 Murder in the Mews (35)
005| S1 The Adventure of Johnnie Waverly (15)
005| S1 Four and Twenty Blackbirds (51)
005| S1 The Third Floor Flat (29)
005| S1 Triangle at Rhodes (34)
005| S1 Problem at Sea (33)
005| S1 The Incredible Theft (19)
005| S1 The King of Clubs (03)
005| S1 The Dream (37)
005| S2 Peril at End House, part 1 [07]
005| S2 Peril at End House, part 2 [07]
005| S2 The Veiled Lady (14)
005| S2 The Lost Mine (21)
005| S2 The Cornish Mystery (22)
005| S2 The Disappearance of Mr. Davenheim (04)
005| S2 Double Sin (27)
005| S2 The Adventure of the Cheap Flat (10)
005| S2 The Kidnapped Prime Minister (08)
005| S2 The Adventure of the Western Star (06)
005| S3 The Mysterious Affair at Styles [01]
005| S3 How Does Your Garden Grow? (32)
005| S3 The Million Dollar Bond Robbery (09)
005| S3 The Plymouth Express (05)
005| S3 Wasp’s Nest (28)
005| S3 The Tragedy at Marsdon Manor (07)
005| S3 The Double Clue (23)
005| S3 The Mystery of the Spanish Chest (30)
005| S3 The Theft of the Royal Ruby (24)
005| S3 The Affair at the Victory Ball (01)
005| S3 The Mystery of Hunter’s Lodge (11)
005| S4 The ABC Murders [12]
005| S4 Death in the Clouds [11]
005| S4 One, Two, Buckle My Shoe [20]
005| S5 The Adventure of the Egyptian Tomb (13)
005| S5 The Underdog (26)
005| S5 The Yellow Iris (36)
005| S5 The Case of the Missing Will (18)
005| S5 The Adventure of the Italian Nobleman (17)
005| S5 The Chocolate Box (12)
005| S5 Dead Man’s Mirror (31)
005| S5 Jewel Robbery at the Grand Metropolitan (02)
005| S6 Hercule Poirot’s Christmas [18]
005| S6 Hickory Dickory Dock [27]
005| S6 Murder on the Links [02]
005| S6 Dumb Witness [15]
005| S9 Five Little Pigs [22]
005| S9 Sad Cypress [19]
005| S9 Death on the Nile [16]
005| S9 The Hollow [23]
005| S10 The Mystery of the Blue Train [05]
005| S10 After the Funeral [26]
005| S10 Cards on the Table [14]
005| S10 Taken at the Flood [24]
005| S11 Mrs. McGinty’s Dead [25]
005| S11 Cat Among the Pidgeons [29]
005| S11 Third Girl [31]
005| S11 Appointment with Death [17]
005| S12 Three Act Tragedy [10]
005| S12 Hallowe’en Party [32]
005| S12 Murder on the Orient Express [09]
005| S12 The Clocks [30]
005| S13 Elephants Can Remember [33]
005| S13 The Big Four [04]
005| S13 Dead Man’s Folly [28]
005| S13 The Labours of Hercules (38)
005| S13 Curtain - Poirot’s Final Case [34]
005| """
006|
007|
008| class EpisodeData (list):
009|
010| def __init__ (self):
011|
012| self.rows = TheList.splitlines()
013|
014|
015| self.eps = [row.split('\t') for row in self.rows]
016|
017|
018| self.titles = {}
019|
020|
021| episode_number = None
022| curr_season = None
023|
024| for season,title,which in self.eps:
025| if season != curr_season:
026| curr_season = season
027| episode_number = 1
028| t = (int(season[1:]), episode_number, which, title)
029| self.append(t)
030| self.titles[title] = t
031| episode_number += 1
032|
033|
034| def __repr__ (self):
035| return f'<{type(self).__name__} {len(self)} eps @{id(self):012x}>'
036|
037| def __str__ (self):
038| return f'Poirot: {len(self)} episodes'
039|
040| def save (self, fname):
041| '''Save episode data to a file.'''
042| with open(fname, mode='w', encoding='utf-8') as fout:
043|
044|
045| for ix,t in enumerate(self, start=1):
046| season,episode,which,title = t
047| s = f'{ix:02d}: "{title}" (S{season}E{episode}) {which}'
048| print(s, file=fout)
049| print(s)
050|
051| print(file=fout)
052| print()
053|
054|
055| by_seq = list(sorted(self, key=lambda t:t[2]))
056|
057| for ix,t in enumerate(by_seq, start=1):
058| season,episode,which,title = t
059| s = f'{ix:02d}: {which} "{title}" (S{season}E{episode})'
060| print(s, file=fout)
061| print(s)
062|
063| print(file=fout)
064| print()
065|
066|
067| def main ():
068| filename = path.join(BasePath, "poirot.out")
069|
070| data = EpisodeData()
071| data.save(filename)
072|
073| return data
074|
075| if __name__ == '__main__':
076| rv = main()
077|