Difference between revisions of "User:Alvonruff/Python2.7 Futurize"

From ISFDB
Jump to navigation Jump to search
Line 85: Line 85:
 
         param += '\n|Artist1=%s\n|Artist2=%s' % (cover_artists[0][1].decode('utf8', 'ignore'), cover_artists[1][1])
 
         param += '\n|Artist1=%s\n|Artist2=%s' % (cover_artists[0][1].decode('utf8', 'ignore'), cover_artists[1][1])
 
         param += '\n|Artist3=%s' % cover_artists[2][1].decode('utf8', 'ignore')
 
         param += '\n|Artist3=%s' % cover_artists[2][1].decode('utf8', 'ignore')
 +
 +
These changes merely allows the script to complete, as it does not output the offending characters. Need to find the real fix.
 +
 +
===Author Tags===
 +
'''Issue:''' When printing the title links associated with specific tags, whenever the title contains (not an exhaustive list): Italian, German.
 +
 +
'''Examples:''' https://www.isfdb2.org/cgi-bin/p3/tag_author.cgi?31+5
 +
 +
'''Workarounds:'''
 +
In __main__ (biblio/tag_author.py), on the first line within the title_list loop, change it to:
 +
    print('\<li\>%s - %s ' % (ISFDBconvertYear(title_record[0][:4]), ISFDBLink('title.cgi', title_record[2], title_record[1].decode('utf8', 'ignore'))))
  
 
These changes merely allows the script to complete, as it does not output the offending characters. Need to find the real fix.
 
These changes merely allows the script to complete, as it does not output the offending characters. Need to find the real fix.

Revision as of 09:40, 15 September 2022

Prerequisites

  • pip2 install future
  • pip2 install six

Conversion

  • Within the target directory (biblio, common, edit, etc), create a new directory called FUTURIZE
  • Create a shell script which lists all py files in the target directory, and turn it into a set of futurize commands as shown below. This will create a modified version of the file in the local FUTURIZE directory.
   set -x
   futurize adv_identifier_search.py -n -w -o FUTURIZE
   futurize adv_notes_search.py -n -w -o FUTURIZE
   futurize advSearchClass.py -n -w -o FUTURIZE
   futurize adv_search_menu.py -n -w -o FUTURIZE
   futurize adv_search_results.py -n -w -o FUTURIZE
   ...
  • Edit each of the output files, and move any import lines of the form "from __future__ import xxx" below the top comment block. The first line of the comment block contains the poundbang statement, which tells the OS that it should use python to interpret the file. The poundbang statement must be the first line of the file, but futurize will place some of the import statements before the poundbang, causing a runtime error.
  • You are now free to replace specific files within the target directory with its futurized version. You may want to keep a directory containing original versions of the files, so that you may revert to its original state if some disaster ensues.

Issues

The first step in resolving the issues generated by the futurizing process is to identify them, and find a workaround that keeps the script running, so that other issues in the script can also be identified. None of the workarounds are actual fixes.

Pound Pricing

Issue: When printing publication details, an exception occurs whenever the pricing is in British Pounds. It's curious that the publication note can have information utilizing the Pound symbol, but the Price field fails.

Example: https://www.isfdb2.org/cgi-bin/p3/pl.cgi?911384

Workaround: At the beginning of ISFDBPrice (common/library.py) place:

   price = price.decode('utf8', 'ignore')

This merely allows the script to complete, as it does not output a Pound symbol. Need to find the real fix.

Titles and Variant Titles

Issue: When printing a title or variant title, an exception occurs whenever the variant title contains (not an exhaustive list): Italian, German.

Examples:

https://isfdb2.org/cgi-bin/p3/ea.cgi?26

https://isfdb2.org/cgi-bin/p3/ea.cgi?342790

Workarounds: In buildCoreTitleLine (biblio/common.py), just after the comment to "Convert special years to strings" place:

   output = output.decode('utf8', 'ignore')
   cnvyear = cnvyear.decode('utf8', 'ignore')

In displayVariantTitle (biblio/common.py), just after the comment to "Convert special years to strings" place:

   output = output.decode('utf8', 'ignore')
   cnvyear = cnvyear.decode('utf8', 'ignore')

Both of these changes merely allows the script to complete, as it does not output the offending characters. Need to find the real fix.

Publication Contents

Issue: When printing the contents of a publication (magazine, anthology, collection), an exception occurs whenever a title contains (not an exhaustive list): Italian, German.

Examples: https://www.isfdb2.org/cgi-bin/p3/pl.cgi?713111

Workarounds: In PrintTitleLine (biblio/pl.py), just after adding COVERART:

   output = output.decode('utf8', 'ignore')

Also in PrintTitleLine (biblio/pl.py), in the section which prints the parent title:

   output = output.decode('utf8', 'ignore')

Both of these changes merely allows the script to complete, as it does not output the offending characters. Need to find the real fix.

Publications, when Generating Link for New Cover Scan

Issue: When printing the link for a new cover scan, an exception occurs whenever the artist(s) contain (not an exhaustive list): Italian, German.

Examples: https://www.isfdb2.org/cgi-bin/p3/pl.cgi?576760

Workarounds: In __main__ (biblio/pl.py), just before utilizing the publisher_string, add:

   param = template + '\n|Title=' + pub.pub_title.decode('utf8', 'ignore')
   publisher_string = publisher_string.decode('utf8', 'ignore')

In __main__ (biblio/pl.py), where generating the CID information, change code to:

   if template == 'CID1':
       if len(cover_artists) == 0:
           param += '\n|Artist=' + 'Unknown'
       else:
           param += '\n|Artist=%s\n|ArtistId=%d' % (cover_artists[0][1].decode('utf8', 'ignore'), cover_artists[0][0])
   elif template == 'CID1-2':
       param += '\n|Artist1=%s\n|Artist2=%s' % (cover_artists[0][1].decode('utf8', 'ignore'), cover_artists[1][1])
   elif template == 'CID1-3':
       param += '\n|Artist1=%s\n|Artist2=%s' % (cover_artists[0][1].decode('utf8', 'ignore'), cover_artists[1][1])
       param += '\n|Artist3=%s' % cover_artists[2][1].decode('utf8', 'ignore')

These changes merely allows the script to complete, as it does not output the offending characters. Need to find the real fix.

Author Tags

Issue: When printing the title links associated with specific tags, whenever the title contains (not an exhaustive list): Italian, German.

Examples: https://www.isfdb2.org/cgi-bin/p3/tag_author.cgi?31+5

Workarounds: In __main__ (biblio/tag_author.py), on the first line within the title_list loop, change it to:

   print('\<li\>%s - %s ' % (ISFDBconvertYear(title_record[0][:4]), ISFDBLink('title.cgi', title_record[2], title_record[1].decode('utf8', 'ignore'))))

These changes merely allows the script to complete, as it does not output the offending characters. Need to find the real fix.