import os #========================================================================= # If you like this software, then give it forward and do something nice for # a complete stranger. # For the rest, I release this into the public domain. # Posted on: https://www.circuitsonline.net/forum/reply/153659 #========================================================= Variables. Adjust? elektuur_path = "./" # Path name to the Elektuur magazines. elektuur_inhoudsopgave = "00aa_elektuur_nl_inhoudsopgave.txt" # Filename of index. #========================================================= Prepare Filenames. """ Goal is to: 1. Read the text file with the index. 2. split the lines into separate lists. Each line is either: * Chapter title. * ( "Year", "Month", "Page Number", "Title of article") """ inhoud20 = open( elektuur_inhoudsopgave, 'r') inhoud30 = inhoud20.readlines( ) inhoud40 = [] for asdf in inhoud30: if asdf.strip(): # Skip the empty lines. inhoud40.append( asdf.replace("\n", "")) # Remove newline from other lines. #print( inhoud40) inhoud50 = [] for asdf in inhoud40: if asdf[0].isdigit() and asdf[1].isdigit() and asdf[2].isdigit() and asdf[3].isdigit(): year = int(asdf[:4]) aline = [] aline.append( "a") # Article aline.append( int(asdf[0:4])) # Year. aline.append( int(asdf[5:7])) # Month. if asdf[8] == 'X': aline.append( 99) # Bug: Offset for the X pages? else: aline.append( int(asdf[8:11])) # Page Number. aline.append( asdf[11:]) # Article title. inhoud50.append( aline) # print( "Year:", year) else: aline = [] aline.append( "t") # Title of chapter. aline.append( asdf) # Title string. inhoud50.append( aline) # print( "Title:", asdf) print( aline) inhoud = inhoud50 for asdf in inhoud: print( asdf) inhoud20.close() #================================================== Generate asciidoc output. """ Correctian table for page offess between official page numbers, and pdf pages. Offsets are added to the offical numbers to get pdf numbers (used by browsers). For some magazines, this offset shifts though the magazine. """ correction = [ #0 1 2 3 4 5 6 7 8 9 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 000 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 010 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 020 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 030 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 040 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 050 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 060 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 070 2, 2, # J Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 082 1970-01 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 093 1971-01 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 104 1972-01 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 115 1973-01 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 126 1974-01 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 137 1975-01 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 148 1976-01 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 159 1977-01 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 171 1978-01 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 183 1979-01 2, 2, 2, 2, 2, 2, 2,102, 2, 2, 2, 4, # 195 1980-01 Ok. 0, 0, 0, 0, 0, 0, 0,100, 0, 0, 0, 0, # 207 1981-01 Ok. 0, 0, 0, 0, 0, 0, 0,100, 0, 0, 0, 0, # 219 1982-01 Ok. 0, 0, 0, 0, 0, 0, 0,104, 0, 0, 0, 0, # 231 1983-01 Ok. 0, 0, 0, 0, 0, 0, 0,104, 0, 0, 0, 0, # 243 1984-01 Ok. 0, 0, 0, 0, 0, 0, 0,100, 0, 6, 0, 0, # 255 1985-01 Ok. 0, -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 267 1986-01 Ok. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 279 1987-01 Ok. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 291 1988-01 Ok. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 303 1989-01 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, # 315 1990-01 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 327 1991-01 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 339 1992-01 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 351 1993-01 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 363 1994-01 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 375 1995-01 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 387 1996-01 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 399 1997-01 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 411 1998-01 Ok. except 07/08. Pages are broken. 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, # 423 1999-01 Ok, except 07/08. Pages are broken. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 435 2000-01 Ok. except 07/08. Pages are broken. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 447 2001-01 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 459 2002-01 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 471 2003-01 0] index = open( "00aa_index.adoc", "w") index.write( "= Elektuur 1980 t/m 2000\n") index.write( "// Created from a script on 2024-10-24\n") year = 1980 # First year of generating index. for line in inhoud: if line[0] == 't': # Title. index.write( "\n\n== ") index.write( str( year)) index.write( " ") index.write( line[1]) index.write( "\n") elif line[0] == 'a': # Article. year = line[1] month = line[2] page = line[3] issue = (year - 1963) * 12 - 10 + month index.write( "* link:Elektuur_") if month == 7: index.write( str( issue)) index.write( "_") index.write( str( issue + 1)) elif month == 8: index.write( str( issue - 1)) index.write( "_") index.write( str( issue)) else: index.write( str( issue)) index.write( "_") index.write( str( year)) index.write( "_") if month == 7: index.write( "{:0>2d}".format( month)) index.write( "_") index.write( "{:0>2d}".format( month + 1)) elif month == 8: index.write( "{:0>2d}".format( month - 1)) index.write( "_") index.write( "{:0>2d}".format( month )) else: index.write( "{:0>2d}".format( month)) index.write( ".pdf#page=") index.write( str( page + correction[issue])) index.write( "[") index.write( line[4]) # String with the article name. index.write( "] ~#") # ~ = subscript. index.write( str( issue)) index.write( "~ ~") index.write( str( year)) index.write( "-") index.write( "{:0>2d}".format( month )) index.write( "~ ~/") index.write( str( page)) index.write( "~\n") # index.write( "]\n") # print( line) index.close()