{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import urllib.request, json\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import os\n",
    "import requests\n",
    "import cv2\n",
    "import json\n",
    "from urllib.request import urlopen\n",
    "from skimage.metrics import structural_similarity as compare_ssim"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('NFT+Hackathon+Traits+Dataset.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>collection</th>\n",
       "      <th>contract</th>\n",
       "      <th>token_id</th>\n",
       "      <th>nft_url</th>\n",
       "      <th>trait_type</th>\n",
       "      <th>value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>695998</th>\n",
       "      <td>44430</td>\n",
       "      <td>pudgy_penguins</td>\n",
       "      <td>0xbd3531da5cf5857e7cfaa92426877b022e612cf8</td>\n",
       "      <td>8886</td>\n",
       "      <td>https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...</td>\n",
       "      <td>Background</td>\n",
       "      <td>Blue</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>695999</th>\n",
       "      <td>44431</td>\n",
       "      <td>pudgy_penguins</td>\n",
       "      <td>0xbd3531da5cf5857e7cfaa92426877b022e612cf8</td>\n",
       "      <td>8886</td>\n",
       "      <td>https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...</td>\n",
       "      <td>Skin</td>\n",
       "      <td>Normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696000</th>\n",
       "      <td>44432</td>\n",
       "      <td>pudgy_penguins</td>\n",
       "      <td>0xbd3531da5cf5857e7cfaa92426877b022e612cf8</td>\n",
       "      <td>8886</td>\n",
       "      <td>https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...</td>\n",
       "      <td>Body</td>\n",
       "      <td>Hawaiian Shirt</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696001</th>\n",
       "      <td>44433</td>\n",
       "      <td>pudgy_penguins</td>\n",
       "      <td>0xbd3531da5cf5857e7cfaa92426877b022e612cf8</td>\n",
       "      <td>8886</td>\n",
       "      <td>https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...</td>\n",
       "      <td>Face</td>\n",
       "      <td>Handlebar Bear</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696002</th>\n",
       "      <td>44434</td>\n",
       "      <td>pudgy_penguins</td>\n",
       "      <td>0xbd3531da5cf5857e7cfaa92426877b022e612cf8</td>\n",
       "      <td>8886</td>\n",
       "      <td>https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...</td>\n",
       "      <td>Head</td>\n",
       "      <td>Bucket Hat Green</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696003</th>\n",
       "      <td>44435</td>\n",
       "      <td>pudgy_penguins</td>\n",
       "      <td>0xbd3531da5cf5857e7cfaa92426877b022e612cf8</td>\n",
       "      <td>8887</td>\n",
       "      <td>https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...</td>\n",
       "      <td>Background</td>\n",
       "      <td>Blue</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696004</th>\n",
       "      <td>44436</td>\n",
       "      <td>pudgy_penguins</td>\n",
       "      <td>0xbd3531da5cf5857e7cfaa92426877b022e612cf8</td>\n",
       "      <td>8887</td>\n",
       "      <td>https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...</td>\n",
       "      <td>Skin</td>\n",
       "      <td>Olive Green</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696005</th>\n",
       "      <td>44437</td>\n",
       "      <td>pudgy_penguins</td>\n",
       "      <td>0xbd3531da5cf5857e7cfaa92426877b022e612cf8</td>\n",
       "      <td>8887</td>\n",
       "      <td>https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...</td>\n",
       "      <td>Body</td>\n",
       "      <td>Puffer Green</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696006</th>\n",
       "      <td>44438</td>\n",
       "      <td>pudgy_penguins</td>\n",
       "      <td>0xbd3531da5cf5857e7cfaa92426877b022e612cf8</td>\n",
       "      <td>8887</td>\n",
       "      <td>https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...</td>\n",
       "      <td>Face</td>\n",
       "      <td>Handlebar Bear</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696007</th>\n",
       "      <td>44439</td>\n",
       "      <td>pudgy_penguins</td>\n",
       "      <td>0xbd3531da5cf5857e7cfaa92426877b022e612cf8</td>\n",
       "      <td>8887</td>\n",
       "      <td>https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...</td>\n",
       "      <td>Head</td>\n",
       "      <td>Flat Cap Tan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        Unnamed: 0      collection  \\\n",
       "695998       44430  pudgy_penguins   \n",
       "695999       44431  pudgy_penguins   \n",
       "696000       44432  pudgy_penguins   \n",
       "696001       44433  pudgy_penguins   \n",
       "696002       44434  pudgy_penguins   \n",
       "696003       44435  pudgy_penguins   \n",
       "696004       44436  pudgy_penguins   \n",
       "696005       44437  pudgy_penguins   \n",
       "696006       44438  pudgy_penguins   \n",
       "696007       44439  pudgy_penguins   \n",
       "\n",
       "                                          contract  token_id  \\\n",
       "695998  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8886   \n",
       "695999  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8886   \n",
       "696000  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8886   \n",
       "696001  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8886   \n",
       "696002  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8886   \n",
       "696003  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8887   \n",
       "696004  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8887   \n",
       "696005  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8887   \n",
       "696006  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8887   \n",
       "696007  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8887   \n",
       "\n",
       "                                                  nft_url  trait_type  \\\n",
       "695998  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...  Background   \n",
       "695999  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Skin   \n",
       "696000  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Body   \n",
       "696001  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Face   \n",
       "696002  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Head   \n",
       "696003  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...  Background   \n",
       "696004  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Skin   \n",
       "696005  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Body   \n",
       "696006  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Face   \n",
       "696007  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Head   \n",
       "\n",
       "                   value  \n",
       "695998              Blue  \n",
       "695999            Normal  \n",
       "696000    Hawaiian Shirt  \n",
       "696001    Handlebar Bear  \n",
       "696002  Bucket Hat Green  \n",
       "696003              Blue  \n",
       "696004       Olive Green  \n",
       "696005      Puffer Green  \n",
       "696006    Handlebar Bear  \n",
       "696007      Flat Cap Tan  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://ikzttp.mypinata.cloud/ipfs/QmQFkLSQysj94s5GvTHPyzTxrawwtjgiiYS2TBLgrvw8CW/1\n"
     ]
    }
   ],
   "source": [
    "print(df.iloc[7]['nft_url'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Unnamed: 0', 'collection', 'contract', 'token_id', 'nft_url',\n",
       "       'trait_type', 'value'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.keys()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Create database of small size images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "image_data = {}\n",
    "for ix, row in df.iloc[: 1000].iterrows():\n",
    "  try:\n",
    "    data_url = row['nft_url']\n",
    "    r = requests.get(data_url)\n",
    "    image_name = str(row['collection']) + '_' + str(row['token_id'])\n",
    "    image_url = r.json()['image']\n",
    "    image_data.setdefault(image_name, image_url)\n",
    "  except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "for image_name, image_url in image_data.items():\n",
    "  try:\n",
    "    user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'\n",
    "    headers={'User-Agent':user_agent,} \n",
    "\n",
    "    request=urllib.request.Request(image_url,None,headers) #The assembled request\n",
    "    response = urllib.request.urlopen(request)\n",
    "    \n",
    "#     resp = urlopen(image_url)\n",
    "    image = np.asarray(bytearray(response.read()), dtype=\"uint8\")\n",
    "    image = cv2.imdecode(image, cv2.IMREAD_COLOR)\n",
    "    img_path = './images1/' + str(image_name) + '.jpg'\n",
    "#     print(img.shape)\n",
    "    img_resized = cv2.resize(image, (64, 64), interpolation = cv2.INTER_AREA)\n",
    "    cv2.imwrite(img_path, img_resized)\n",
    "  except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Test image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://ikzttp.mypinata.cloud/ipfs/QmYDvPAXtiJg7s8JdRBSLWdgSphQdac8j1YuQNNxcGE1hg/13.png\n"
     ]
    }
   ],
   "source": [
    "ex_url = df.iloc[100]['nft_url']\n",
    "r = requests.get(ex_url)\n",
    "print(r.json()['image'])\n",
    "image_url = r.json()['image']\n",
    "user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'\n",
    "headers={'User-Agent':user_agent,} \n",
    "\n",
    "request=urllib.request.Request(image_url,None,headers) #The assembled request\n",
    "response = urllib.request.urlopen(request)\n",
    "# resp = urlopen(image_url , timeout=10)\n",
    "image = np.asarray(bytearray(response.read()), dtype=\"uint8\")\n",
    "test_image = cv2.imdecode(image, cv2.IMREAD_COLOR)\n",
    "img_resized = cv2.resize(test_image, (500, 500), interpolation = cv2.INTER_AREA)\n",
    "cv2.imshow('img_resized', img_resized)\n",
    "cv2.waitKey() & 0xFF == ord('q')\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Find the test image in database"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9905571084662425 azuki_13.jpg\n"
     ]
    }
   ],
   "source": [
    "test_image_resized = cv2.resize(test_image, (64, 64), interpolation = cv2.INTER_AREA)\n",
    "ssim_list = []\n",
    "for image_name in os.listdir('./images1'):\n",
    "  img = cv2.imread('./images1/' + image_name)\n",
    "  ssim = compare_ssim(img, test_image_resized, multichannel=True)\n",
    "  ssim_list.append(ssim)\n",
    "print(max(ssim_list), os.listdir('./images1')[ssim_list.index(max(ssim_list))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "        Unnamed: 0      collection  \\\n",
      "695343       43775  pudgy_penguins   \n",
      "695344       43776  pudgy_penguins   \n",
      "695345       43777  pudgy_penguins   \n",
      "695346       43778  pudgy_penguins   \n",
      "695347       43779  pudgy_penguins   \n",
      "\n",
      "                                          contract  token_id  \\\n",
      "695343  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8755   \n",
      "695344  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8755   \n",
      "695345  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8755   \n",
      "695346  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8755   \n",
      "695347  0xbd3531da5cf5857e7cfaa92426877b022e612cf8      8755   \n",
      "\n",
      "                                                  nft_url  trait_type  \\\n",
      "695343  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...  Background   \n",
      "695344  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Skin   \n",
      "695345  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Body   \n",
      "695346  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Face   \n",
      "695347  https://ipfs.io/ipfs/QmWXJXRdExse2YHRY21Wvh4pj...        Head   \n",
      "\n",
      "                   value  \n",
      "695343              Blue  \n",
      "695344            Normal  \n",
      "695345          Overalls  \n",
      "695346    Circle Glasses  \n",
      "695347  Grizzly Bear Hat  \n"
     ]
    }
   ],
   "source": [
    "image_url = os.listdir('./images')[ssim_list.index(max(ssim_list))].split('.')[0]\n",
    "if max(ssim_list) > 0.9:\n",
    "  collection = '_'.join(os.listdir('./images')[ssim_list.index(max(ssim_list))].split('.')[0].split('_')[: -1])\n",
    "  token_id = os.listdir('./images')[ssim_list.index(max(ssim_list))].split('.')[0].split('_')[-1]\n",
    "  info = df[(df['collection'] == collection) & (df['token_id'] == int(token_id))]\n",
    "  print(info)\n",
    "else:\n",
    "  print('Image is not from dataset.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_sales = pd.read_csv('NFT+Hackathon+Sales+Dataset.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>blockNumber</th>\n",
       "      <th>timeStamp</th>\n",
       "      <th>hash</th>\n",
       "      <th>from</th>\n",
       "      <th>contractAddress</th>\n",
       "      <th>to</th>\n",
       "      <th>tokenID</th>\n",
       "      <th>tokenName</th>\n",
       "      <th>tokenSymbol</th>\n",
       "      <th>gasPrice</th>\n",
       "      <th>currency</th>\n",
       "      <th>amount</th>\n",
       "      <th>amountUsd</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>431398</th>\n",
       "      <td>14473393</td>\n",
       "      <td>1648452996</td>\n",
       "      <td>0xa0742c124b822bab20b0b85436ce781b62327eb863e8...</td>\n",
       "      <td>0x8b4ad8680a98b3dc0210eb4f21a69124211346e5</td>\n",
       "      <td>0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b</td>\n",
       "      <td>0x9cfb3e1c528253dcb1754a266f9f95540b41e446</td>\n",
       "      <td>17241</td>\n",
       "      <td>CloneX</td>\n",
       "      <td>CloneX</td>\n",
       "      <td>21145077548</td>\n",
       "      <td>ETH</td>\n",
       "      <td>14.99</td>\n",
       "      <td>49797.533594</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>431399</th>\n",
       "      <td>14473553</td>\n",
       "      <td>1648455050</td>\n",
       "      <td>0x480a70e101ad4516226baa0514594540f22c4fe26901...</td>\n",
       "      <td>0x55c05c91a859493a8b3a1017269ca706e0feb344</td>\n",
       "      <td>0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b</td>\n",
       "      <td>0xc9b77effa94b599f326c3d76641f63f0979b4c67</td>\n",
       "      <td>7254</td>\n",
       "      <td>CloneX</td>\n",
       "      <td>CloneX</td>\n",
       "      <td>21820224805</td>\n",
       "      <td>ETH</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>431400</th>\n",
       "      <td>14473558</td>\n",
       "      <td>1648455130</td>\n",
       "      <td>0xdad0473a6aa703d5c1bc1d2bdcee6df07991e65eecc3...</td>\n",
       "      <td>0xf0c55da3a8274f6843434df0da437ed4ac0dd310</td>\n",
       "      <td>0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b</td>\n",
       "      <td>0xf2e03bb3bae583d72d750b3ef443372f92cf2c24</td>\n",
       "      <td>9303</td>\n",
       "      <td>CloneX</td>\n",
       "      <td>CloneX</td>\n",
       "      <td>23763705682</td>\n",
       "      <td>ETH</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>431401</th>\n",
       "      <td>14473606</td>\n",
       "      <td>1648455681</td>\n",
       "      <td>0x82aa9c3f16b9b5d440325fb09d5004e8a514a2003e03...</td>\n",
       "      <td>0xeef2c87291d8b74537260339f50fbc1f53b6a660</td>\n",
       "      <td>0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b</td>\n",
       "      <td>0xa5ee824f94abb9e3dc037815cc4727f76ab851d4</td>\n",
       "      <td>1818</td>\n",
       "      <td>CloneX</td>\n",
       "      <td>CloneX</td>\n",
       "      <td>23771779965</td>\n",
       "      <td>ETH</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>431402</th>\n",
       "      <td>14473637</td>\n",
       "      <td>1648456149</td>\n",
       "      <td>0x16cefb107a731b767d1e4eded3f3b3f81986506f2e9b...</td>\n",
       "      <td>0x00cd05371a28d91ef833016f2aeceed5defd95e0</td>\n",
       "      <td>0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b</td>\n",
       "      <td>0x47da18cff5533b95435d6ee0ed8179f5daadac24</td>\n",
       "      <td>13596</td>\n",
       "      <td>CloneX</td>\n",
       "      <td>CloneX</td>\n",
       "      <td>21262054721</td>\n",
       "      <td>ETH</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        blockNumber   timeStamp  \\\n",
       "431398     14473393  1648452996   \n",
       "431399     14473553  1648455050   \n",
       "431400     14473558  1648455130   \n",
       "431401     14473606  1648455681   \n",
       "431402     14473637  1648456149   \n",
       "\n",
       "                                                     hash  \\\n",
       "431398  0xa0742c124b822bab20b0b85436ce781b62327eb863e8...   \n",
       "431399  0x480a70e101ad4516226baa0514594540f22c4fe26901...   \n",
       "431400  0xdad0473a6aa703d5c1bc1d2bdcee6df07991e65eecc3...   \n",
       "431401  0x82aa9c3f16b9b5d440325fb09d5004e8a514a2003e03...   \n",
       "431402  0x16cefb107a731b767d1e4eded3f3b3f81986506f2e9b...   \n",
       "\n",
       "                                              from  \\\n",
       "431398  0x8b4ad8680a98b3dc0210eb4f21a69124211346e5   \n",
       "431399  0x55c05c91a859493a8b3a1017269ca706e0feb344   \n",
       "431400  0xf0c55da3a8274f6843434df0da437ed4ac0dd310   \n",
       "431401  0xeef2c87291d8b74537260339f50fbc1f53b6a660   \n",
       "431402  0x00cd05371a28d91ef833016f2aeceed5defd95e0   \n",
       "\n",
       "                                   contractAddress  \\\n",
       "431398  0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b   \n",
       "431399  0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b   \n",
       "431400  0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b   \n",
       "431401  0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b   \n",
       "431402  0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b   \n",
       "\n",
       "                                                to  tokenID tokenName  \\\n",
       "431398  0x9cfb3e1c528253dcb1754a266f9f95540b41e446    17241    CloneX   \n",
       "431399  0xc9b77effa94b599f326c3d76641f63f0979b4c67     7254    CloneX   \n",
       "431400  0xf2e03bb3bae583d72d750b3ef443372f92cf2c24     9303    CloneX   \n",
       "431401  0xa5ee824f94abb9e3dc037815cc4727f76ab851d4     1818    CloneX   \n",
       "431402  0x47da18cff5533b95435d6ee0ed8179f5daadac24    13596    CloneX   \n",
       "\n",
       "       tokenSymbol     gasPrice currency  amount     amountUsd  \n",
       "431398      CloneX  21145077548      ETH   14.99  49797.533594  \n",
       "431399      CloneX  21820224805      ETH    0.00      0.000000  \n",
       "431400      CloneX  23763705682      ETH    0.00      0.000000  \n",
       "431401      CloneX  23771779965      ETH    0.00      0.000000  \n",
       "431402      CloneX  21262054721      ETH    0.00      0.000000  "
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_sales.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Azuki\n",
      "    blockNumber   timeStamp  \\\n",
      "13     13988541  1641961048   \n",
      "\n",
      "                                                 hash  \\\n",
      "13  0xc208fdb2f133bda64522fececd6518a565aaa6e8801b...   \n",
      "\n",
      "                                          from  \\\n",
      "13  0x0000000000000000000000000000000000000000   \n",
      "\n",
      "                               contractAddress  \\\n",
      "13  0xed5af388653567af2f388e6224dc7c4b3241c544   \n",
      "\n",
      "                                            to  tokenID tokenName tokenSymbol  \\\n",
      "13  0xd45058bf25bbd8f586124c479d384c8c708ce23a       13     Azuki       AZUKI   \n",
      "\n",
      "        gasPrice currency  amount  amountUsd  \n",
      "13  144500135604      ETH     0.0        0.0  \n"
     ]
    }
   ],
   "source": [
    "image_url = os.listdir('./images1')[ssim_list.index(max(ssim_list))].split('.')[0]\n",
    "if max(ssim_list) > 0.9:\n",
    "  collection = '_'.join(os.listdir('./images1')[ssim_list.index(max(ssim_list))].split('.')[0].split('_')[: -1])\n",
    "  collection = collection[0].upper() + collection[1:]\n",
    "  print(collection)\n",
    "  token_id = os.listdir('./images1')[ssim_list.index(max(ssim_list))].split('.')[0].split('_')[-1]\n",
    "  info = df_sales[(df_sales['tokenName'] == collection) & (df_sales['tokenID'] == int(token_id))]\n",
    "  print(info)\n",
    "else:\n",
    "  print('Image is not from dataset.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
