feature: add argument parsing and setup.py file for cli tool capability
This commit is contained in:
31
setup.py
Normal file
31
setup.py
Normal file
@@ -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='adamfo@microsoft.com',
|
||||||
|
description='Convert various file formats to markdown',
|
||||||
|
license='MIT',
|
||||||
|
python_requires='>=3.6',
|
||||||
|
)
|
||||||
@@ -2,21 +2,15 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
from ._markitdown import MarkItDown
|
from ._markitdown import MarkItDown
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) == 1:
|
parser = argparse.ArgumentParser(
|
||||||
markitdown = MarkItDown()
|
description='Convert various file formats to markdown.',
|
||||||
result = markitdown.convert_stream(sys.stdin.buffer)
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
print(result.text_content)
|
usage="""
|
||||||
elif len(sys.argv) == 2:
|
|
||||||
markitdown = MarkItDown()
|
|
||||||
result = markitdown.convert(sys.argv[1])
|
|
||||||
print(result.text_content)
|
|
||||||
else:
|
|
||||||
sys.stderr.write(
|
|
||||||
"""
|
|
||||||
SYNTAX:
|
SYNTAX:
|
||||||
|
|
||||||
markitdown <OPTIONAL: FILENAME>
|
markitdown <OPTIONAL: FILENAME>
|
||||||
@@ -34,8 +28,19 @@ EXAMPLE:
|
|||||||
|
|
||||||
markitdown < example.pdf
|
markitdown < example.pdf
|
||||||
""".strip()
|
""".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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user