* feat : Gateway class added

* feat : gateway parameter added to nft_storage method

* doc : docstring updated

* fix : Gateway enum added to init file

* fix : Gateway class updated

* fix : tests updated

* fix : NFT_STORAGE_LINK removed

* doc : CHANGELOG updated

* doc : README.md updated

* fix : minor edit in nft_upload_test.py

* fix : minor edit in nft_upload_test.py
pull/198/head
Sepand Haghighi 2023-11-28 10:06:05 +03:30 zatwierdzone przez GitHub
rodzic bbb1f14f45
commit 1214f1768b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 70 dodań i 10 usunięć

Wyświetl plik

@ -7,11 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- `get_cmap` function
- `Gateway` enum
### Changed
- minor edits in `functions.py`
- `DEFAULT_CMAP` renamed to `DEFAULT_CMAP_NAME`
- `pillow` added to conda dependencies
- `codecov` removed from `dev-requirements.txt`
- `gateway` parameter added to `nft_storage` method
- Test system modified
- `README.md` updated
## [1.1] - 2023-04-05

Wyświetl plik

@ -261,7 +261,15 @@ or
{'status': {'image': True, 'data':True}, 'message': {'image':'IMAGE_FILE_LINK', 'data':'DATA_FILE_LINK'}
```
You have the option to choose a specific IPFS gateway:
```pycon
>>> from samila import Gateway
>>> g.nft_storage(api_key="API_KEY", upload_data=True, gateway=Gateway.DWEB)
{'status': {'image': True, 'data':True}, 'message': {'image':'IMAGE_FILE_LINK', 'data':'DATA_FILE_LINK'}
```
* Default timeout is **3000** seconds
* Default gateway is **IPFS_IO**
### Save image
Save generated image

Wyświetl plik

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""Samila modules."""
from .genimage import GenerativeImage
from .params import Projection, Marker, VALID_COLORS, SAMILA_VERSION
from .params import Projection, Marker, Gateway, VALID_COLORS, SAMILA_VERSION
from .errors import samilaDataError, samilaGenerateError
__version__ = SAMILA_VERSION

Wyświetl plik

@ -14,7 +14,7 @@ from .params import SAMILA_VERSION
from .params import DEFAULT_MARKER, DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE, DEFAULT_DEPTH
from .params import DEFAULT_CMAP_NAME, DEFAULT_CMAP_RANGE, DEFAULT_ROTATION
from .params import DEFAULT_BACKGROUND_COLOR, DEFAULT_SPOT_SIZE, DEFAULT_PROJECTION, DEFAULT_ALPHA, DEFAULT_LINEWIDTH
from .params import Projection, Marker, VALID_COLORS, HEX_COLOR_PATTERN, NFT_STORAGE_API, NFT_STORAGE_LINK, OVERVIEW
from .params import Projection, Marker, VALID_COLORS, HEX_COLOR_PATTERN, NFT_STORAGE_API, OVERVIEW
from .params import DATA_TYPE_ERROR, DATA_FORMAT_ERROR, CONFIG_TYPE_ERROR, CONFIG_FORMAT_ERROR, PLOT_DATA_ERROR, CONFIG_NO_STR_FUNCTION_ERROR
from .params import NO_FIG_ERROR_MESSAGE, FIG_SAVE_SUCCESS_MESSAGE, NFT_STORAGE_SUCCESS_MESSAGE, SAVE_NO_DATA_ERROR
from .params import INVALID_COLOR_TYPE_ERROR, COLOR_SIZE_ERROR
@ -515,7 +515,7 @@ def _GI_initializer(g, function1, function2):
g.missed_points_number = 0
def nft_storage_upload(api_key, data, timeout):
def nft_storage_upload(api_key, data, timeout, gateway):
"""
Upload file to nft.storage.
@ -525,6 +525,8 @@ def nft_storage_upload(api_key, data, timeout):
:type data: binary
:param timeout: upload timeout (in seconds)
:type timeout: int
:param gateway: IPFS gateway
:type gateway: Gateway enum
:return: result as dict
"""
result = {"status": True, "message": NFT_STORAGE_SUCCESS_MESSAGE}
@ -537,7 +539,7 @@ def nft_storage_upload(api_key, data, timeout):
timeout=timeout)
response_json = response.json()
if response_json["ok"]:
result["message"] = NFT_STORAGE_LINK.format(
result["message"] = gateway.value.format(
response_json['value']['cid'])
return result
result["status"] = False

Wyświetl plik

@ -175,7 +175,8 @@ class GenerativeImage:
upload_data=False,
upload_config=False,
depth=None,
timeout=3000):
timeout=3000,
gateway=Gateway.IPFS_IO):
"""
Upload image to nft.storage.
@ -189,6 +190,8 @@ class GenerativeImage:
:type depth: float
:param timeout: upload timeout (in seconds)
:type timeout: int
:param gateway: IPFS gateway
:type gateway: Gateway enum
:return: result as dict
"""
save_params_filter(self, depth)
@ -199,7 +202,8 @@ class GenerativeImage:
response = nft_storage_upload(
api_key=api_key,
data=buf.getvalue(),
timeout=timeout)
timeout=timeout,
gateway=gateway)
if upload_config == False and upload_data == False:
return response
result = {key: {'image': value} for key, value in response.items()}
@ -207,14 +211,16 @@ class GenerativeImage:
response = nft_storage_upload(
api_key=api_key,
data=json.dumps(get_config(self)),
timeout=timeout)
timeout=timeout,
gateway=gateway)
for key, value in response.items():
result[key]['config'] = value
if upload_data:
response = nft_storage_upload(
api_key=api_key,
data=json.dumps(get_data(self)),
timeout=timeout)
timeout=timeout,
gateway=gateway)
for key, value in response.items():
result[key]['data'] = value
return result

Wyświetl plik

@ -36,7 +36,6 @@ VALID_COLORS = list(
**matplotlib.colors.CSS4_COLORS).keys())
HEX_COLOR_PATTERN = r'^#(?:[0-9a-fA-F]{3}){1,2}$'
NFT_STORAGE_API = "https://api.nft.storage/upload"
NFT_STORAGE_LINK = "https://ipfs.io/ipfs/{}"
NFT_STORAGE_SUCCESS_MESSAGE = "Everything seems good."
FIG_SAVE_SUCCESS_MESSAGE = "Everything seems good."
DATA_SAVE_SUCCESS_MESSAGE = "Everything seems good."
@ -56,6 +55,36 @@ BOTH_COLOR_COMPLEMENT_WARNING = "It is not possible to set color and bgcolor to
COLOR_NOT_FOUND_WARNING = "color '{0}' not found. Replacing it with '{1}'"
class Gateway(Enum):
"""
IPFS gateway class.
>>> import samila
>>> gateway = samila.Gateway.IPFS_IO
"""
CID = "{0}"
IPFS_IO = "https://ipfs.io/ipfs/{0}"
GATEWAY_IPFS_IO = "https://gateway.ipfs.io/ipfs/{0}"
VIA0 = "https://via0.com/ipfs/{0}"
CLOUDFLARE_IPFS = "https://cloudflare-ipfs.com/ipfs/{0}"
HARDBIN = "https://hardbin.com/ipfs/{0}"
PINATA = "https://gateway.pinata.cloud/ipfs/{0}"
JORROPO = "https://jorropo.net/ipfs/{0}"
DWEB = "https://dweb.link/ipfs/{0}"
BEST_PRACTICE = "https://ipfs.best-practice.se/ipfs/{0}"
RUNFISSION = "https://ipfs.runfission.com/ipfs/{0}"
ARAGON_NETWORK = "https://ipfs.eth.aragon.network/ipfs/{0}"
TEXTILE = "https://hub.textile.io/ipfs/{0}"
EVERLAND = "https://{0}.ipfs.4everland.io"
CF_IPFS = "https://{0}.ipfs.cf-ipfs.com"
LITNET = "https://ipfs.litnet.work/ipfs/{0}"
JPU = "https://ipfs.jpu.jp/ipfs/{0}"
CZIP = "https://ipfs.czip.it/ipfs/{0}"
W3S = "https://{0}.ipfs.w3s.link"
GW3 = "https://{0}.ipfs.gw3.io"
class Projection(Enum):
"""
Samila Projection type class.

Wyświetl plik

@ -2,7 +2,7 @@
"""
>>> import os
>>> import time
>>> from samila import GenerativeImage, Projection
>>> from samila import GenerativeImage, Projection, Gateway
>>> from samila.params import VALID_COLORS
>>> g = GenerativeImage()
>>> g.generate()
@ -42,4 +42,17 @@ True
True
>>> result['status']["data"]
True
>>> status = False
>>> counter = 0
>>> while(status == False and counter<try_limit):
... result = g.nft_storage(api_key=NFT_STORAGE_API_KEY, upload_data=True, upload_config=True, gateway=Gateway.CID)
... counter = counter + 1
... status = all(result["status"].values())
... time.sleep(10)
>>> result['status']["image"]
True
>>> result['status']["data"]
True
>>> result['status']["config"]
True
"""