scocodes1.py

This is a python script that surveys the $scohtm/index.html file and pulls out the recognized task names. It is probably over-written, but was really an early attempt at writing a python code that uses functions to slice and recognize substrings in lines of text. Hence, I show a sample below on a portion of my index.html file, and then I show the complete python code. The output values: code_name and code_type can be directed to a file, which in turn might be fed to a shell script for further processing. For intsance, one of the prime motivations was writing a script that would insure that that all of the python codes present in my $scohtm listing do, in fact, have executables present on the machine being used. With the output from scocodes1.py I can easily tabulae my python codes, and then build/run a script to insure that they will run.

 

% scocodes1.py T2  
Name Source
2mass_00.py python
2mass02 bash
boxpix otw
calstats.py python
XYP lmgf

% cat T2 
<html> <BODY bgcolor=#ffffff> <table> <br> <br> <center> <table border=2 class="boldtable"> <tr> <td align="left"> Name </td> <td align="left"> Source </td> <td align="left"> Task (Link) </td> <td align="left"> Extra Comments </td> </tr> <tr> <td align="left"> 2mass_00.py </td> <td align="left"> python </td> <td align="left"> <a href="./2mass_00.py/index.html">Process a 2MASS catalog. </td> <td align="left"> Creates a cdfp file.</td> </tr> <tr> <td align="left"> 2mass02 </td> <td align="left"> bash </td> <td align="left"> <a href="./2mass02/index.html">Query 2MASS PSC </td> <td align="left"> Output to 2mass.cat. </td> </tr> <tr> <td align="left"> boxpix </td> <td align="left"> otw </td> <td align="left"> <a href="./boxpix/index.html">Write image pixels in a box </td> <td align="left"> O2SO </td> </tr> <tr> <td align="left"> calstats.py </td> <td align="left"> python </td> <td align="left"> <a href="./calstats.py/index.html">Compute simple statistics. </td> <td align="left"> O2SO </td> </tr> <tr> <td align="left"> XYP </td> <td align="left"> lmgf </td> <td align="left"> <a href="./xyp/index.html"> Interactively plot XY data. </td> <td align="left"> Uses ASCII tables for input </td> </tr> </font> </table> </center>

Notice that this code has not been refined. I must have white-space around the code names in order for them to be properly recognized. For example, the first line below will work properly, but the second will NOT:

<td align="left"> calstats.py </td> <td align="left">calstats.py </td> Also, the table row that has the column names is recognized as a valid task set. Things like this can be patched and cleaned up, but I wanted to record this early version because it (for the most part) works, and the code is fairly easy to follow.
 


#!/usr/bin/python

def line_look_00(words):
  nn = len(words)
  return nn

def line_look_trSTART(line):
  start = line.find('') 
  return start

def line_look_trEND(line):
  start = line.find('') 
  return start

def getit_codename(line):
  words = line.split(' ') 
  mytask = words[2] 
  return mytask 


# Read and use a scocodes html file (Table) of codes 
# Setup to read the name of the input file 
from sys import argv
script_name, scocodefile = argv

# Read the ENTIRE file into lines
# Open the files for read-only
fall = open(scocodefile,'r')
lines = fall.readlines()
fall.close()
nlines = len(lines) 

# scan each line and do things 
ii = 0
trs=[]
tre=[]
for line in lines:
    ii=ii+1
    words = line.split() 
# Use a function to count number of words  
    number_of_words = line_look_00(words)

# count the "" occurences 
    numtr = line_look_trSTART(line)
    trs.append(numtr)

    numte = line_look_trEND(line)
    tre.append(numte)

############################################################
# loop through the trs,tre arrays to see how many 
# sets of  and  were present 
ii = 0
while True:
 if ii < nlines:
  numostart = trs[ii]
 else:
  break
 ii=ii+1
############################################################

nstarts = 0 
startline=[]
ii = 0
while True:
 if ii < nlines-5:
  if (trs[ii]==0) and (tre[ii+5]==0):
    nstarts=nstarts+1
    startline.append(ii)
 else:
  break
 ii=ii+1

ii = 0
while True:
 if ii < nstarts:
    iw = startline[ii] + 1
    task_name = getit_codename(lines[iw])
    task_type = getit_codename(lines[iw+1])
    print "%s %s" % (task_name,task_type) 
 else:
  break
 ii=ii+1

Some more advanced versions of this code will be developed to help maintain my code table(s), but the basics are here.




Back to SCO CODES page