-
Notifications
You must be signed in to change notification settings - Fork 4
Screenshots endpoint #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from hvpy.io import HvpyParameters, OutputType | ||
|
|
||
|
|
||
| class downloadScreenshotInputParameters(HvpyParameters): | ||
| """ | ||
| Handles the input parameters of the downloadScreenshot API. | ||
|
|
||
| Attributes | ||
| ---------- | ||
| {Shared} | ||
| id: int | ||
| Unique screenshot identifier (provided by the response to a takeScreenshot request). | ||
|
|
||
| References | ||
| ---------- | ||
| * `<https://api.helioviewer.org/docs/v2/api/api_groups/screenshots.html#downloadscreenshot>`__ | ||
| {Shared} | ||
| """ | ||
|
|
||
| id: int | ||
|
|
||
| def get_output_type(self) -> OutputType: | ||
| """ | ||
| Returns the output type of the API call. | ||
| """ | ||
| return OutputType.RAW |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| from typing import Optional | ||
| from datetime import datetime | ||
|
|
||
| from pydantic import validator | ||
|
|
||
| from hvpy.io import HvpyParameters, OutputType | ||
| from hvpy.utils import convert_date_to_isoformat | ||
|
|
||
|
|
||
| class takeScreenshotInputParameters(HvpyParameters): | ||
| """ | ||
| Handles the input parameters of the takeScreenshot API. | ||
|
|
||
| Attributes | ||
| ---------- | ||
| {Shared} | ||
| date : datetime.datetime | ||
| Desired date/time of the image. | ||
| imageScale : float | ||
| Image scale in arcseconds per pixel. | ||
| layers : str | ||
| Image datasource layer(s) to include in the screenshot. | ||
| eventLabels : bool | ||
| Optionally annotate each event marker with a text label. | ||
| events : str, optional | ||
| List feature/event types and FRMs to use to annoate the movie. Use the empty string to indicate that no feature/event annotations should be shown. | ||
| scale : bool, optional | ||
| Optionally overlay an image scale indicator. | ||
| scaleType : str, optional | ||
| Image scale indicator. | ||
| scaleX : int, optional | ||
| Horizontal offset of the image scale indicator in arcseconds with respect to the center of the Sun. | ||
| scaleY : int, optional | ||
| Vertical offset of the image scale indicator in arcseconds with respect to the center of the Sun. | ||
| width : str, optional | ||
| Width of the field of view in pixels. (Used in conjunction width x0,`y0`, and height). | ||
| height : str, optional | ||
| Height of the field of view in pixels. (Used in conjunction width x0,`y0`, and width). | ||
| x0 : str, optional | ||
| The horizontal offset of the center of the field of view from the center of the Sun. Used in conjunction with y0, width, and height. | ||
| y0 : str, optional | ||
| The vertical offset of the center of the field of view from the center of the Sun. Used in conjunction with x0, width, and height. | ||
| x1 : str, optional | ||
| The horizontal offset of the top-left corner of the field of view with respect to the center of the Sun (in arcseconds). Used in conjunction with y1, x2, and y2. | ||
| y1 : str, optional | ||
| The vertical offset of the top-left corner of the field of view with respect to the center of the Sun (in arcseconds). Used in conjunction with x1, x2, and y2. | ||
| x2 : str, optional | ||
| The horizontal offset of the bottom-right corner of the field of view with respect to the center of the Sun (in arcseconds). Used in conjunction with x1, y1, and y2. | ||
| y2 : str, optional | ||
| The vertical offset of the bottom-right corner of the field of view with respect to the center of the Sun (in arcseconds). Used in conjunction with x1, y1, and x2. | ||
| display : bool, optional | ||
| Set to true to directly output binary PNG image data. Default is `False` (which outputs a JSON object). | ||
| watermark : bool, optional | ||
| Optionally overlay a watermark consisting of a Helioviewer logo and the datasource abbreviation(s) and timestamp(s) displayed in the screenshot. | ||
| callback : str, optional | ||
| Wrap the response object in a function call of your choosing. | ||
|
|
||
| References | ||
| ---------- | ||
| * `<https://api.helioviewer.org/docs/v2/api/api_groups/screenshots.html#takescreenshot>`__ | ||
| {Shared} | ||
| """ | ||
|
|
||
| date: datetime | ||
| imageScale: float | ||
| layers: str | ||
| events: Optional[str] = None | ||
| eventLabels: Optional[bool] = False | ||
| scale: Optional[bool] = False | ||
| scaleType: Optional[str] = None | ||
| scaleX: Optional[int] = None | ||
| scaleY: Optional[int] = None | ||
| width: Optional[str] = None | ||
| height: Optional[str] = None | ||
| x0: Optional[str] = None | ||
| y0: Optional[str] = None | ||
| x1: Optional[str] = None | ||
| y1: Optional[str] = None | ||
| x2: Optional[str] = None | ||
| y2: Optional[str] = None | ||
| display: Optional[bool] = False | ||
| watermark: Optional[bool] = False | ||
| callback: Optional[str] = None | ||
| _date_vaidator = validator("date", allow_reuse=True)(convert_date_to_isoformat) | ||
|
|
||
| def get_output_type(self) -> OutputType: | ||
| """ | ||
| Returns the output type of the API call. | ||
| """ | ||
| return OutputType.RAW if self.display else OutputType.JSON | ||
19 changes: 19 additions & 0 deletions
19
hvpy/api_groups/screenshots/tests/test_download_screenshot.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import pytest | ||
|
|
||
| from hvpy import downloadScreenshot | ||
| from hvpy.api_groups.screenshots.download_screenshot import downloadScreenshotInputParameters | ||
|
|
||
|
|
||
| def test_raw_response(): | ||
| response = downloadScreenshot(id=3240748) | ||
| assert isinstance(response, bytes) | ||
|
|
||
|
|
||
| def test_url_property(): | ||
| params = downloadScreenshotInputParameters(id=3240748) | ||
| assert params.url == "https://api.helioviewer.org/v2/downloadScreenshot/" | ||
|
|
||
|
|
||
| def test_error_handling(): | ||
| with pytest.raises(TypeError, match="missing 1 required positional argument: 'id'"): | ||
| downloadScreenshot() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| from datetime import datetime | ||
|
|
||
| import pytest | ||
|
|
||
| from hvpy import takeScreenshot | ||
| from hvpy.api_groups.screenshots.take_screenshot import takeScreenshotInputParameters | ||
|
|
||
|
|
||
| def test_json_response(): | ||
| response = takeScreenshot( | ||
| date=datetime(2014, 1, 1, 23, 59, 59), | ||
| imageScale=2.4204409, | ||
| layers="[3,1,100]", | ||
| width=1920, | ||
| height=1200, | ||
| x0=0, | ||
| y0=0, | ||
| ) | ||
| assert "id" in response | ||
|
|
||
|
|
||
| def test_raw_response(): | ||
| response = takeScreenshot( | ||
| display=True, | ||
| date=datetime(2014, 1, 1, 23, 59, 59), | ||
| imageScale=2.4204409, | ||
| layers="[3,1,100]", | ||
| width=1920, | ||
| height=1200, | ||
| x0=0, | ||
| y0=0, | ||
| ) | ||
| assert isinstance(response, bytes) | ||
|
|
||
|
|
||
| def test_url_property(): | ||
| params = takeScreenshotInputParameters( | ||
| date=datetime(2014, 1, 1, 23, 59, 59), | ||
| imageScale=2.4204409, | ||
| layers="[3,1,100]", | ||
| width=1920, | ||
| height=1200, | ||
| x0=0, | ||
| y0=0, | ||
| ) | ||
| assert params.url == "https://api.helioviewer.org/v2/takeScreenshot/" | ||
|
|
||
|
|
||
| def test_error_handling(): | ||
| with pytest.raises(TypeError, match="missing 1 required positional argument: 'date'"): | ||
| takeScreenshot( | ||
| imageScale=2.4204409, | ||
| layers="[3,1,100]", | ||
| ) | ||
| with pytest.raises(TypeError, match="missing 1 required positional argument: 'imageScale'"): | ||
| takeScreenshot( | ||
| date=datetime(2014, 1, 1, 23, 59, 59), | ||
| layers="[3,1,100]", | ||
| ) | ||
| with pytest.raises(TypeError, match="missing 1 required positional argument: 'layers'"): | ||
| takeScreenshot( | ||
| date=datetime(2014, 1, 1, 23, 59, 59), | ||
| imageScale=2.4204409, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.