diff --git a/engine/md_update.py b/engine/md_update.py index f83d7e4..b2033b7 100644 --- a/engine/md_update.py +++ b/engine/md_update.py @@ -4,7 +4,7 @@ import codecs from engine.conf import PATH_TO_MD, SCREENSHOT_INBOX, PATH_TO_IMG, IMG_PREFIX, AI_WRITER, USE_RM_TO_REMOVE_FIGURE -from engine.process_md import right_MD_from_webservices, get_youtube_embeds_insert, remove_image, simply_interal_links, insert_file_into_archive +from engine.process_md import right_MD_from_webservices, get_youtube_embeds_insert, remove_image, simply_interal_links, insert_file_into_archive, insert_safari_url from engine.plugins.insert_image import insert_image_in_md from engine.plugins.draw_secondary_structure import get_ss from engine.plugins.ia_writer import edit_syntax_from_ai_writer_to_geekbook @@ -56,6 +56,8 @@ def compile(self): self.md, file_inserted = insert_file_into_archive(self.md) + self.md, changed = insert_safari_url(self.md) + # ai writer is_edit_synatx_ai = False if AI_WRITER: @@ -63,7 +65,7 @@ def compile(self): # check if anything changed if any([is_get_ss, is_ii, is_right_MD, is_edit_synatx_ai, yti, use_rm, - is_simply_interal_links, file_inserted]): + is_simply_interal_links, file_inserted, changed]): return True else: return False diff --git a/engine/process_md.py b/engine/process_md.py index 7944d0f..3c75fa8 100644 --- a/engine/process_md.py +++ b/engine/process_md.py @@ -12,11 +12,25 @@ from engine.conf import PATH_TO_IMG, PATH_TO_MD, PATH_TO_ORIG +from icecream import ic +import sys +ic.configureOutput(outputFunction=lambda *a: print(*a, file=sys.stderr), includeContext=True) +ic.configureOutput(prefix='> ') + import logging logger = logging.getLogger('geekbook') logger.setLevel(logging.INFO) +import subprocess +def exe(cmd): + o = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out = o.stdout.read().strip().decode() + err = o.stderr.read().strip().decode() + return out, err + + def right_MD_from_webservices(text): """ Just paste the url generated by Dropbox to convert it in a markdown img """ changed = False @@ -58,6 +72,26 @@ def simply_interal_links(text): ntext += l + '\n' return ntext, changed +def insert_safari_url(text): + ntext = '' + changed = False + for l in text.split('\n'): + if l.startswith('\is'): + with open('/tmp/is.applescript', 'w') as f: + f.write("""tell application "Safari" + tell window 1 + tell current tab + return URL + end tell + end tell +end tell""") + url, err = exe('osascript /tmp/is.applescript') + ic(url) + changed = True + l = url + ntext += l + '\n' + return ntext, changed + def insert_file_into_archive(text): """Change file:///Users/magnus/Desktop/1VQM-01642-01680_rpr.pdb into @@ -228,3 +262,7 @@ def get_youtube_embeds_insert(text): changed = True ntext += l + '\n' return ntext, changed + + +if __name__ == '__main__': + print(insert_safari_url('\is'))