Spaces:
Sleeping
Sleeping
File size: 3,450 Bytes
1f72938 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
import base64
import os
import rsa
from datetime import date
import secrets
import string
import requests
import json
def generate_token_id(length):
characters = string.ascii_letters + string.digits # + string.punctuation
token = ''.join(secrets.choice(characters) for _ in range(length))
return token
# Examples for what will be generated
# 5!bA9H2f1q^...
# Xe7uM$4d9@...
# &3yTb1*8Z#...
# %pWqN7!6zX...
# @9oV!s6Rd2...
def get_today_date():
today = date.today()
return str(today)
# Example for what will be returned
# 2023-06-29
def generate_request(data):
url = 'http://ipygg-api-test-env.ap-east-1.elasticbeanstalk.com/SBT'
pubkey_path = os.path.join(os.path.dirname(__file__), '..', 'pubkey.pem')
with open(pubkey_path, 'rb') as f:
pubKey = rsa.PublicKey.load_pkcs1(f.read())
for key, value in data.items():
value_bytes = value.encode("utf-8")
encrypted_value = rsa.encrypt(value_bytes, pubKey)
encoded_value = base64.b64encode(encrypted_value)
data[key] = encoded_value
# Write the encrypted and encoded values to a file
with open("sbt_request.txt", "w") as f:
for key, value in data.items():
f.write(f"{key}: {value}\n\n")
# posting Json file to api
r = requests.post(url, data=data)
print(r.json)
def split_data(data):
request_id = "request1234"
# token_id = generate_token_id(501)
token_id = "12344321"
f = open('data1.txt', 'r')
with open('data1.txt') as f:
data_raw = f.read()
data = json.loads(data_raw)
if "avg_score" not in data.keys():
data["avg_score"] = "0"
legal_doc_data = {
"endpoint": "SBT",
"apiType": "store_legalDoc_verif",
"requestId": "request_id_id",
"date": get_today_date(), # a string
"tokenID": token_id,# a string
"docType": "HKID",
"nameDoc": data["name_on_id"], # a string; lower case with space separate; e.g. san chi nan
"docID": data["hkid"], # a string; with bracket (); e.g. G908833(1)
"docValidity": data["validity"], # a string; "True" or "False"
"dateOfIssue": data["issue_date"], # a string; month-year; e.g. 07-81
"matchingScore": str(data["avg_score"]) # a string; e.g. "0.957"
}
bank_statement_data = {
"endpoint": "SBT",
"apiType": "store_statement_verif",
"requestId": "request_id_bs",
"date": get_today_date(), # a string
"tokenID": token_id, # a string
"bank":data["bank"], #
"nameStatement":data["name_on_bs"], #
"address":data["address"], #
"asset": str(data["asset"]), # a string containing only numbers
"liability": data["liabilities"], # a string containing only numbers
"statementDate": data["date"], # a string
}
generate_request(legal_doc_data)
generate_request(bank_statement_data)
# demo structure of the data
# {"password2": "chingfuilau", "username": "Allenlau1111", "password1": "Allen02118173", "date": "2023-03-03 00:00:00",
# "credentialId": "testing123","requestID": "test_statements",
# "userId": "7893456",
# "endpoint": "SBT",
# "apiType": "metadata",
# 'tokenId':"500",
# "ipfsLink1": ".",
# "ipfsLink2": "..",
# "ipfsLink3": "...",
# "membershipStatus": "1"} |