Skip to content

Instantly share code, notes, and snippets.

@jackty9
jackty9 / nft_python_collage.py
Last active February 23, 2022 19:01
A collage to join 50 images in a 10 x 5 arrangement.
# Import necessary libraries
from PIL import Image
import random
# Connect to Github repo to load images for the collage
!rm -r /content/NFT_tutorial_python
!git clone https://github.com/jackty9/NFT_tutorial_python.git
# Define the size of the collage
collage = Image.new("RGBA", (5000,2500), color=(255,255,255,255))
@jackty9
jackty9 / nft_python_output_generated_images.py
Created February 17, 2022 23:56
Compose and output generated arts to designated folder
# Create a directory for output images
os.mkdir("/content/images/")
# Generate Images
for item in all_images:
im1 = Image.open(f'/content/NFT_tutorial_python/nft_raw_images/backgrounds/{background_files[item["Background"]]}.png').convert('RGBA')
im2 = Image.open(f'/content/NFT_tutorial_python/nft_raw_images/triangles/{triangle_files[item["Triangle"]]}.png').convert('RGBA')
im3 = Image.open(f'/content/NFT_tutorial_python/nft_raw_images/circles/{circle_files[item["Circle"]]}.png').convert('RGBA')
im4 = Image.open(f'/content/NFT_tutorial_python/nft_raw_images/squares/{square_files[item["Square"]]}.png').convert('RGBA')
@jackty9
jackty9 / nft_python_define_arts_generation_functions.py
Last active February 17, 2022 23:31
Define functions to layer traits, generate NFT arts, and assign token IDs
# Generate Traits
# Number of random unique images to be generated
TOTAL_IMAGES = 50
all_images = []
# A recursive function to generate unique image combinations
def create_new_image():
@jackty9
jackty9 / nft_python_define_image_traits.py
Last active February 16, 2022 00:39
Assign the weightages for different traits as well as mapping image file names
# Each image is made up a series of traits
# The weitages for each trait distribute the rarity and add up to 100%
background = ["Silver", "Salmon", "Cantaloupe", "Mocha", "Teal"]
background_weights = [40, 30, 15, 10, 5]
triangle = ["Red", "Orange", "Yellow", "Green", "Blue"]
triangle_weights = [40, 30, 15, 10, 5]
circle = ["Red", "Orange", "Yellow", "Green", "Blue"]
@jackty9
jackty9 / nft_python_setting_up.py
Last active July 22, 2022 05:12
Import necessary libraries and cloning Github repo for raw images to generate NFT arts
#import necessary libraries
from PIL import Image
import random
import json
import os
#connect to Github repo to load raw images and metadata file
!rm -r /content/NFT_tutorial_python
!git clone https://github.com/jackty9/NFT_tutorial_python.git
@jackty9
jackty9 / datetime_python_conditionally_compare.py
Last active December 13, 2021 21:52
Snippets to conditionally work with datetime
#uncomment to import library
#import pandas as pd
#import datetime
#create first datetime dataframe df1
df1 = pd.DataFrame(
pd.to_datetime(["13:45:33", '14:17:25',"14:13:25", "15:16:43", "16:51:19"]),
columns=["MsgTime"],
)
print(df1)
@jackty9
jackty9 / datetime_python_timezone_calculations.py
Last active December 12, 2021 22:57
Snippets to work with different time zones
#uncomment to import library
#import pandas as pd
#from datetime import datetime
#import pytz, tzlocal
#convert a naive datetime to an aware datetime
dt_naive = pd.to_datetime('2021-11-27T12:24:30')
japan = pytz.timezone("Asia/Tokyo")
dt_aware = dt_naive.tz_localize(japan)
print(dt_aware)
@jackty9
jackty9 / datetime_python_string_to_datetime.py
Last active November 22, 2021 21:58
Snippets to convert strings into datetime format
#uncomment to import library
#import pandas as pd
#import datetime as dt
#converting string into datetime
df1 = pd.DataFrame(
{
"DateTime": pd.to_datetime(["2021-11-13 13:45:33", '2021-11-14 14:13:25',"2021-11-15 14:39:25", "2021-11-16 15:16:43", "2021-11-17 16:51:19"]),
}
)
from google.colab import files
customers_df.to_csv('customers_df.csv')
files.download('customers_df.csv')
@jackty9
jackty9 / faker_python_generate_fake_data
Last active August 15, 2021 15:00
Snippets to generate fake data
import pandas as pd
import random
from faker import Faker
from random import randrange
from datetime import datetime
nr_of_customers = 1000
fake = Faker('de_DE')