@@ -361,12 +361,19 @@ def clean_doi(doi):
361361 METADATA .iloc [x ][_worker + 'LastName' ].strip (),
362362 METADATA .iloc [x ][_worker + 'FirstName' ].strip ()))
363363 workerID = cursor .fetchall ()[0 ][0 ]
364+ # test if the workerID is already registered
364365 cursor .execute (
365- "INSERT INTO metaworker (sampleName, workerID, workerRole) "
366- "VALUES (%s, %d, %s)" % (
367- is_null_str (METADATA .iloc [x ]['SampleName' ]), workerID ,
368- is_null_str (METADATA .iloc [x ][_worker + 'Role' ])))
369- conn .commit ()
366+ ("SELECT * FROM metaworker WHERE samplename=%s AND "
367+ "workerid=%s" ) % (is_null_str (METADATA .iloc [x ]['SampleName' ]),
368+ workerID ))
369+ res = cursor .fetchall ()
370+ if len (res ) == 0 :
371+ cursor .execute (
372+ "INSERT INTO metaworker (sampleName, workerID, workerRole) "
373+ "VALUES (%s, %d, %s)" % (
374+ is_null_str (METADATA .iloc [x ]['SampleName' ]), workerID ,
375+ is_null_str (METADATA .iloc [x ][_worker + 'Role' ])))
376+ conn .commit ()
370377 for i in '1234' :
371378 _pub = 'Publication' + i
372379 _doi = 'DOI' + i
@@ -377,11 +384,18 @@ def clean_doi(doi):
377384 is_null_str (METADATA .iloc [x ][_pub ]),
378385 clean_doi (METADATA .iloc [x ][_doi ])))
379386 publiID = cursor .fetchall ()[0 ][0 ]
387+ # test if the publiID is already registered
380388 cursor .execute (
381- "INSERT INTO metapubli (sampleName, publiID) VALUES "
382- "(%s, %d)" % (is_null_str (METADATA .iloc [x ]['SampleName' ]),
383- publiID ))
384- conn .commit ()
389+ ("SELECT * FROM metapubli WHERE samplename=%s AND "
390+ "publiID=%s" ) % (is_null_str (METADATA .iloc [x ]['SampleName' ]),
391+ publiID ))
392+ res = cursor .fetchall ()
393+ if len (res ) == 0 :
394+ cursor .execute (
395+ "INSERT INTO metapubli (sampleName, publiID) VALUES "
396+ "(%s, %d)" % (is_null_str (METADATA .iloc [x ]['SampleName' ]),
397+ publiID ))
398+ conn .commit ()
385399
386400cursor .execute ("SELECT MAX(var_) FROM p_vars" )
387401res = cursor .fetchall ()
0 commit comments