![]() |
![]() |
#1 |
May 2004
Oslo, Norway
23×3×5 Posts |
![]()
I'm dabbling with a small MySQL database that stores my finished exponents. A Python script gets the cleared exponent from the Individual report, and then does some munging to get the data into a MySQL insert command. I won't post the entire code here at the moment, but if anyone is interested, I just might do it in a while
![]() Now, to convert the date from GIMPS format ("21-Jan-05 10:43") to MySQL format ("2005-01-21 10:43:00") I found that Python has excellent built-in functionality to do so. The documentation is found online at http://docs.python.org/lib/module-time.html: Code:
from time import strptime, strftime def convertDate(mystring): mytimeobj = strptime(mystring, "%d-%b-%y %H:%M") return strftime("%Y-%m-%d %H:%M:00", mytimeobj) ![]() regards, Leif. |
![]() |
![]() |
![]() |
#2 | |
Banned
"Luigi"
Aug 2002
Team Italia
481110 Posts |
![]() Quote:
![]() Luigi |
|
![]() |
![]() |
![]() |
#3 | |
May 2004
Oslo, Norway
23·3·5 Posts |
![]() Quote:
Code:
#! /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. # assign.py 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 - \ http://mersenne.org/cgi-bin/primenet_report.pl\?UserID=xxx&userPW=yyy \ | grep ' + exp child = os.popen(command) data = child.read() return data def convertDate(mystring): # converts from GIMPS date format into MySQL date format. # RTFM at http://docs.python.org/lib/module-time.html 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." sys.exit(1) else: 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)) myConnection.close() 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. |
|
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Conversion GHz to GFLOPS? | preda | PrimeNet | 11 | 2017-12-02 21:51 |
v5 Server Conversion | compusion | Software | 3 | 2008-11-14 19:22 |
PS3 programmers(program conversion for pay?) | jasong | Programming | 5 | 2007-12-16 00:10 |
Units Conversion Puzzle | JHagerson | Lounge | 19 | 2005-11-24 05:38 |
conversion to GF(2) | bigbud | Math | 9 | 2005-04-16 01:13 |