Merge pull request #30 from sepandhaghighi/dev-sadra

Minor Refactor
pull/36/head
Sepand Haghighi 2021-09-30 14:56:28 +03:30 zatwierdzone przez GitHub
commit fd8813f819
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 11 dodań i 7 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
"""Samila modules."""
from .genimage import GenerativeImage
from .params import Projection,VALID_COLORS
from .params import Projection, VALID_COLORS

Wyświetl plik

@ -4,6 +4,7 @@
import requests
from .params import Projection, DEFAULT_PROJECTION, VALID_COLORS, NFT_STORAGE_API, NFT_STORAGE_SUCCESS_MESSAGE
def float_range(start, stop, step):
"""
Generate float range.
@ -68,6 +69,7 @@ def filter_color(color):
return VALID_COLORS[distance_list.index(min_distance)]
return None
def filter_projection(projection):
"""
Filter given projection.
@ -80,6 +82,7 @@ def filter_projection(projection):
return projection.value
return DEFAULT_PROJECTION
def nft_storage_upload(api_key, data):
"""
Upload file to nft.storage.
@ -93,7 +96,10 @@ def nft_storage_upload(api_key, data):
result = {"status": True, "message": NFT_STORAGE_SUCCESS_MESSAGE}
try:
headers = {'Authorization': 'Bearer {0}'.format(api_key)}
response = requests.post(url=NFT_STORAGE_API,data=data,headers=headers)
response = requests.post(
url=NFT_STORAGE_API,
data=data,
headers=headers)
response_json = response.json()
if response_json["ok"]:
return result
@ -104,4 +110,3 @@ def nft_storage_upload(api_key, data):
result["status"] = False
result["message"] = str(e)
return result

Wyświetl plik

@ -108,7 +108,7 @@ class GenerativeImage:
ax.add_artist(ax.patch)
self.fig = fig
def nft_storage(self,api_key):
def nft_storage(self, api_key):
"""
Upload image to nft.storage.
@ -118,5 +118,5 @@ class GenerativeImage:
"""
buf = io.BytesIO()
self.fig.savefig(buf, format='png')
response = nft_storage_upload(api_key=api_key,data=buf.getvalue())
return response
response = nft_storage_upload(api_key=api_key, data=buf.getvalue())
return response

Wyświetl plik

@ -20,7 +20,6 @@ NFT_STORAGE_API = "https://api.nft.storage/upload"
NFT_STORAGE_SUCCESS_MESSAGE = "Everything seems good"
class Projection(Enum):
"""
Samila Projection type class.