Diff for "ForumWikiTeam/ImportTool"


Differences between revisions 19 and 20
Revision 19 as of 2012-05-09 18:26:56
Size: 5020
Editor: host86-130-24-251
Comment:
Revision 20 as of 2012-05-09 18:35:11
Size: 5185
Editor: host86-130-24-251
Comment:
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
# Version 0.1 # Version 0.3
Line 13: Line 13:
# Assistance from cortman, forestpiskie, and wildmanne39 # Assistance from bobweaver, cortman, forestpiskie, nothingspecial, and wildmanne39
Line 25: Line 25:
[[ -d "${HOME}/Documents/ubforums2ubwiki" ]] || mkdir -p $HOME/Documents/ubforums2ubwiki
#echo "This script calls the converter program and will create a converted file."
#echo "First we'll confirm you have html2wiki installed on your computer, and if not, will install it."
# need to check for html2wiki
Line 29: Line 27:
# need to check for gedit
[[ -x /usr/bin/gedit ]] || sudo apt-get -y install gedit
Line 35: Line 31:
DIR="${HOME}/Documents/ubforums2ubwiki" DIR="${HOME}/Documents/wiki"
# Does the working directory exist ? $HOME/Documents/wiki
[[ -d "${DIR}" ]] || mkdir -p "${DIR}"
Line 44: Line 42:
GEDIT=$(which gedit) if [ -x /usr/bin/gedit ]; then
  EDIT='/usr/bin/gedit'
elif [ -x /usr/bin/kate ]; then
  EDIT='/usr/bin/kate'
elif [ -x /usr/bin/leafpad ]; then
  EDIT='/usr/bin/leafpad'
else
  EDIT=$($ZENITY --title="Please choose an editor" --file-selection)
  return_value=$?
  if [ "$return_value" -ne "0" ]; then exit 1; fi
fi
Line 48: Line 56:
# Download the page to ~/$HOME/Documents/ubforums2ubwiki/file.html # Download to working directory ~/$HOME/Documents/wiki
Line 53: Line 61:

# The was dialog to select what to convert, we can add it in later
#echo "Enter filename."
#read yourfile
Line 77: Line 80:
$AWK '/-- message --/,/\/ message --/' "${FILE}" | $GREP -v '(Code|Quote):' > "${CLEAN}" $AWK '/-- message --/ {n++}; /-- \/ message --/ {n++} ;{if (n == 1) {print}}; {if ( n > 1 ) {exit}}' "${FILE}" | $GREP -v '(Code|Quote):' > "${CLEAN}"
return_value=$?
if [ "$return_value" -ne "0" ]; then echo -e '\e[0;31m' "Cleanup Failed"; exit 1; fi
Line 94: Line 99:

#Cleanup
return_value=$?
if [ "$return_value" -ne "0" ]; then echo -e '\e[0;31m' "Conversion Failed"; exit 1; fi
Line 98: Line 103:
$GEDIT "${WIKI}" $EDIT "${WIKI}"
return_value=$?
if [ "$return_value" -ne "0" ]; then echo -e '\e[0;31m' "Opening document with your editor failed"; exit 1; fi
Line 100: Line 107:
#This is an old line from a previous attempt at this script.
# Not sure what the problem was , so left it
#sed -r 's/[^[:space:]]*\.(jpg|jpeg|png|gif)/{{&}}/g' $yourfile.new > $yourfile}}}

}}}

Forum Import Tool

This tool is still in development and subject to change.

Installing the software

# ubforums2ubwiki.sh
# Version 0.3
# Copyleft 2012 bodhi.zazen
# Assistance from bobweaver, cortman, forestpiskie, nothingspecial, and wildmanne39
# This program is distributed free under terms of the GNU General Public License (v. 3.0)

# script converts Ubuntu forums (VBulletin syntax) posts to
# Ubuntu wiki (moin moin markdown).

# Designed to facilitate transcribing Tutorials and documentation
# from Ubuntu forums to Ubuntu wiki.
# Pages for import are listed at
# https://help.ubuntu.com/community/Pages%20For%20Import

# Sanity checks
# need to check for html2wiki
[[ -x /usr/bin/html2wiki ]] || sudo apt-get -y install libhtml-wikiconverter-moinmoin-perl
# need to check for zenity
[[ -x /usr/bin/zenity ]] || sudo apt-get -y install zenity

