Last active
August 29, 2015 14:04
-
-
Save nshtg/23361ff64a404d0bd895 to your computer and use it in GitHub Desktop.
Proof of concept for zams db
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
#!/usr/bin/env python3 | |
""" | |
Shebang python3 | |
""" | |
import re | |
import sqlite3 | |
INT_TO_CHAR = ['A', 'B', 'C', 'D', 'E'] | |
def remove_br(raw): | |
""" | |
Removes <br /> tags from the raw text | |
""" | |
if isinstance(raw, str): | |
return re.sub('<br />', '\n', raw) | |
else: | |
return raw | |
def extract_question(raw): | |
""" | |
Extracts the data from a raw question | |
""" | |
raw_list = list(raw)[7:-1] | |
question = remove_br(raw_list[0]) | |
print('%s\n' % question) | |
raw_list = raw_list[1:] | |
answers = [] | |
correct_answer = -1 | |
for i in range(len(raw_list)): | |
if i % 2 == 0: | |
answers.append(remove_br(raw_list[i])) | |
print('[%s] %s' % (INT_TO_CHAR[int(i/2)], answers[int(i/2)])) | |
else: | |
if raw_list[i] == 1: | |
correct_answer = int((i-1)/2) | |
print('\nCorrect Answer: [%s]\n\n-----' % INT_TO_CHAR[correct_answer]) | |
return [question, answers, correct_answer] | |
def main(): | |
""" | |
Main function | |
""" | |
database = sqlite3.connect('patho2014.zdb') | |
database_conn = database.cursor() | |
query = 'SELECT * FROM tQuestions' | |
database_conn.execute(query) | |
# extract_question(database_conn.fetchone()) | |
questions = database_conn.fetchall() | |
for _ in questions: | |
extract_question(_) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment