MedicineSearch/import_non_pbs.py

36 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright © 2023 Lee Yingtong Li (RunasSudo)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import csv
import sqlite3
# Open database
con = sqlite3.connect('database.db')
cur = con.cursor()
# Init schema
cur.execute('DROP TABLE IF EXISTS non_pbs_tpp')
cur.execute('CREATE TABLE non_pbs_tpp (mp_preferred_term TEXT, mpp_preferred_term TEXT, brand_name TEXT)')
with open('non_pbs.csv', 'r', newline='') as f:
reader = csv.DictReader(f)
for tpp in reader:
if not tpp['Hide']:
cur.execute('INSERT INTO non_pbs_tpp (mp_preferred_term, mpp_preferred_term, brand_name) VALUES (?, ?, ?)', (tpp['MP'], tpp['MPP'], tpp['TPP']))
con.commit()