# Variables
DIR="${HOME}/Documents/wiki"
# Does the working directory exist ? $HOME/Documents/wiki
[[ -d "${DIR}" ]] || mkdir -p "${DIR}"
AWK=$(which awk)
GREP=$(which egrep)
SED=$(which sed)
CONVERT='html2wiki --dialect MoinMoin'
WGET=$(which wget)
ZENITY=$(which zenity)
NAME=''
URL=''
if [ -x /usr/bin/gedit ]; then
  EDIT='/usr/bin/gedit'
elif [ -x /usr/bin/kate ]; then
  EDIT='/usr/bin/kate'
elif [ -x /usr/bin/leafpad ]; then
  EDIT='/usr/bin/leafpad'
else
  EDIT=$($ZENITY --title="Please choose an editor" --file-selection)
  return_value=$?
  if [ "$return_value" -ne "0" ]; then exit 1; fi
fi
CAT='/bin/cat'

# What post to transcribe
# Download to working directory ~/$HOME/Documents/wiki

URL=$($ZENITY --entry --title="Tutorial to transcribe" --text="Paste the tutorial URL from your browser")
return_value=$?
if [ "$return_value" -ne "0" ]; then exit 1; fi

# What working name to give our pages

NAME=$($ZENITY --entry --title="Title?" --text="Please enter your title")
return_value=$?
if [ "$return_value" -ne "0" ]; then exit 1; fi
FILE="${DIR}/${NAME}.html"
CLEAN="${DIR}/${NAME}.clean.html"
WIKI="${DIR}/${NAME}.wiki"

# Download

$WGET "${URL}" -O "${FILE}"
return_value=$?
if [ "$return_value" -ne "0" ]; then echo -e '\e[0;31m' "Download Failed"; exit 1; fi

# Clean up the raw html and then convert the clean html

# GREP -v '(Code|Quote):' removes the "Code:" and "Quote:" divisions
$AWK '/-- message --/ {n++}; /-- \/ message --/ {n++} ;{if (n == 1) {print}}; {if ( n > 1 ) {exit}}' "${FILE}" | $GREP -v '(Code|Quote):' > "${CLEAN}"
return_value=$?
if [ "$return_value" -ne "0" ]; then echo -e '\e[0;31m' "Cleanup Failed"; exit 1; fi

# Add wiki page header
$CAT <<EOF>"${WIKI}"
## <<Include(Tag/ContentCleanup)>>
## <<Include(Tag/StyleCleanup)>>
## <<Include(Tag/NeedsExpansion)>>
||<tablestyle=\"float:right\; font-size:0.9em\; width:40%\; background:#F1F1ED\; margin: 0 0 1em 1em\;\" style=\"padding:0.5em\;\"><<TableOfContents>>||

EOF


# Convert
# The forums use [[BR]] for page breaks, the sed statement converts them to new lines
# The second sed http[s]: ... formats wiki links

$CONVERT "${CLEAN}" |  $SED -e 's|\[\[BR\]\]|\n|g' | $SED -e 's/\(\[http[s]*:\S*\)\(.*\]\)\(.*\)/\[\1|\2\]\3 /g' >> "${WIKI}"
return_value=$?
if [ "$return_value" -ne "0" ]; then echo -e '\e[0;31m' "Conversion Failed"; exit 1; fi

# Review the document
$EDIT "${WIKI}"
return_value=$?
if [ "$return_value" -ne "0" ]; then echo -e '\e[0;31m' "Opening document with your editor failed"; exit 1; fi

Save this as /usr/local/bin/ubforums2ubwiki.sh

or

~/bin/ubforums2ubwiki.sh

Make it executable

sudo chmod a+x /usr/local/bin/ubforums2ubwiki.sh

Run the tool

ubforums2ubwiki.sh

or create a desktop launcher. An image to be used as an icon can be found at https://launchpadlibrarian.net/101180651/logo64.png

https://launchpadlibrarian.net/101180651/logo64.png

Running the tool will cause an entry box to show - paste in the URL for the first post of the tutorial you wish to convert. Followed when prompted by name for the new wiki - do not use spaces in the name.

url.png

title.png

Once the tool has run - a text editor window will open with the text, you can copy this for use in the wiki creation.

attachment:gedit.png

You can either create a new page by directly entering it's name, if it does not exist you will be prompted to create the new page.

Please make sure to not have spaces in the name you choose.

Alternatively you can use the Page Creation macro to do so.

Once you have the new page, paste in the text from your new foo.txt.new file, check for any further editing and when happy save changes. You can if you wish preview the page before saving.

attachment:wikidone.png

Other Options


If you would like to just drop some links that you think are nice. You may do it at this page HERE and others will convert for you.

ForumWikiTeam/ImportTool (last edited 2012-09-11 20:31:26 by mail)