Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- PID4
- PHP4
- CenOS6.10
- 에디트플러스 #sftp안될때
- 코드라마 #AI
- CapsLock키보드 뽑기
- ubunto #네티워크설정
- 인터넷안되는문제해결
- windows19Server
- 조성남
- utf8mb4
- root직접로그인
- php7
- 신바람여비서win98
- centos7
- IT제어
- MSSQL #TCP/IP Enabled
- putty
- 아이티제어
- 윈도우앱지우기
- 한글2 #hangul2_from_2024_01_17
- ftp
- winscp
- sftp
Archives
- Today
- Total
아이티제어
파이이선 python3 -f /filepaht/filename -d DbName 같이 업션읽기 본문
Linux/우분투Ubuntu
파이이선 python3 -f /filepaht/filename -d DbName 같이 업션읽기
프로그래머 파이브010-2629-0471 2023. 2. 19. 21:03import sys
import getopt
def main(argv):
inputfile = ''
dbname = ''
try:
opts, args = getopt.getopt(argv,"hf:d:",["file=","dbname="])
except getopt.GetoptError:
print('_xlsx.py -f <inputfile> -d <dbname>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('_xlsx.py -f <inputfile> -d <dbname>')
sys.exit()
elif opt in ("-f", "--file"):
inputfile = arg
elif opt in ("-d", "--dbname"):
dbname = arg
print('Input file is ', inputfile)
print('DB name is ', dbname)
if __name__ == "__main__":
main(sys.argv[1:])
#!/usr/bin/env python3
# <?php echo "PHP는정상". __FILE__; /* PHP주석시작
#?>
import mysql.connector
import pandas as pd
import sys
# Connect to the database
conn = mysql.connector.connect(
host='localhost',
user='root',
password='apmsetup',
database='mydb'
)
cursor = conn.cursor()
table_name = "vkdlf기"
df = pd.read_excel('C:\\Users\\yjm91\\aaa\\koex\\{}.xlsx'.format(table_name), sheet_name=0)
# Create the table with columns
columns = ', '.join(['`{}` varchar(100) not null default \'\' '.format(col) for col in df.columns])
create_table_query = 'CREATE TABLE if not exists `{}` (idx int(11) AUTO_INCREMENT PRIMARY KEY, {}) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;'.format(table_name, columns)
print(create_table_query)
cursor.execute(create_table_query)
result = cursor.fetchall()
print("Cre reult=",result)
cursor.execute("truncate {}".format(table_name) )
colIns = ', '.join(['`{}` '.format(col) for col in df.columns])
# Use for loop to insert values into the table for each row
for index, row in df.iterrows():
''' nan표시문제.
#insert_query = 'INSERT INTO `{}` ({}) VALUES ({})'.format(
# table_name,
# ', '.join(df.columns),
# ', '.join(['\'{}\''.format(row[col]) for col in df.columns])
)
'''
values = ', '.join([f"'{str(value).replace('nan', '')}'" for value in row.values])
sql = f"INSERT INTO `{table_name}` ({colIns}) VALUES ({values});"
#print(sql)
cursor.execute(sql)
result = cursor.fetchall()
print("Ins reult=",result)
# Commit the changes
conn.commit()
result = cursor.fetchall()
print("Ins reultㄸ=",result)
# Close the cursor and connection
cursor.close()
conn.close()
# php로 실행시에도 소스 유출방지.
# 여기서PHP주석끝 <?php */ ?>
'Linux > 우분투Ubuntu' 카테고리의 다른 글
sudo 명렁어 안되면 (0) | 2023.03.02 |
---|---|
파이선 프로그램 python3 aa.py 서비스등 록하기 (0) | 2023.02.26 |
우분투 iptable 등이 system 시작시 자동 실행 되게 하기 (0) | 2023.02.14 |
두대의 리눅스에서 tcp패킷을 그대로 다른 컴퓨터에 다른 포트로 전달해주는 기능 구현방법 (0) | 2023.02.14 |
우분투 22 화면 둘러보기 (0) | 2022.08.15 |