Skip to content

Commit

Permalink
Functions for Obsidian App
Browse files Browse the repository at this point in the history
  • Loading branch information
Exouth committed Sep 26, 2023
1 parent a46c464 commit 567ae15
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
12 changes: 7 additions & 5 deletions src/examgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from odf.opendocument import OpenDocumentText
from odf.text import P

engine = ExamPrompt("180bdc1f34ea46a48abaf34f2c121cb05391263a49a1b3c246c6241df172bf8dc06dd27d4c0b8edbc60eed6380be8b27566c6bcd7dfa34578efe5e0113605839")
engine = ExamPrompt()

try:

name = engine.ask_exam_name()

engine.ask_note_path()

engine.ask_topic_number()

toppic_notes = engine.give_topic_notes()
Expand All @@ -25,13 +27,13 @@

doc = OpenDocumentText()
for topic in toppic_notes:
page, note_id, title = topic
engine.prompt_exam(note_id, title, doc)
engine.prompt_exam(topic, doc)
engine.next_step()

doc.save(name);

engine.exit()

except KeyboardInterrupt:
engine.exit()
engine.exit()

32 changes: 19 additions & 13 deletions src/lib/exam_prompt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from pyperclip import copy
from lib.obsidian_api import ObsidianAPI
from lib.prompting import Prompt
from lib.joplin_api import JoplinAPI
from odf.text import P, Span, List, ListItem
Expand All @@ -8,25 +9,28 @@

class ExamPrompt():

def __init__(self, joplin_api):
def __init__(self):
self.name = ""
self.note_path = ""
self.topic_number = ""
self.prompt_instance = Prompt()
self.api_instance = JoplinAPI(joplin_api)
self.api_instance = ObsidianAPI()

def ask_exam_name(self):
self.name = self.prompt_instance.promp_user_return("What is the Exam Name?", "You set the Exam name to")
return self.name

def ask_note_path(self):
self.note_path = self.prompt_instance.promp_user_return("What is the Path to the Notes?", "You set the Path to")

def ask_topic_number(self):
self.topic_number = self.prompt_instance.promp_user_return("What is the Topic Number?", "You set the Topic Number to")
self.topic_number = self.prompt_instance.promp_user_return("What is the Topic?", "You set the Topic to")

def give_topic_notes(self):
matching_notes = self.api_instance.find_all_topic_notes(self.topic_number)
matching_notes = self.api_instance.find_all_topic_notes(self.note_path, self.topic_number)

for note in matching_notes:
page, note_id, title = note
self.prompt_instance.write_message(f"Used Note - Page: {page}, ID: {note_id}, Title: {title}")
self.prompt_instance.write_message(f"Used Note: {note}")

return matching_notes

Expand All @@ -35,17 +39,19 @@ def give_initial_Exam_Message(self):
copy(message)
self.prompt_instance.write_message(message)

def ask_obsidian_path(self):
self.general_path = self.__prompt_instance.promp_user_return("What is the Path to Obsidian?", "You set the Path to Obsidian to")
return self.general_path

def next_step(self):
self.prompt_instance.prompt_user("Are you ready to go to the next step? Click a Button")
self.prompt_instance.send_logo()

def prompt_exam(self, topic_id, title, document):
markdown_file = self.api_instance.get_note_text(topic_id)

self.prompt_instance.write_message("Doing now: " + title)
def prompt_exam(self, path, document):
markdown_file = self.api_instance.get_note_text(path)

# Multiplie Choice Questions
message = "Here is my Markdown Text. Can you give me 15 Multiplie Choices Questions based on this Note? Also put the Characters '+++' after each Multiplie Choice at the end without the Answer just the Characters! Here is my Markdown File: " + markdown_file["body"]
message = "Here is my Markdown Text. Can you give me 15 Multiplie Choices Questions based on this Note? Also put the Characters '+++' after each Multiplie Choice at the end without the Answer just the Characters! Here is my Markdown File: " + markdown_file
copy(message)
self.prompt_instance.write_message(message)

Expand All @@ -58,7 +64,7 @@ def prompt_exam(self, topic_id, title, document):
self.next_step()

# True or False Questions
message = "Here is my Markdown Text. Can you give me 10 True or False Questions based on this Note? Also put the Characters '+++' after each True or False Question at the end without the Answer just the Characters! Here is my Markdown File: " + markdown_file["body"]
message = "Here is my Markdown Text. Can you give me 10 True or False Questions based on this Note? Also put the Characters '+++' after each True or False Question at the end without the Answer just the Characters! Here is my Markdown File: " + markdown_file
copy(message)
self.prompt_instance.write_message(message)

Expand All @@ -71,7 +77,7 @@ def prompt_exam(self, topic_id, title, document):
self.next_step()

# Full Sentence Answers
message = "Here is my Markdown Text. Can you give me 15 Full Sentence Questions, where i need to answer with an Full Sentence based on this Note? Also put the Characters '+++' after each Full Sentence Question at the end without the Answer just the Characters! Here is my Markdown File: " + markdown_file["body"]
message = "Here is my Markdown Text. Can you give me 15 Full Sentence Questions, where i need to answer with an Full Sentence based on this Note? Also put the Characters '+++' after each Full Sentence Question at the end without the Answer just the Characters! Here is my Markdown File: " + markdown_file
copy(message)
self.prompt_instance.write_message(message)

Expand Down
34 changes: 34 additions & 0 deletions src/lib/obsidian_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os

class ObsidianAPI:

def __init__(self):
self.note_path = ""

def findNote(self, path, name):
for root, dirs, files in os.walk(path):
if name in files:
note_path = os.path.join(root, name)
return note_path
return None

def find_all_topic_notes(self, note_path, topic):
matching_files = []

for dirpath, _, filenames in os.walk(note_path):
for filename in filenames:
if filename.endswith(".md"):
full_filepath = os.path.join(dirpath, filename)
try:
with open(full_filepath, 'r', encoding='utf-8') as file:
content = file.read()
if topic in content:
matching_files.append(full_filepath)
except Exception as e:
print(f"Error reading {full_filepath}: {e}")

return matching_files

def get_note_text(self, path):
with open(path, 'r', encoding='utf-8') as file:
return file.read()

0 comments on commit 567ae15

Please sign in to comment.