Python ile .txt'deki yazilari .db veya mysql insert'lemek.

SekoMirson

Kayıtlı Kullanıcı
Katılım
7 Şub 2023
Mesajlar
3
Tepkime puanı
0
Puanları
1
Ornek : .txt metinimiz
Name,Surname,Gender,Address,Mail,Date,City,Salary,WorkPlace,,
Ina,Jackson,Man,"P.O. Box 257, 5339 Risus St.",[email protected],10.10.21,Insaatcilar,$589.00,Et Magna Ltd,,
Rose,Nieves,Female,Ap #647-7299 Nulla. Avenue,[email protected],11.10.21,Elmler,$916.00,Vestibulum Massa Rutrum Limited,,
Yoko,Mack,Man,"P.O. Box 324, 4768 Eget Road",[email protected],12.10.21,Ehmedli,$529.00,Tristique Pellentesque Associates,,
Eaton,Rich,Female,7578 Nam Street,[email protected],13.10.21,Ecemi,$920.00,Purus Industries,,
Chancellor,Noble,Man,Ap #358-5738 Eu Street,[email protected],15.10.21,Insaatcilar,$924.00,Fringilla Foundation,,
Tatum,Shelton,Female,443 Ipsum Ave,[email protected],17.10.21,Ehmedli,$814.00,Quisque Limited,,
Ima,Cleveland,Man,Ap #737-222 Dui Av.,[email protected],18.10.21,Ecemi,$953.00,Sollicitudin Commodo Ipsum Corporation,,
Chloe,Roy,Female,"P.O. Box 637, 5132 Proin Rd.",[email protected],22.10.21,Ehmedli,$975.00,Donec Ltd,,
Cheryl,Pruitt,Man,8630 Nunc St.,[email protected],24.10.21,Yanvar,$905.00,Orci Corp.,,
Dane,Farmer,Female,Ap #567-756 Bibendum Road,[email protected],26.10.21,Elmler,$754.00,Egestas Foundation,,
Clayton,Fletcher,Man,4353 Sed Rd.,[email protected],27.10.21,Ehmedli,$885.00,Elementum Limited,,
Madaline,Lamb,Female,Ap #643-2513 In St.,[email protected],31.10.21,Elmler,$480.00,Aliquam Adipiscing Lobortis Incorporated,,
Sara,Battle,Man,"1286 Ultrices, Ave",[email protected],01.11.21,Ehmedli,$812.00,Nec Quam Associates,,
Francis,Haynes,Female,3325 Mauris. Street,[email protected],02.11.21,Ecemi,$956.00,Sed Corporation,,
Lyle,Gibbs,Man,174-2493 Urna. Road,[email protected],03.11.21,Yanvar,$357.00,Sed Incorporated,,
Vaughan,Massey,Female,Ap #523-6903 Ligula. St.,[email protected],08.11.21,Yanvar,$943.00,Eu Tellus Incorporated,,
Blake,Stokes,Man,Ap #539-233 Vitae St.,[email protected],10.11.21,Elmler,$784.00,Vitae Velit Inc.,,
Sybill,Norton,Female,Ap #670-2386 Dictum St.,[email protected],11.11.21,Ehmedli,$306.00,Enim Foundation,,
Kimberly,Mcpherson,Man,Ap #669-514 Aliquam St.,[email protected],13.11.21,Yanvar,$332.00,Purus Mauris A Ltd,,
Breanna,Hyde,Female,795-8143 Et Rd.,[email protected],14.11.21,Insaatcilar,$940.00,Phasellus Vitae Associates,,
Cruz,Coffey,Man,"411-2804 Lorem, Street",[email protected],17.11.21,Ecemi,$367.00,Maecenas Libero Inc.,,
Carl,Durham,Female,577-7851 Ante St.,[email protected],19.11.21,Insaatcilar,$520.00,In Tempus Institute,,
Dorian,Pearson,Man,542-5868 Eleifend Ave,[email protected],22.11.21,Ecemi,$731.00,Dui Quis Institute,,
Preston,Holt,Female,263-1931 Feugiat. Ave,[email protected],28.11.21,Yanvar,$718.00,Praesent Institute,,
Vaughan,Heath,Man,714-3401 Vivamus Av.,[email protected],06.12.21,Ehmedli,$382.00,Sed Limited,,
Nolan,Fuller,Female,Ap #638-5328 Sit St.,[email protected],08.12.21,Yanvar,$349.00,Dignissim Magna Ltd,,
Barbara,Moore,Man,Ap #396-1030 Nisi. Rd.,[email protected],09.12.21,Insaatcilar,$566.00,Ipsum LLC,,
Zahir,Franco,Female,489 Elit Street,[email protected],11.12.21,Ehmedli,$507.00,Enim LLC,,
Victoria,Mayo,Man,Ap #315-9677 Cursus Rd.,[email protected],12.12.21,Ecemi,$594.00,Non Bibendum Limited,,
Katell,Stevenson,Female,"P.O. Box 859, 6994 In St.",[email protected],14.12.21,Insaatcilar,$880.00,Nec Luctus Felis PC,,
Drake,Browning,Man,Ap #613-2519 Odio St.,[email protected],17.12.21,Ecemi,$932.00,Cras Industries,,
Zachary,Estes,Female,235-5750 Egestas. Street,[email protected],18.12.21,Yanvar,$634.00,Enim Condimentum Corporation,,
Warren,Brady,Man,"P.O. Box 167, 6720 Orci, St.",[email protected],23.12.21,Yanvar,$727.00,Lorem Fringilla Ornare Industries,,
Dieter,Park,Female,"905-1599 Eget, Avenue",[email protected],24.12.21,Insaatcilar,$640.00,Orci Lacus Institute,,
Gillian,Buckner,Man,Ap #863-1313 In Road,[email protected],25.12.21,Elmler,$316.00,Eros Turpis Non LLC,,
Emma,Wade,Female,Ap #126-2124 Duis Av.,[email protected],26.12.21,Ehmedli,$755.00,Ornare Incorporated,,
Thaddeus,Blake,Man,4233 Consequat Road,[email protected],27.12.21,Ecemi,$308.00,Est Arcu Inc.,,
Bert,Harmon,Female,"P.O. Box 500, 4710 Venenatis Street",[email protected],29.12.21,Insaatcilar,$808.00,Porttitor PC,,
Emi,Ramos,Man,Ap #542-656 Magna. St.,[email protected],01.01.22,Ecemi,$413.00,Magna Ut Incorporated,,
Lane,Bolton,Female,340-7687 Proin St.,[email protected],02.01.22,Yanvar,$944.00,Facilisis Suspendisse Commodo Incorporated,,
Berk,Blevins,Man,1367 Vehicula. Av.,[email protected],05.01.22,Ehmedli,$610.00,Aliquet Industries,,
Tamara,Padilla,Female,"772-6535 Et, St.",[email protected],07.01.22,Yanvar,$987.00,Tortor Associates,,
Bruno,Mathis,Man,496-7246 Torquent Road,[email protected],08.01.22,Insaatcilar,$715.00,Mi Duis Risus Incorporated,,
Hadassah,Finley,Female,877-286 Vel Road,[email protected],09.01.22,Elmler,$791.00,Hendrerit A Arcu Consulting,,
Erica,Melton,Man,3053 Parturient Road,[email protected],11.01.22,Ecemi,$636.00,Sed Associates,,
Nissim,Alvarez,Female,"9580 A, Ave",[email protected],13.01.22,Insaatcilar,$818.00,Turpis Egestas Ltd,,
Samantha,Howard,Man,Ap #506-4100 Eu Road,[email protected],14.01.22,Elmler,$609.00,Semper LLP,,

