Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think that a better option than "marking" the CSV file is to keep a file were you store the number of the last line you processed.</p> <p>So if the file does not exist (the one were you store the number of the last processed line), you process the whole CSV file. If this file exists you only process records after this line.</p> <p>Final Code On Working System:</p> <pre><code>#!/usr/bin/python import csv import MySQLdb import os mydb = MySQLdb.connect(host='localhost', user='root', passwd='*******', db='kestrel_keep') cursor = mydb.cursor() csv_data = csv.reader(file('data_csv.log')) start_row = 0 def getSize(fileobject): fileobject.seek(0,2) # move the cursor to the end of the file size = fileobject.tell() return size file = open('data_csv.log', 'rb') curr_file_size = getSize(file) # Get the last file Size if os.path.exists("file_size"): with open("file_size") as f: saved_file_size = int(f.read()) # Get the last processed line if os.path.exists("lastline"): with open("lastline") as f: start_row = int(f.read()) if curr_file_size &lt; saved_file_size: start_row = 0 cur_row = 0 for row in csv_data: if cur_row &gt;= start_row: cursor.execute('INSERT INTO `heating` VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s ,%s)', row) # Other processing if necessary cur_row += 1 mydb.commit() cursor.close() # Store the last processed line with open("lastline", 'w') as f: start_line = f.write(str(cur_row + 1)) # you want to start at the **next** line # next time # Store Current File Size To Find File Flush with open("file_size", 'w') as f: start_line = f.write(str(curr_file_size)) # not necessary but good for debug print (str(cur_row)) print "Done" </code></pre> <p><strong>Edit:</strong> Final Code Submited by ZeroG and now working on the system!! Thank You also Too Xion345 For Helping</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload