Skip to content

Commit

Permalink
insert_safari_url(): in code in md_update.py, rocess_md.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagnus committed Apr 3, 2022
1 parent 99ced55 commit 0ae5665
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
6 changes: 4 additions & 2 deletions engine/md_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,14 +56,16 @@ 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:
self.md, is_edit_synatx_ai = edit_syntax_from_ai_writer_to_geekbook(self.md, IMG_PREFIX)

# 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
Expand Down
38 changes: 38 additions & 0 deletions engine/process_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:

This comment has been minimized.

Copy link
@mmagnus

mmagnus Apr 3, 2022

Author Owner
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
Expand Down Expand Up @@ -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'))

0 comments on commit 0ae5665

Please sign in to comment.