Forum for Bill Spight's Elf Positional Judgment Exercises

Converting from L19 to SL format [#8405]

Back to forum     Back to page

New reply

 
reply
xela: Converting from L19 to SL format (2019-12-07 05:15) [#11454]

Just in case anyone is wondering: pasting discussion from [ext] http://lifein19x19.com to SL can be time-consuming if you manually replace each occurrence of :w1: with W1, :bc: with black+circle, etc. I've made a Python script which gets the task down to a few seconds per page. This is custom made for Bill's posts and would need more work to convert it to a generic tool (I haven't caught all the special characters, and was too lazy to parse the "quote" tag properly). Use at own risk!


#! /usr/bin/python3

# Read one of Bill Spight's posts
# and reformat the text for SL

# Replacements needed include:
#  :w5: change to W5 and sim for other numbers
#  :w21: change to W21 and sim for other numbers
#  :wc: change to WC
#  all of the above with b/B instead of w/W
# [b]something[/b] change to __something__
# [i]something[/i] change to ''something''
# delete [quote], [/quote], [go], [/go]

import sys, os, re

infile = sys.argv[1]
outfile = sys.argv[2]

if (os.path.exists(outfile)):
  sys.exit("Error: output file " + outfile + " already exists.")

with open(infile, 'r') as file:
  text = file.read()

text = text.replace('[b]', '__')
text = text.replace('[/b]', '__')
text = text.replace('[i]', "''")
text = text.replace('[/i]', "''")
text = text.replace(':wc:', 'WC')
text = text.replace(':bc:', 'BC')
text = text.replace(':wt:', 'WT')
text = text.replace(':bt:', 'BT')
text = text.replace('[go]', '')
text = text.replace('[/go]', '')
text = text.replace('[quote="Bill Spight"]', '')
text = text.replace('[/quote]', '')
text = text.replace('[hide]', '')
text = text.replace('[/hide]', '')

text = re.sub("(:w)([0-9]*)(:)", r"W\2", text)
# note r for raw string, so that \2 is interpreted as a backreference not as unicode character number 2!
text = re.sub("(:b)([0-9]*)(:)", r"B\2", text)

with open(outfile, 'w') as file:
  file.write(text)
reply
Dieter: ((no subject)) (2019-12-08 17:09) [#11457]

fantastic effort!

pardon my basic, but how do I run a python script? in the command prompt?

X
Unkx80: Re: ((no subject)) (2019-12-08 18:47) [#11458]

Of course, the prerequisite is to have the [ext] Python interpreter installed.

Here is one way to run the script. Note that this is definitely not the only way to use it!

First, copy and paste the code into a text file, named "convert.py".

For each post you want to convert:

  • Save the post into a file "in.txt" in the same directory as "convert.py".
  • In the Command Prompt:
    • Navigate into the directory containing the "convert.py" script. For example, if this directory is in "D:\Scripts", you would execute "D:" followed by "cd \Scripts".
    • Execute the command: "python convert.py in.txt out.txt"
  • The converted post is now in "out.txt". :)
reply
xela: ((no subject)) (2019-12-09 10:07) [#11459]

Thanks Unkx80, you got here first :-) That's a really good explanation. (I normally do this sort of thing on Linux, and sometimes forget that most normal people use Windows and aren't accustomed to using the command prompt.)

X
Dieter: Re: ((no subject)) (2019-12-09 10:36) [#11460]

I am accustomed to the command prompt, but unkx's procedure still doesn't work for me. (python not recognized as internal or external command) But I'll get to one of the engineers at the office and they'll show me.

Unkx80: Re: ((no subject)) (2019-12-12 09:52) [#11461]

Sorry for the very late response, but in this case you need to add the Python installation directory into your PATH environment variable.

Right now I am on a Linux machine so I can't verify any steps. However, this might help: [ext] https://www.computerhope.com/issues/ch000549.htm

 
Back to forum     Back to page

New reply


Forum for Bill Spight's Elf Positional Judgment Exercises
RecentChanges · StartingPoints · About
Edit page ·Search · Related · Page info · Latest diff
[Welcome to Sensei's Library!]
RecentChanges
StartingPoints
About
RandomPage
Search position
Page history
Latest page diff
Partner sites:
Go Teaching Ladder
Goproblems.com
Login / Prefs
Tools
Sensei's Library