-
Notifications
You must be signed in to change notification settings - Fork 7
Call the VENFT App Server API from Python
fyziktom edited this page Dec 1, 2021
·
1 revision
This code is simple example of the call of the VENFT App Server API from the Python code:
# you will need to install "request" library
# $ pip install requests
import requests
import json
from types import SimpleNamespace
from requests.exceptions import HTTPError
apicommand = 'https://venftappserver.azurewebsites.net/api/GetNFT/'
firstnft = '34b610c345c214731f97c53889ef1f2028da036032359cdf6755b48f2cefbb4e'
secondnft = 'df95849f4bd791178a25a9e4dcb9ef512cc671a48631cd78ab3f20aeb4d515a7'
for nfthash in [ firstnft, secondnft]:
try:
print('Requesting the API command:')
print('command: ' + apicommand)
print('nft hash: ' + nfthash)
print(' ')
response = requests.get(apicommand + nfthash)
print('NFT Data: ')
nft = json.loads(response.content, object_hook=lambda d: SimpleNamespace(**d))
print('Type: ' + nft.typeText)
print('Name: ' + nft.name)
print('Description: ' + nft.description)
print('Author: ' + nft.author)
print('Image Link: ' + nft.imageLink)
print('Tags: ' + nft.tags)
print('---------------------')
print(' ')
# If the response was successful, no Exception will be raised
response.raise_for_status()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # Python 3.6
except Exception as err:
print(f'Other error occurred: {err}') # Python 3.6
else:
print('Success!')
print('------------------------------')
print('Request page with data demo: ')
apicommand = 'https://venftappserver.azurewebsites.net/api/GetPublicSellNFTsPage/'
for page in range(1):
try:
print('Requesting the API command:')
print('command: ' + apicommand)
print('nfts page: ' + nfthash)
print(' ')
response = requests.get(apicommand + str(page))
print('NFTs Data: ')
print('-----------')
nfts = json.loads(response.content, object_hook=lambda d: SimpleNamespace(**d))
for onenft in nfts:
print('NFT Data: ')
print('Type: ' + onenft.typeText)
print('Name: ' + onenft.name)
print('---------------------')
print(' ')
# If the response was successful, no Exception will be raised
response.raise_for_status()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # Python 3.6
except Exception as err:
print(f'Other error occurred: {err}') # Python 3.6
else:
print('Success!')