View Single Post
Old 2005-01-26, 23:00   #3
leifbk's Avatar
May 2004
Oslo, Norway

12010 Posts

Originally Posted by ET_
Could you zip and PM that code to me pls?

What do you need, -- the entire data definition, or just the input script? The latter isn't bigger than I just post it right here:

#! /usr/bin/env python

# ll_return, leifbk 2005
# purpose: Insert finished exponent from GIMPS into MySQL database.
# this program fetches parameters directly from server with wget, and
# turns them into MySQL-readable data.

# All you have to enter is the exponent number as a parameter. This should of
# course exist in the Cleared Exponents sections of the Individual Report, or
# the effect of this script will be totally unpredictable. Compare with eg.
# for an assessment of the improvement in automation level.

# this first version is very crude and has no error handling at all. Use at own risk.

import os, sys, MySQLdb
from time import strptime, strftime
from p90 import calc_p90

def wgetline(exp):  # see Python Cookbook p. 228
    str(exp)        # just to ensure that exp _is_ a string
    print "Getting exponent from server ..."
    command = 'wget -q -O - \\?UserID=xxx&userPW=yyy \
        | grep ' + exp
    child = os.popen(command)
    data =
    return data

def convertDate(mystring): # converts from GIMPS date format into MySQL date format.
    # RTFM at
    mytimeobj = strptime(mystring, "%d-%b-%y %H:%M")
    return strftime("%Y-%m-%d %H:%M:00", mytimeobj)

def getcid(computername):
    myCursor = myConnection.cursor()
    myCursor.execute("select computer_id from computers \
                        where computer_name like %s", computername)
    row = myCursor.fetchone()
    return str(row[0])

if __name__ == '__main__':
    # open db
    myConnection = MySQLdb.connect(user="xxx", passwd="yyy", db="gimps")

    myline = wgetline(sys.argv[1])
    print myline
#   22788427  68     0x630FB7626E0591__                03-Jan-05 06:09  brutalis
    exp = myline[0:8]
    bts = myline[10:12]
    typ = myline[14]
    if typ == ' ': typ = '1'            # LL test
    elif typ == 'D': typ = '2'          # DC test
    res = myline[17:35]
    dtr = convertDate(myline[51:66])
    cid = getcid(myline[68:76])
    p90 = str(calc_p90(int(exp)))

    print "Exponent = " + exp
    print "Bits     = " + bts
    print "Type     = " + typ
    print "Residual = " + res
    print "Returned = " + dtr
    print "Computer = " + cid
    print "P-90 yrs = " + p90

    inp = raw_input("Is this information correct (y/n) ? ")
    if inp in ("n", "N"):
        print "Entry aborted."
        print "Adding exponent to database ..."
        myCursor = myConnection.cursor()
        myCursor.execute("insert into ll_test (exponent, bits, test_type, \
                            residual, finished, computer_id, on_line, p90_years) \
                            values (%s, %s, %s, %s, %s, %s, %s, %s)", \
                            (exp, bts, typ, res, dtr, cid, 1, p90))
The part in "main" that extracts the fields should really be put in its own module, as it's quite useful and probably needed elsewhere.

The column "on_line" in the ll_test table is a "logical" field containing either 0 or 1 depending on the exponent's PrimeNet status. For the first months I used manual assignment and return for one of my computers, that's why I created this field. Nowadays, it' always 1 for new exponents.

HTH, Leif.
leifbk is offline   Reply With Quote