text stringlengths 0 828 |
|---|
df = pd.DataFrame(dictList) |
df.replace(['nan', 'None', '', 'NaN', np.nan], '\\N', inplace=True) |
df.to_csv('/tmp/%(tmpTable)s' % locals(), sep=""|"", |
index=False, escapechar=""\\"", quotechar='""', columns=csvColumns, encoding='utf-8') |
sqlQuery = """"""LOAD DATA LOCAL INFILE '/tmp/%(tmpTable)s' |
INTO TABLE %(tmpTable)s |
FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '""' |
IGNORE 1 LINES |
(%(csvColumnsString)s);"""""" % locals() |
writequery( |
log=log, |
sqlQuery=sqlQuery, |
dbConn=dbConn |
) |
updateStatement = """" |
for i in csvColumns: |
updateStatement += ""`%(i)s` = VALUES(`%(i)s`), "" % locals() |
if dateModified: |
updateStatement += ""dateLastModified = NOW(), updated = 1"" |
else: |
updateStatement = updateStatement[0:-2] |
sqlQuery = """""" |
INSERT IGNORE INTO %(dbTablename)s |
SELECT * FROM %(tmpTable)s |
ON DUPLICATE KEY UPDATE %(updateStatement)s;"""""" % locals() |
writequery( |
log=log, |
sqlQuery=sqlQuery, |
dbConn=dbConn |
) |
sqlQuery = """"""DROP TEMPORARY TABLE %(tmpTable)s;"""""" % locals() |
writequery( |
log=log, |
sqlQuery=sqlQuery, |
dbConn=dbConn |
) |
try: |
os.remove('/tmp/%(tmpTable)s' % locals()) |
except: |
pass |
log.debug( |
'completed the ``_add_dictlist_to_database_via_load_in_file`` function') |
return None" |
3978,"def make_directory(path): |
"""""" Create directory if that not exists. """""" |
try: |
makedirs(path) |
logging.debug('Directory created: {0}'.format(path)) |
except OSError as e: |
if e.errno != errno.EEXIST: |
raise" |
3979,"def copy_file(self, from_path, to_path): |
"""""" Copy file. """""" |
if not op.exists(op.dirname(to_path)): |
self.make_directory(op.dirname(to_path)) |
shutil.copy(from_path, to_path) |
logging.debug('File copied: {0}'.format(to_path))" |
3980,"def params(self): |
"""""" Read self params from configuration. """""" |
parser = JinjaInterpolationNamespace() |
parser.read(self.configuration) |
return dict(parser['params'] or {})" |
3981,"def scan(cls, path): |
"""""" Scan directory for templates. """""" |
result = [] |
try: |
for _p in listdir(path): |
try: |
result.append(Template(_p, op.join(path, _p))) |
except ValueError: |
continue |
except OSError: |
pass |
return result" |
3982,"def copy(self): |
"""""" Prepare and paste self templates. """""" |
templates = self.prepare_templates() |
if self.params.interactive: |
keys = list(self.parser.default) |
for key in keys: |
if key.startswith('_'): |
continue |
prompt = ""{0} (default is \""{1}\"")? "".format( |
key, self.parser.default[key]) |
if _compat.PY2: |
value = raw_input(prompt.encode('utf-8')).decode('utf-8') |
else: |
value = input(prompt.encode('utf-8')) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.