Spaces:
Sleeping
Sleeping
| 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"} |