Skip to content

Commit

Permalink
feat: connect image convert cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
steveoh committed Oct 19, 2022
1 parent ae62f2b commit 737860a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
7 changes: 3 additions & 4 deletions cov.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" ?>
<coverage version="6.5.0" timestamp="1666216429206" lines-valid="19" lines-covered="17" line-rate="0.8947" branches-valid="0" branches-covered="0" branch-rate="1" complexity="0">
<coverage version="6.5.0" timestamp="1666220875349" lines-valid="18" lines-covered="16" line-rate="0.8889" branches-valid="0" branches-covered="0" branch-rate="1" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/Users/sgourley/dev/udot-parcel-ml</source>
</sources>
<packages>
<package name="." line-rate="0.8947" branch-rate="1" complexity="0">
<package name="." line-rate="0.8889" branch-rate="1" complexity="0">
<classes>
<class name="row.py" filename="row.py" complexity="0" line-rate="0.8947" branch-rate="1">
<class name="row.py" filename="row.py" complexity="0" line-rate="0.8889" branch-rate="1">
<methods/>
<lines>
<line number="3" hits="1"/>
Expand All @@ -29,7 +29,6 @@
<line number="37" hits="1"/>
<line number="39" hits="1"/>
<line number="41" hits="1"/>
<line number="43" hits="1"/>
</lines>
</class>
</classes>
Expand Down
2 changes: 0 additions & 2 deletions row.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,4 @@ def convert_pdf_to_pil(pdf_as_bytes):

count = len(images)

print(f"number of images: {count}")

return (images, count, messages)
45 changes: 39 additions & 6 deletions row_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
row
"""

from pathlib import Path

from docopt import docopt

import row
Expand All @@ -34,12 +36,43 @@
def main():
"""doc string"""
args = docopt(__doc__, version="1.0") # type: ignore
print(args)

if args["test"]:
print("great job dude")
return

if args["storage"] and args["download"]:
return
# row.download(args["--from-bucket"], args["--task-index"], args["--testing"])

if args["images"] and args["process"]:
return

if args["image"]:
if args["convert"]:
pdf = Path(args["<file_name>"])
if not pdf.exists():
print("file does not exist")
return

images, count, messages = row.convert_pdf_to_pil(pdf.read_bytes())
print(f"{pdf.name} contained {count} pages and converted with message {messages}")

if args["--output-directory"]:
print(f'saving {count} images to {args["--output-directory"]}')

directory = Path(args["--output-directory"])
if not directory.exists():
print("directory does not exist")
return

for index, image in enumerate(images):
image.save(directory / f"{pdf.stem}_{index+1}.jpg")

return
if args["rotate"]:
return

def test():
"""doc string"""
greeting = row.function()
print(greeting)

return greeting
if __name__ == "__main__":
main()

0 comments on commit 737860a

Please sign in to comment.