Python'daki kodumuz:
import sqlite3 as db
import os as cmd

try:
mySqlite = "baza"
if cmd.path.exists(mySqlite+".db"):
mydb = db.connect(mySqlite+".db")
connect = mydb.cursor()
else:
mydb = db.connect(mySqlite+".db")
connect = mydb.cursor()
# BASLIQLARIN YAZILMASI
file_adi = "baza"
file = open(file_adi+".txt", "r")
basliq = file.readline().strip("\n").split(",")
# DATALARIN YAZILMASI
infolar = file.readlines(-1)
sql = (
"""CREATE TABLE Senedler (
"""
+ basliq[0]
+ """ TEXT,
"""
+ basliq[1]
+ """ TEXT,
"""
+ basliq[2]
+ """ TEXT,
"""
+ basliq[3]
+ """ TEXT,
"""
+ basliq[4]
+ """ TEXT,
"""
+ basliq[5]
+ """ TEXT,
"""
+ basliq[6]
+ """ TEXT,
"""
+ basliq[7]
+ """ TEXT,
"""
+ basliq[8]
+ """ TEXT)"""
)
mydb.execute(sql)
print("- Basliqlar Yaradildi.")
mydb.commit()
x = range(0, 47)
for n in x:
info = list(infolar)[n].strip("\n").split(",")
connect.execute(
"INSERT INTO Senedler VALUES(?,?,?,?,?,?,?,?,?)",
(
info[0],
info[1],
info[2],
info[3],
info[4],
info[5],
info[6],
info[7],
info[8],
),
)
print("- Melumatlar yuklendi.")
mydb.commit()
except FileNotFoundError:
print(file_adi + ".txt adinda fayl tapilmadi..")
except db.OperationalError as bazaError:
print("Xeta var: " + bazaError)
 
5,682Konular
16,863Mesajlar
9,648Kullanıcılar
Üst