#!/usr/bin/env python
from __future__ import print_function
import pymysql.cursors
Journal=open('J_15April.txt')
jrn=Journal.read()
Zeile=jrn.split('14.04.2015')
conn = pymysql.connect(host='localhost', port=3306, user='root',passwd='',db='daten', cursorclass=pymysql.cursors.DictCursor)
ean = int(row[0])
smr = char(row[1])
uhrzeit = char(row[2])
for line in Zeile:
cur = conn.cursor()
if 'BOTTLE_ID' in line
line2 = line.split(';')
line3 = line2[0].strip(' BOTTLE_UNIQUE: BOTTLE_ID: 0')
uhrzeit = (line3[:-4])
if 'EAN' not in line:
ean = 0
else:
ean = line2[7].strip('EAN: ')
if ' SMR: 1;' in line:
smr = ('gelesen')
else:
smr = ('nicht gelesen')
cur.execute("INSERT INTO lga (ean, smr, uhrzeit) VALUES ('%s','%s','%s')%(ean, smr, uhrzeit)")
cur.fetchall()
cur.close()
conn.commit()
conn.close()
Hi guys,
im currently trying to put a lot of data into a mysqldb. I wrote two seperate programms, one is for filtering the important stuff out of a very long .txt and the other one inserts them in the database.
The actual problem now occured when i tried combine those two programm to automatically read and insert the data. I think the structure of the shown programm my be a little chaotic and thats the main reason why it is not working. Im absolutely new to python and it was quite hard for me two make the two other programms work so please help me out.
If you are interested in the two single functions i can post them as well.
greetings
trbo
Aucun commentaire:
Enregistrer un commentaire