일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- License
- zip 파일 암호화
- token filter test
- 차트
- sort
- licence delete curl
- Elasticsearch
- docker
- API
- aggregation
- matplotlib
- 파이썬
- analyzer test
- 900gle
- license delete
- Python
- zip 암호화
- Test
- query
- aggs
- plugin
- Mac
- TensorFlow
- ELASTIC
- Java
- flask
- Kafka
- high level client
- MySQL
- springboot
Archives
- Today
- Total
개발잡부
[python] csv 파일 읽어서 sql insert 문 생성 본문
반응형
LOAD DATA LOCAL INFILE 로 넣으려고 했으나
1. local_infile 옵션을 수정할 수 가 없다 .
2. vdesk 를 통해서 파일을 옮기니 한글이 깨진다.
그래서 sql 문을 만들어서 컨트롤 씨부이를 해야겠다 .
재활용 파일
# -*- coding: utf-8 -*-
import time
import json
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
import tensorflow_hub as hub
import tensorflow_text
import kss, numpy
##### INDEXING #####
def csv_data():
f_v = open("stopword_prd.sql",'w')
f_a = open("attribute_prd.sql",'w')
count= 71166300;
with open(CSV_FILE) as data_file:
for line in data_file:
line = line.strip()
lineArray = line.split(',')
sql_v = "INSERT INTO `search`.tb_dic_vocabulary (word_id, word_name, sense_tag, reg_date, note, use_flag, stop_flag, reg_userid, mod_userid, mod_date) VALUES("+str(count)+" , '"+lineArray[1]+"', '000000', now(), '', '1', '1', '2022100206', '2022100206', now());\n"
sql_a = "INSERT INTO `search`.tb_dic_attribute (word_id, dict_type, pos, noun_attr, verb_attr, ne_type, `domain`, origin_language, dont_split_comp, is_general) VALUES ("+str(count)+", 'TOTAL', 'NOUN', '', 'X', '', '', '', 0, 'N');\n"
f_v.write(sql_v)
f_a.write(sql_a)
print(sql_v)
count += 100
f_v.close()
f_a.close()
print("Done sql.")
#INSERT INTO `search`.tb_dic_vocabulrary_test (word_id, word_name, sense_tag, reg_date, note, use_flag, stop_flag, reg_userid, mod_userid, mod_date) VALUES(0, '', '0', CURRENT_TIMESTAMP, '', '1', '0', '', '', '');
#INSERT INTO `search`.tb_dic_attribute_test (word_id, dict_type, pos, noun_attr, verb_attr, ne_type, `domain`, origin_language, dont_split_comp, is_general) VALUES (0, '', 'NOUN', '', 'X', '', '', '', 0, 'N');
##### MAIN SCRIPT #####
if __name__ == '__main__':
CSV_FILE = "./data/products/stopword0525.csv"
csv_data()
print("Done.")
반응형
'Python' 카테고리의 다른 글
[python] numpy upgrade (0) | 2022.06.21 |
---|---|
[python] 설치된 Package 확인 (0) | 2022.06.20 |
[python] 검색어 확인 (0) | 2022.05.26 |
SSL 어쩌고 해서 .. (0) | 2022.05.26 |
Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings (0) | 2022.05.26 |
Comments