This sample is to get specification for PallyCon Watermark APIs for python
This works on PYTHON
version :
- 3.7.x
Virtual Environments(a.k.a. Envs
) must be established and do all the tasks in this Envs.
In this project we use Anaconda 4.8.2
as Envs.
how to install virtual environments?
If you are not familiar with Envs, see the list below and choose one out of this.
Installation guide is here : How to create virtual environments with venv and conda in Python
list of virtual environments
- Anaconda
- miniconda
- venv
For Anaconda users, create a virtual environment using environment.yml
file and command.
environment.yml
file :
name: wm_api_request_sample {{or, set environment name}}
channels:
- defaults
dependencies:
- ca-certificates=2021.5.25
- certifi=2021.5.30
- openssl=1.1.1k
- pip=21.1.2
- pycrypto=2.6.1
- python=3.7.10
- pytz=2021.1
- setuptools=52.0.0
- sqlite=3.35.4
- vc=14.2
- vs2015_runtime=14.27.29016
- wheel=0.36.2
- wincertstore=0.2
prefix: {{set anaconda env directory}}
command :
conda env create -f environment.yml
For other environments users, install packages using requirements.txt
.
certifi==2021.5.30
pycrypto==2.6.1
pytz==2021.1
wincertstore==0.2
Clone this git repository and go to the sample.py
. This code below is from sample.py
.
NOTE
See UrlInfo
enum class for request url and it's method.
import json
from watermark.pallycon_wm_api import execute
from config.url_info import UrlInfo
"""
THIS IS A SAMPLE CODE FOR GENERATE PallyCon HTTP API specification.
"""
def generate(request_url: UrlInfo, **kwargs):
print('data requested', json.dumps(kwargs, indent=4))
# set the parameters for generate.
site_id = kwargs.get('site_id')
access_key = kwargs.get('access_key')
site_key = kwargs.get('site_key')
json_req = kwargs.get('json_req')
# get a result using execute function from module `pallycon_wm_api`
api_data_str = execute(site_id, access_key, site_key, json_req)
result = request_url.request_url_method(api_data_str, site_id)
print('result', json.dumps(result, indent=4))
json_str = {
"storage_type": "S3",
"region": "RG011"
}
# Sample Code
generate(UrlInfo.PACK_JOB_LIST,
site_id='TUTO',
site_key='lU5D8s3PWoLls3PWFWkClULlFWk5D8oC',
access_key='LT2FVJDp2Xr018zf4Di6lzvNOv3DKP20',
json_req=json.dumps(json_str))
data requested {
"site_id": "TUTO",
"site_key": "lU5D8s3PWoLls3PWFWkClULlFWk5D8oC",
"access_key": "LT2FVJDp2Xr018zf4Di6lzvNOv3DKP20",
"json_req": "{\"storage_type\": \"S3\", \"region\": \"RG011\"}"
}
result {
"description": "DETECT_REGISTER",
"pallycon-apidata": "eyJkYXRhIjogIjFoY0crOUhMckR1ZWlJTjlDWXQ4SVNvekIzY0x6Zy9Db2VHNE5PKzY2cW9WRWo5eEJ1S2JzZkNUaVM3KzZrWWoiLCAidGltZXN0YW1wIjogIjIwMjItMDMtMzBUMDg6Mjk6NTdaIiwgImhhc2giOiAibWlUaUxSbmh5ZnBWdmEyZHlVbXdHVHI1VzV3NUpkRmFrbnl0YXdFNTVzaz0ifQ==",
"url": "https://api.pallycon.com/api/v2/detect/TUTO/url?pallycon-apidata=eyJkYXRhIjogIjFoY0crOUhMckR1ZWlJTjlDWXQ4SVNvekIzY0x6Zy9Db2VHNE5PKzY2cW9WRWo5eEJ1S2JzZkNUaVM3KzZrWWoiLCAidGltZXN0YW1wIjogIjIwMjItMDMtMzBUMDg6Mjk6NTdaIiwgImhhc2giOiAibWlUaUxSbmh5ZnBWdmEyZHlVbXdHVHI1VzV3NUpkRmFrbnl0YXdFNTVzaz0ifQ==",
"method": "POST"
}
If want to see how it works, go to module pallycon.sample.watermark.pallycon_wm_api
. On the top of this module, there is a simple note how it works.
- get
site_id
,access_key
,site_key
, andjson_req
- encrypt
json_req
with_make_data()
.- make
timestamp
with_make_timestamp()
.- make
hash
with_make_hash()
.- return PallyCon Watermark API specificated String from the values
#2 ~ #4