Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(flow): add warning to jpg downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Oct 12, 2019
1 parent e3ab1aa commit 7d2c681
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gnes/flow/__init__.py
Expand Up @@ -238,7 +238,7 @@ def to_url(self, **kwargs) -> str:
return 'https://mermaidjs.github.io/mermaid-live-editor/#/view/%s' % encoded_str return 'https://mermaidjs.github.io/mermaid-live-editor/#/view/%s' % encoded_str


@_build_level(BuildLevel.GRAPH) @_build_level(BuildLevel.GRAPH)
def to_jpg(self, path: str = 'flow.jpg', **kwargs): def to_jpg(self, path: str = 'flow.jpg', **kwargs) -> None:
""" """
Rendering the current flow as a jpg image, this will call :py:meth:`to_mermaid` and it needs internet connection Rendering the current flow as a jpg image, this will call :py:meth:`to_mermaid` and it needs internet connection
Expand All @@ -249,7 +249,9 @@ def to_jpg(self, path: str = 'flow.jpg', **kwargs):


from urllib.request import Request, urlopen from urllib.request import Request, urlopen
encoded_str = self.to_url().replace('https://mermaidjs.github.io/mermaid-live-editor/#/view/', '') encoded_str = self.to_url().replace('https://mermaidjs.github.io/mermaid-live-editor/#/view/', '')
self.logger.info('saving jpg...') self.logger.warning('jpg exporting relies on https://mermaid.ink/, but it is not very stable. '
'some syntax are not supported, please use with caution.')
self.logger.info('downloading as jpg...')
req = Request('https://mermaid.ink/img/%s' % encoded_str, headers={'User-Agent': 'Mozilla/5.0'}) req = Request('https://mermaid.ink/img/%s' % encoded_str, headers={'User-Agent': 'Mozilla/5.0'})
with open(path, 'wb') as fp: with open(path, 'wb') as fp:
fp.write(urlopen(req).read()) fp.write(urlopen(req).read())
Expand Down

0 comments on commit 7d2c681

Please sign in to comment.