Skip to content

Commit

Permalink
add hackmd runner test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Nov 24, 2024
1 parent 14af7ec commit 97e8a3a
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/test_hackmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import platform
import base64
print(sys.argv)

async def to_img_file(filename, url):
with open(filename,'wb') as out:

if url.startswith('//') or url.startswith('http'):
async with platform.fopen(img, "rb") as img:
out.write(img.read())
elif url.startswith('data:image/'):
url = url[url.find(';base64,')+7:]
out.write(base64.b64decode(url,validate=False))
print("IMAGE:", filename,len(url))


async def main():
buff = []
code = False
if sys.argv[-1].find('hackmd.io')<0:
sys.argv.append('https://hackmd.io/zZTCp8XETLiX0QA30bbPUQ')

async with platform.fopen(sys.argv[-1]+"/download", "r") as file:
for line in file.readlines():
if line[0]=='!' and line.find('](')>0:
tag, img = line.rsplit('](',1)
tag = tag.rsplit('[',1)[-1].strip()
img = img.strip(')\n')
await to_img_file(tag, img)
continue
if line.startswith('```py'):
print('Begin')
code = True
continue

if line.endswith('```\n'):
print('End')
code = False
continue

if code:
buff.append(line)
continue
print(line,end="")

with open('main.py','w') as file:
file.write(''.join(buff))

await shell.runpy('main.py')

print("\n"*4, "HACKMD URL :", sys.argv[-1],"\n"*4)
shell.interactive(prompt=True)

while 1:
await asyncio.sleep(0)


asyncio.run(main())

0 comments on commit 97e8a3a

Please sign in to comment.