Created
January 17, 2021 02:29
-
-
Save ilius/7e2b0cfd1198dac360c871bd62adff04 to your computer and use it in GitHub Desktop.
Drug-guide.py
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
from formats_common import * | |
import html | |
enable = True | |
format = 'Drug-guide' | |
description = 'Drug-guide (SQLite3)' | |
extensions = () | |
readOptions = [] | |
writeOptions = [] | |
tools = [ | |
{ | |
"name": "Drug-guide", | |
"web": "", | |
"platforms": ["Android"], | |
# "license": "", | |
}, | |
] | |
class Reader(object): | |
def __init__(self, glos): | |
self._glos = glos | |
self._clear() | |
def _clear(self): | |
self._filename = '' | |
self._con = None | |
self._cur = None | |
def open(self, filename): | |
from sqlite3 import connect | |
self._filename = filename | |
self._con = connect(filename) | |
self._cur = self._con.cursor() | |
self._glos.setDefaultDefiFormat("h") | |
def __len__(self): | |
self._cur.execute("select count(*) from diseases") | |
return self._cur.fetchone()[0] | |
def __iter__(self): | |
self._cur.execute( | |
"select name, definition, type, etiology, signs_and_symptoms, diagnosis, treatment, prevention_and_screening, prevalence_and_risk_factors from diseases " | |
" order by id" | |
) | |
# FIXME: iteration over self._cur stops after one entry | |
# and self._cur.fetchone() returns None | |
# for row in self._cur: | |
for row in self._cur.fetchall(): | |
name = row[0] | |
definition = row[1] | |
type = row[2] | |
etiology = row[3] | |
signs_and_symptoms = row[4] | |
diagnosis = row[5] | |
treatment = row[6] | |
prevention_and_screening = row[7] | |
prevalence_and_risk_factors = row[8] | |
word = name | |
if definition is None: | |
definition = "" | |
if type: | |
definition += f'<br><br><b>Category:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{type}</div></a>' | |
if etiology: | |
definition += f'<br><b>Etiology:</b> <a> <div style="white-space: pre-wrap;">{etiology}</div></a>' | |
if signs_and_symptoms: | |
definition += f'<br><b>Clinical Picture:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{signs_and_symptoms}</div></a>' | |
if diagnosis: | |
definition += f'<br><b>Diagnosis:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{diagnosis}</div></a>' | |
if treatment: | |
definition += f'<br><b>Treatment:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{treatment}</div></a>' | |
if prevention_and_screening: | |
definition += f'<br><b>Prevention and screening:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{prevention_and_screening}</div></a>' | |
if prevalence_and_risk_factors: | |
definition += f'<br><b>Prevalence and risk factors:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{prevalence_and_risk_factors}</div></a>' | |
yield self._glos.newEntry( | |
word, | |
definition, | |
defiFormat="h", | |
) | |
def close(self): | |
if self._cur: | |
self._cur.close() | |
if self._con: | |
self._con.close() | |
self._clear() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment