Convert from STRS Email to CSV file for Import into eRoom Database
Usage
The Email2CSV script is used to create a comma-separated value (CSV) file for import into eRoom database. The input data is obtained from an eMail created by a web page using FormMail when the submit button is clicked. The CSV file provides a simple and consistent means of copying contents into an eRoom database without copying and pasting.
Setup
- Install Python. See Python download site. The script was tested against Python 2.7 and Python 3.2. Since there were residual errors when handling special characters in Python 2.7, it is recommended that the user install and use Python 3.2 or above.
- Create/find a working directory to store scripts and execution results for upload and download.
- Save the Email2CSV.python.txt script (from eRoom) into that working directory.
- Save the FormMail email, as UTF-8 (or Unicode) text, with the name identified on the line containing “Suggest_File_Name:”, into the working directory identified.
Convert
- Run the Email2CSV procedure/script as described below. The usage is:
usage: Email2CSV.python.txt [-h] [-c [CSVFILE]] [-s SUBDIRECTORY] fileIn Convert a form from email saved as text into a CSV file for import. positional arguments: fileIn Path to file to be analyzed. optional arguments: -h, --help show this help message and exit -c [CSVFILE], --csv [CSVFILE] CSV output file name. Add ".csv", if ".csv" is not there. STRS.type.Metadata.date.csv is used if no file name is specified, where type may be public, restricted, historical, etc.. -s SUBDIRECTORY, --subdirectory SUBDIRECTORY Subdirectory to output web page or CSV file.
- In a PC command window, execute python script Email2CSV.python.txt with input being the file just saved and the output being a new file; for example:
cd C:path\SoftwareDefinedRadio\STRS Repository
C:\python27\python Email2CSV.python.txt “strs-repository-manager STRS Application Repository PublicMetadata.txt”
or
C:\python32\python Email2CSV.python.txt “strs-repository-manager STRS Application Repository PublicMetadata.txt” - In a Linux command window, execute python script Email2CSV.python.txt with input being the file just saved and the output being a new file; for example:
cd $HOME/strs/20120207
python Email2CSV.python.txt “strs-repository-manager STRS Application Repository PublicMetadata.txt”
or
python27 Email2CSV.python.txt “strs-repository-manager STRS Application Repository PublicMetadata.txt”
or
python32 Email2CSV.python.txt “strs-repository-manager STRS Application Repository PublicMetadata.txt” - Note that the Email2CSV procedure/script has only been tested using “Python 2.7.3” and “Python 3.2.3”. If you have an older version, it may not work. To determine which version of python you are using, type python (or equivalent) on a command line. It will return the version in an interactive mode. To exit, type “exit()” or “quit()” or Ctrl-Z plus Return.
- Note that if you install python, python must be started so that it can find the corresponding python-related files. On Linux, for example, the PATH variable needed to be changed and the easiest way to do this was to create a Bourne shell script. For example, to execute python in $HOME/python-2.7.3, I created $HOME/bin/python27 (where $HOME/bin is already in the PATH variable) containing:
#!/bin/sh # python27 ... PATH=$HOME/Python-2.7.3:$PATH python $*
Then I made $HOME/bin/python27 executable (chmod +x $HOME/bin/python27) and executed the following, after reinitializing the command window shell:
; python27 Email2CSV.python.txt -c output.csv input.txt
which worked fine.
- In a PC command window, execute python script Email2CSV.python.txt with input being the file just saved and the output being a new file; for example:
- Check the resulting CSV file in an editor to verify that it matches the original eRoom database.
- Import the resulting comma-separated value (CSV) file to the appropriate STRS application repository metadata eRoom database.
- Click Import at the bottom of the eRoom database and the following window will appear:
- Click on Browse and select the CSV file just created.
- Then click on OK.
- Click Import at the bottom of the eRoom database and the following window will appear: