MedicineSearch/export_json.py
2023-01-23 19:09:48 +11:00

30 lines
1.3 KiB
Python

# 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 json
import sqlite3
con = sqlite3.connect('database.db')
cur = con.cursor()
results = []
cur.execute('SELECT item_code, mp_pt, tpuu_or_mpp_pt, restriction_flag, mq, repeats, streamlined_authorities FROM pbs')
for item_code, mp_pt, tpuu_or_mpp_pt, restriction_flag, mq, repeats, streamlined_authorities in cur.fetchall():
results.append(dict(item_code=item_code, mp_pt=mp_pt, tpuu_or_mpp_pt=tpuu_or_mpp_pt, restriction_flag=restriction_flag, mq=mq, repeats=repeats, streamlined_authorities=streamlined_authorities))
with open('html/pbs.json', 'w') as f:
json.dump(results, f)