Skip to content

Commit

Permalink
create user tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Sep 25, 2024
1 parent e1c5b90 commit 7ef94e4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 125 deletions.
4 changes: 3 additions & 1 deletion any_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from any_parser.base import AnyParser
"""AnyParser module for parsing data."""

from any_parser.any_parser import AnyParser

__all__ = ["AnyParser"]

Expand Down
8 changes: 6 additions & 2 deletions any_parser/any_parser_rt.py → any_parser/any_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
TIMEOUT = 60
SUPPORTED_FILE_EXTENSIONS = ["pdf", "doc", "docx", "ppt", "pptx"]


class AnyParser:
"""AnyParser RT: Real-time parser for any data format."""

Expand Down Expand Up @@ -70,7 +71,10 @@ def extract(
# Send the POST request
start_time = time.time()
response = requests.post(
self._sync_url, headers=self._headers, data=json.dumps(payload), timeout=TIMEOUT
self._sync_url,
headers=self._headers,
data=json.dumps(payload),
timeout=TIMEOUT,
)
end_time = time.time()

Expand Down Expand Up @@ -186,4 +190,4 @@ def async_fetch(
return "\n".join(markdown_list)
elif response.status_code == 202:
return None
return f"Error: {response.status_code}"
return f"Error: {response.status_code}"
99 changes: 0 additions & 99 deletions any_parser/base.py

This file was deleted.

23 changes: 23 additions & 0 deletions examples/test_async_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Testing Aynchronous Extraction"""

import sys

from any_parser import AnyParser

sys.path.append(".")
sys.path.append("..")
sys.path.append("../..")

# define API key and file path
API_KEY = "U1xoe4F7qQ9MGJkiMFtR240r3r2iF6NQaAMUEYYc"
FILE_PATH = "./sample_data/stoxx_index_guide_0003.pdf"

# create instance of AnyParser
ap = AnyParser(API_KEY)

# asynchronous extract job (extraction and result fetching are separate)
file_id = ap.async_extract(FILE_PATH)

# fetch results (5s polling)
md = ap.async_fetch(file_id=file_id)
print(md)
23 changes: 0 additions & 23 deletions examples/test_example.py

This file was deleted.

21 changes: 21 additions & 0 deletions examples/test_sync_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Testing Syncrhonous Extraction"""

import sys

from any_parser import AnyParser

sys.path.append(".")
sys.path.append("..")
sys.path.append("../..")

# define API key and file path
API_KEY = "U1xoe4F7qQ9MGJkiMFtR240r3r2iF6NQaAMUEYYc"
FILE_PATH = "./sample_data/stoxx_index_guide_0003.pdf"

# create instance of AnyParser
ap = AnyParser(API_KEY)

# synchronous extract job (extraction and result fetching together)
md_output, total_time = ap.extract(FILE_PATH)
print(md_output)
print(total_time)

0 comments on commit 7ef94e4

Please sign in to comment.