Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.8 kB
7
Indexable
Never
import random
import boto3
from faker import Faker
fake = Faker()
from datetime import datetime 


# {
#     "ID" : "8",
#     "domainName": "github.com",
#     "nameServers": ["sg1.domain_name.com", "sg2.domain_name.com"],
#     "registrationDate": "2021-03-27",
#     "expiryDate": "2024-12-09"
# }

domain_list = ['buff163.com', 'twitter.com', 'youtube.com', 'gmail.com', 'facebook.com', 'dmarket.com',
               'bitskins.com', 'instagram.com', 'vnexpress.net', 'wikipedia.org', 'github.com',
               'learn.cantrill.io', 'shadowpay.com', 'kenh14.vn', 'schannel.vn', 'thegioididong.com',
               'cellphones.com.vn']

def Generate_random_records(cnt) :
    ID = str(cnt)
    domainName = domain_list[random.randint(1, 16)]
    nameServers = "sg." + domainName
    
    registrationDate =  fake.date_between(datetime(2021, 12, 12), datetime.now())
    expiryDate = fake.date_between(datetime.now(), datetime(2023, 11, 1))

    registrationDate = str(registrationDate)
    expiryDate = str(expiryDate)

    cnt += 1
    return ID, domainName, nameServers, registrationDate, expiryDate
    
def Insert_records(cnt) :
    
    data = Generate_random_records(cnt)
    item_data = {
        'ID'                : {'S' : data[0]},
        'domainName'        : {'S' : data[1]},
        'nameServers'       : {'S' : data[2]},
        "registrationDate"  : {'S' : data[3]},
        "expiryDate"        : {'S' : data[4]},
        "dummyCol"          : {'S' : "A"}
    }

    print(item_data)
    return item_data 
    

dynamoDB = boto3.client('dynamodb')
table_name = "test-table"
# n = len(domain_list)
n = 9
for i in range(n) : 
    dynamoDB.put_item(
        TableName = table_name,
        Item = Insert_records(i + 1)
    )