How to use str_insert method in localstack

Best Python code snippet using localstack_python

db_load.py

Source:db_load.py Github

copy

Full Screen

1import os2import csv3import sqlite34conn_db = sqlite3.connect('../db/antaq.db')5cursor_db = conn_db.cursor()6path_to_load = os.getcwd() + '../data/to_load'7base_to_load = path_to_load +'../data/base'8years_to_load = path_to_load + '../data/years.txt'9# loading base10for csvfiles_to_load in os.listdir(base_to_load):11 row_count = 012 ext_pos = csvfiles_to_load.find('.')13 csvfiles_to_load_path = base_to_load + '/' + csvfiles_to_load14 print(f'Loading {csvfiles_to_load_path}...')15 with open(csvfiles_to_load_path) as csvfile_to_load:16 csvreader_file_to_load = csv.reader(csvfile_to_load, delimiter=';')17 csvreader_file_to_load.__next__()18 for csvfile_to_load_row in csvreader_file_to_load:19 col_count = 020 str_insert = 'insert into ' + csvfiles_to_load[:ext_pos] + ' values ( '21 for col in csvfile_to_load_row:22 str_insert = str_insert + '\'' + col.replace('\'','') + '\''23 if col_count < len(csvfile_to_load_row)-1:24 str_insert = str_insert + ', '25 col_count += 126 str_insert = str_insert + ');'27 cursor_db.execute(str_insert)28 row_count += 129 if row_count % 10000 == 0:30 print(f'\t{row_count} rows inserted ... commit!')31 conn_db.commit()32 conn_db.commit()33 print(f'Total rows of {csvfiles_to_load_path}: {row_count}')34# loading years35with open(years_to_load) as csvyears:36 csvreader_years = csv.reader(csvyears, delimiter=';')37 csvreader_years.__next__()38 for csvyears_row in csvreader_years:39 for csvfiles_to_load in os.listdir(path_to_load + '/' + csvyears_row[0]):40 csvfiles_to_load_path = path_to_load + '/' + csvyears_row[0] + '/' + csvfiles_to_load41 with open(csvfiles_to_load_path) as csvfile_to_load:42 row_count = 043 ext_pos = csvfiles_to_load.find('.')44 csvreader_file_to_load = csv.reader(csvfile_to_load, delimiter=';')45 46 csvreader_file_to_load.__next__()47 for csvfile_to_load_row in csvreader_file_to_load:48 col_count = 049 str_insert = 'insert into ' + csvfiles_to_load[:ext_pos] + ' values ( '50 for col in csvfile_to_load_row:51 str_insert = str_insert + '\'' + col.replace('\'','') + '\''52 if col_count < len(csvfile_to_load_row)-1:53 str_insert = str_insert + ', '54 col_count += 155 str_insert = str_insert + ');'56 cursor_db.execute(str_insert)57 row_count += 158 if row_count % 10000 == 0:59 print(f'\t{row_count} rows inserted ... commit!')60 conn_db.commit()61 conn_db.commit()62 print(f'Total rows of {csvfiles_to_load_path}: {row_count}')...

Full Screen

Full Screen

get_stock_code.py

Source:get_stock_code.py Github

copy

Full Screen

2'''3获取符合格式要求的股票池的股票代码序列:4沪深300指数成分股和中证800指数成分股5'''6def str_insert(str1, char, index):7 x = list(str1)8 x.insert(index, char)9 str2 = "".join(x)10 return str211def str_pop(str1, index=-1):12 x = list(str1)13 y = x.pop(index)14 str2 = "".join(x)15 return str216def get_hs_300():17 data_df = pd.read_csv('../data/hs_300.csv', index_col=None, encoding='utf-8')18 code = list(data_df['沪深300成分股'])19 for i in range(300):20 code[i] = code[i].replace('.', '')21 if code[i][7] == 'Z':22 code[i] = str_insert(code[i], 'Z', 0)23 code[i] = str_insert(code[i], 'S', 0)24 if code[i][7] == 'H':25 code[i] = str_insert(code[i], 'H', 0)26 code[i] = str_insert(code[i], 'S', 0)27 code[i] = str_pop(code[i], -1)28 code[i] = str_pop(code[i], -1)29 return code30def get_zz_800():31 data_df = pd.read_csv('../data/zz_800.csv', index_col=None, encoding='utf-8')32 code = list(data_df['成分券代码Constituent Code'])33 for i in range(len(code)):34 code[i] = str(code[i])35 if len(code[i]) == 6:36 if code[i][0] == '6':37 code[i] = str_insert(code[i], 'SH', 0)38 elif code[i][0] == '3':39 code[i] = str_insert(code[i], 'SZ', 0)40 else:41 while len(code[i]) < 6:42 code[i] = str_insert(code[i], '0', 0)43 code[i] = str_insert(code[i], 'SZ', 0)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful