Created
May 11, 2020 09:38
-
-
Save Olbergx/7ca42ef5d05627b73514b37dc6362882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sqlite3 | |
# from xml.etree import ElementTree | |
import xml.etree.ElementTree as ET | |
dom = ET.parse('profile.xml') | |
# compose the argument list in one line, drop the big copied/pasted block | |
args_list = ([t.text for t in dom.iter(tag)] for tag in ['TICKER','NAME','ADDRESS','PHONE','WEBSITE','SECTOR','INDUSTRY','FULL_TIME','BUS_SUMM']) | |
con = sqlite3.connect("DB_SIACLE.db") | |
cur = con.cursor() | |
query = "INSERT INTO profiles(prof_ticker,name,address,phonenum,website,sector,industry,full_time,bus_summ) VALUES (?,?,?,?,?,?,?,?,?)" | |
# create the tuples from the argument list | |
sqltuples = list(zip(*args_list)) | |
# execute query (unchanged) | |
# print(sqltuples) | |
cur.executemany(query,sqltuples) | |
con.commit() | |
con.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment