Skip to content

Commit

Permalink
add artifact upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbull committed Apr 11, 2024
1 parent 468f941 commit 4688c20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/scheduled_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ jobs:
pip install -r requirements.txt
- name: build
run: python main.py
- name: upload
uses: actions/upload-artifact@v4
with:
name: pdf
path: out/guide.pdf
17 changes: 10 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
OUTPUT_DIR = os.environ.get('OUTPUT_DIR')


class ApiException(Exception):
class LarkOpenApiError(Exception):
def __init__(self, code: int, msg: str):
super().__init__(self, code, msg)
self.__code = code
self.__msg = msg
super(f'{self.__code} {self.__msg}')

@property
def code(self):
Expand All @@ -36,6 +36,9 @@ def code(self):
def msg(self):
return self.__msg

def __str__(self) -> str:
return f'LarkOpenApiError: {self.code} {self.msg}'


class NodeTreeWalker(object):
class UninitializedException(Exception):
Expand Down Expand Up @@ -66,7 +69,7 @@ def walk(self, space_id: str, parent_node_token: str | None = None) -> List[Node
if not resp.success():
logging.error(
f'failed to dispatch list space nodes request: {resp.code} {resp.msg}')
raise ApiException(resp.code, resp.msg)
raise LarkOpenApiError(resp.code, resp.msg)

# dive into current node
if resp.data.items:
Expand Down Expand Up @@ -100,7 +103,7 @@ def create_export_task(client: lark.Client, node: Node) -> str:
if not resp.success():
logging.error(
f'failed to dispatch create export task request: {resp.code} {resp.msg}')
raise ApiException(resp.code, resp.msg)
raise LarkOpenApiError(resp.code, resp.msg)
return resp.data.ticket


Expand All @@ -115,13 +118,13 @@ def wait_task(client: lark.Client, node: Node, ticket: str) -> ExportTask:
if not resp.success():
logging.error(
f'failed to query task execution status: {resp.code} {resp.msg}')
raise ApiException(resp.code, resp.msg)
raise LarkOpenApiError(resp.code, resp.msg)
status, msg = resp.data.result.job_status, resp.data.result.job_error_msg
if status == 0:
return resp.data.result
elif status != 1 and status != 2:
logging.error(f'job failed: {status} {msg}')
raise ApiException(status, msg)
raise LarkOpenApiError(status, msg)


def download_exported_pdf(client: lark.Client, task: ExportTask, path: str):
Expand All @@ -132,7 +135,7 @@ def download_exported_pdf(client: lark.Client, task: ExportTask, path: str):
if not resp.success():
logging.error(
f'failed to download exported file: {resp.code} {resp.msg}')
raise ApiException(resp.code, resp.msg)
raise LarkOpenApiError(resp.code, resp.msg)
with open(path, 'wb') as f:
f.write(resp.raw.content)

Expand Down

0 comments on commit 4688c20

Please sign in to comment.