Cobertos / md2notion

A better Notion.so Markdown importer
MIT License
654 stars 65 forks source link

Is it possible to give URL instead of a String or MD file? #24

Closed SohrabAmin closed 3 years ago

SohrabAmin commented 3 years ago

When using upload() do we have the ability to give a URL as mdFile so it works almost like a web clipper?

Cobertos commented 3 years ago

Not directly, but it takes a file-like object, so you can do something like

import requests
r = requests.get(path)
if not r.status_code < 300: #TODO: Make this better..., should only accept success
  raise RuntimeError(f'Could not get file {path}, HTTP {r.status_code}')
fileName = path.split('?')[0]
fileName = fileName.split('/')[-1]
fileLike = io.StringIO(r.text)
fileLike.name = path

which is what the CLI does when you pass it a URL string