script to port old mysql pi logs to django models
This commit is contained in:
parent
4d374b6c45
commit
e1a8a94eba
32
scripts/port_pi_to_django.py
Normal file
32
scripts/port_pi_to_django.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from ConfigParser import ConfigParser, NoOptionError
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from pi.models import PiLog
|
||||||
|
|
||||||
|
import MySQLdb as mdb
|
||||||
|
|
||||||
|
config_file = 'dr.botzo.cfg'
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read(os.path.expanduser(config_file))
|
||||||
|
|
||||||
|
dbhost = config.get('dr.botzo', 'dbhost')
|
||||||
|
dbuser = config.get('dr.botzo', 'dbuser')
|
||||||
|
dbpass = config.get('dr.botzo', 'dbpass')
|
||||||
|
dbname = config.get('dr.botzo', 'dbname')
|
||||||
|
|
||||||
|
db = mdb.connect(dbhost, dbuser, dbpass, dbname, charset='utf8', use_unicode=True)
|
||||||
|
try:
|
||||||
|
cur = db.cursor()
|
||||||
|
query = '''
|
||||||
|
SELECT * FROM pi_log
|
||||||
|
'''
|
||||||
|
cur.execute(query)
|
||||||
|
for row in cur.fetchall():
|
||||||
|
count_inside = row[1]
|
||||||
|
count_total = row[2]
|
||||||
|
pi_log = PiLog.objects.create(count_inside=count_inside, count_total=count_total)
|
||||||
|
except NoOptionError as noe:
|
||||||
|
sys.exit("Aborted due to error in config: {0:s}".format(str(noe)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user