Skip to content

Python tool for converting files and office documents to Markdown.

feature: add argument parsing and setup.py file for cli tool capability

kevinbabou33638f1fe6d3
diff --git a/setup.py b/setup.py
new file mode 100644
index 00000000..7d3e3117
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,31 @@
+from setuptools import setup, find_packages
+
+setup(
+ name='markitdown',
+ version='0.1.0',
+ package_dir={'': 'src'},
+ packages=find_packages(where='src'),
+ install_requires=[
+ 'mammoth',
+ 'markdownify',
+ 'pandas',
+ 'pdfminer.six',
+ 'python-pptx',
+ 'puremagic',
+ 'requests',
+ 'beautifulsoup4',
+ 'pydub',
+ 'SpeechRecognition',
+ 'youtube_transcript_api',
+ ],
+ entry_points={
+ 'console_scripts': [
+ 'markitdown=markitdown.__main__:main',
+ ],
+ },
+ author='Adam Fourney',
+ author_email='[email protected]',
+ description='Convert various file formats to markdown',
+ license='MIT',
+ python_requires='>=3.6',
+)
\ No newline at end of file
diff --git a/src/markitdown/__main__.py b/src/markitdown/__main__.py
index 6c8a6723..a2fafb22 100644
--- a/src/markitdown/__main__.py
+++ b/src/markitdown/__main__.py
@@ -2,21 +2,15 @@
#
# SPDX-License-Identifier: MIT
import sys
+import argparse
from ._markitdown import MarkItDown
def main():
- if len(sys.argv) == 1:
- markitdown = MarkItDown()
- result = markitdown.convert_stream(sys.stdin.buffer)
- print(result.text_content)
- elif len(sys.argv) == 2:
- markitdown = MarkItDown()
- result = markitdown.convert(sys.argv[1])
- print(result.text_content)
- else:
- sys.stderr.write(
- """
+ parser = argparse.ArgumentParser(
+ description='Convert various file formats to markdown.',
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ usage="""
SYNTAX:
markitdown <OPTIONAL: FILENAME>
@@ -34,9 +28,20 @@ EXAMPLE:
markitdown < example.pdf
""".strip()
- + "\n"
- )
+ )
+
+ parser.add_argument('filename', nargs='?')
+ args = parser.parse_args()
+
+ if args.filename is None:
+ markitdown = MarkItDown()
+ result = markitdown.convert_stream(sys.stdin.buffer)
+ print(result.text_content)
+ else:
+ markitdown = MarkItDown()
+ result = markitdown.convert(args.filename)
+ print(result.text_content)
if __name__ == "__main__":
- main()
+ main()
\ No newline at end of file