Skip to content

Instantly share code, notes, and snippets.

@Olbergx
Created May 11, 2020 09:38
Show Gist options
  • Save Olbergx/7ca42ef5d05627b73514b37dc6362882 to your computer and use it in GitHub Desktop.
Save Olbergx/7ca42ef5d05627b73514b37dc6362882 to your computer and use it in GitHub Desktop.
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