File size: 15,126 Bytes
d1e2e7a 5584702 d1e2e7a 443d916 d1e2e7a 6ac2039 d1e2e7a 229c375 d1e2e7a 229c375 7cc11ca d1e2e7a 6a9aba4 d1e2e7a 6a9aba4 d1e2e7a 5584702 a778814 0f0d82b |
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
import requests
import typing
from typing import Optional
from datetime import datetime, timezone, timedelta
import discord
from discord.ext import commands
from discord import app_commands
from PIL import Image, ImageDraw, ImageFont, ImageColor, ImageFilter, ImageSequence
import json
from web3 import Web3
from eth_utils import to_checksum_address
import threading
# PolygonScan API ํค
api_key = "4H655NPT5229MKFE2NNHIS2GNZ3U4UTGT2"
with open("token.txt", "r", encoding='utf-8') as f:
token = f.read()
def first_time(timestamp):
timestamp = int(timestamp)
dt_object = datetime.fromtimestamp(timestamp, timezone.utc)
# Convert UTC to Korea Standard Time (KST)
kst = timezone(timedelta(hours=9)) # KST is UTC+9
dt_kst = dt_object.astimezone(kst)
t = dt_kst.strftime('%Y-%m-%d')
return str(t)
def web3_find(token_id):
# Web3 ํ๋ก๋ฐ์ด๋ ์ค์ (์ฌ๊ธฐ์๋ Infura ์ฌ์ฉ, ์์ ์ ํ๋ก์ ํธ ID๋ก ๋์ฒด)
INFURA_URL = "https://polygon-mainnet.infura.io/v3/16185d569adf4d00a04f2d2a200cf231"
web3 = Web3(Web3.HTTPProvider(INFURA_URL))
# ํ ํฐ ์ปจํธ๋ํธ ์ฃผ์ ๋ฐ ABI (์ต์ํ tokenURI ํจ์๋ฅผ ํฌํจํด์ผ ํจ)
token_contract_address = "0xA4B37bE40F7b231Ee9574c4b16b7DDb7EAcDC99B"
token_id
# ์ปจํธ๋ํธ ABI์ ์ผ๋ถ ์์ (์ค์ ABI๋ก ๋์ฒด ํ์)
contract_abi = [
{
"constant": True,
"inputs": [{"name": "_tokenId", "type": "uint256"}],
"name": "tokenURI",
"outputs": [{"name": "", "type": "string"}],
"payable": False,
"stateMutability": "view",
"type": "function"
},
]
# ์ปจํธ๋ํธ ์ธ์คํด์ค ์์ฑ
contract = web3.eth.contract(address=token_contract_address, abi=contract_abi)
# tokenURI ํธ์ถํ์ฌ ๋ฉํ๋ฐ์ดํฐ URI ๊ฐ์ ธ์ค๊ธฐ
token_uri = contract.functions.tokenURI(token_id).call()
# ๋ฉํ๋ฐ์ดํฐ URI์์ JSON ๋ฉํ๋ฐ์ดํฐ ๋ค์ด๋ก๋
metadata_response = requests.get(token_uri)
metadata = metadata_response.json()
# ๋ฉํ๋ฐ์ดํฐ์์ NFT ์ด๋ฆ ์ถ์ถ
nft_name = metadata.get("name", "Name not found")
print(f"NFT Name: {nft_name}")
return nft_name
def obj_srch(account_address):
# PolygonScan API URL ๊ตฌ์ฑ
contract_address = "0xA4B37bE40F7b231Ee9574c4b16b7DDb7EAcDC99B"
url = f"https://api.polygonscan.com/api?module=account&action=tokenbalance&contractaddress={contract_address}&address={account_address}&tag=latest&apikey={api_key}"
# API ์์ฒญ
response = requests.get(url)
# ์๋ต ํ์ธ ๋ฐ ์ฒ๋ฆฌ
if response.status_code == 200:
data = response.json()
balance = data.get('result')
if balance is not None:
# ERC-721์ ๋ณดํต 1 NFT๋น 1์ ๊ฐ์ง๋ฏ๋ก, balance๋ฅผ ์ง์ ๋ฐํ
real_balance = int(balance)
print(f"๊ณ์ ์ฃผ์ {account_address}๋(์) ํ ํฐ ์ปจํธ๋ํธ {contract_address}์ NFT๋ฅผ {real_balance}๊ฐ ๊ฐ์ง๊ณ ์์ต๋๋ค.")
return real_balance
else:
print("NFT ์์ก ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.")
else:
print("API ์์ฒญ์ ์คํจํ์ต๋๋ค.")
def como_srch(account_address):
tok = "0x58AeABfE2D9780c1bFcB713Bf5598261b15dB6e5"
url = f"https://api.polygonscan.com/api?module=account&action=tokenbalance&contractaddress={tok}&address={account_address}&tag=latest&apikey={api_key}"
response = requests.get(url)
# ์๋ต ํ์ธ
if response.status_code == 200:
data = response.json()
# ํ ํฐ ์๋ ์ถ๋ ฅ
balance = data.get('result')
if balance is not None:
real_balance = int(balance) / 10 ** 18
print(f"๊ณ์ ์ฃผ์ {account_address}๋(์) ํ ํฐ ์ฃผ์ {tok}์ ํ ํฐ์ {int(real_balance)}๊ฐ ๊ฐ์ง๊ณ ์์ต๋๋ค.")
return int(real_balance)
else:
print("ํ ํฐ ์๋ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.")
else:
print("API ์์ฒญ์ ์คํจํ์ต๋๋ค.")
def ad2id(input_str):
input_str = str(input_str)
input_str = to_checksum_address(input_str)
print(input_str)
base_url = "https://cache.nova.gd/user/v1"
users = []
error_message = None
try:
if input_str.startswith("0x"):
url = f"{base_url}/by-address/{input_str}"
response = requests.get(url)
if response.status_code == 200:
users = response.json() # 'by-address' ๊ฐ ๋ฆฌ์คํธ๋ฅผ ์ง์ ๋ฐํํ๋ค๊ณ ๊ฐ์
else:
error_message = f"Request failed with status code {response.status_code}"
except Exception as e:
error_message = str(e)
if error_message:
return "Error"
if not users:
return "Mint"
formatted_result = "".join(f"{user['nickname']}" for i, user in enumerate(users))
return formatted_result
def ad_srch(input_str):
if len(input_str) < 4:
return "4๊ธ์ ์ด์์ผ๋ก ์์ฑํด์ฃผ์ธ์."
base_url = "https://cache.nova.gd/user/v1"
url = f"{base_url}/search?query={input_str}"
response = requests.get(url)
data = response.json()
# 'address' ๊ฐ ์ถ์ถ
address = data['results'][0]['address']
print(address)
return address
def como_txt(text):
image_size = (180, 50)
image = Image.new('RGBA', image_size, (255, 255, 255, 0))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("Helvetica_Neue_LT_Std_75_Bold.otf", 50)
text_color = (200, 200, 200)
# ํ
์คํธ์ ๊ฒฝ๊ณ ์์ ๊ณ์ฐ
text_bbox = draw.textbbox((0, 0), text, font=font)
text_width = text_bbox[2] - text_bbox[0]
text_height = text_bbox[3] - text_bbox[1]
# ํ
์คํธ๋ฅผ ์ด๋ฏธ์ง ์ค์์ ์ ๋ ฌ
text_x = (image_size[0] - text_width) / 2
text_y = (image_size[1] - text_height) / 2
draw.text((text_x, text_y), text, fill=text_color, font=font)
return image
def acom(input_str):
if len(input_str) < 4:
return ["4๊ธ์ ์ด์์ผ๋ก ์์ฑํด์ฃผ์ธ์."]
base_url = "https://cache.nova.gd/user/v1"
url = f"{base_url}/search?query={input_str}"
response = requests.get(url)
data = response.json()
users = data.get("results", []) # 'search' ๊ฐ {"results": [...]} ํ์์ ๋ฐํํ๋ค๊ณ ๊ฐ์
if response.status_code != 200:
raise Exception(f"Request failed with status code {response.status_code}")
if not users:
return ["๊ฒ์ ๊ฒฐ๊ณผ ์์"]
# ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌ์คํธ ํํ๋ก ๋ฐํํ๊ธฐ ์ ์ ์ต๋ 25๊ฐ์ ๊ฒฐ๊ณผ๋ง ํฌํจ๋๋๋ก ์กฐ์
result_list = [user['nickname'] for user in users[:25]]
return result_list
def names(text, img, x = 124, y = 26):
text = str(text)
image = img
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("Helvetica_Neue_LT_Std_75_Bold.otf", 42)
text_color = (208, 211, 214)
draw.text((x, y), text, fill=text_color, font=font)
return image
async def name_auto(interaction: discord.Interaction, current: str) -> typing.List[app_commands.Choice[str]]:
acs = acom(current)
matching_files = acs
return [app_commands.Choice(name=num, value=num) for num in matching_files]
def find_trans(account_address, number):
API_ENDPOINT = "https://api.polygonscan.com/api"
API_KEY = "4H655NPT5229MKFE2NNHIS2GNZ3U4UTGT2"
# ๊ฒ์ํ ๊ณ์ข ์ฃผ์ ๋ฐ ํ ํฐ ์ปจํธ๋ํธ ์ฃผ์
token_contract_address = "0xa4b37be40f7b231ee9574c4b16b7ddb7eacdc99b"
# Transfer ์ด๋ฒคํธ๋ฅผ ์กฐํํ๊ธฐ ์ํ ํ๋ผ๋ฏธํฐ
params = {
"module": "account",
"action": "tokennfttx",
"contractaddress": token_contract_address,
"address": account_address,
"page": 1,
"offset": number, # ์์ฒญํ ์ด๋ฒคํธ ๊ฐ์๋งํผ ์กฐํ
"sort": "desc", # ์ต์ ์์ผ๋ก ์ ๋ ฌ
"apikey": API_KEY
}
response = requests.get(API_ENDPOINT, params=params)
data = response.json()
print(data)
# ๊ฒฐ๊ณผ์์ ์์ฒญํ ๊ฐ์์ NFT ์ ๋ณด ์ถ์ถ
if data["status"] == "1" and data["result"]:
nft_list = data["result"][:number] # ์์ฒญํ ๊ฐ์๋งํผ์ ๊ฒฐ๊ณผ๋ง ์ฌ์ฉ
token_ids = [nft["tokenID"] for nft in nft_list] # ํ ํฐ ID ๋ฆฌ์คํธ ์์ฑ
token_from = [nft["from"] for nft in nft_list] # from ๊ฐ์ ๋ฆฌ์คํธ ์์ฑ
token_to = [nft["to"] for nft in nft_list] # to ๊ฐ์ ๋ฆฌ์คํธ ์์ฑ
return token_ids, token_from, token_to # ํ ํฐ ID ๋ฆฌ์คํธ์ from ๋ฆฌ์คํธ๋ฅผ ๋ฐํ
else:
print("No recent NFT transfers found.")
return [], [], [] # ๋ ๋น ๋ฆฌ์คํธ๋ฅผ ๋ฐํ
def find_first(account_address, number = 1):
API_ENDPOINT = "https://api.polygonscan.com/api"
API_KEY = "4H655NPT5229MKFE2NNHIS2GNZ3U4UTGT2"
# ๊ฒ์ํ ๊ณ์ข ์ฃผ์ ๋ฐ ํ ํฐ ์ปจํธ๋ํธ ์ฃผ์
token_contract_address = "0xa4b37be40f7b231ee9574c4b16b7ddb7eacdc99b"
# Transfer ์ด๋ฒคํธ๋ฅผ ์กฐํํ๊ธฐ ์ํ ํ๋ผ๋ฏธํฐ
params = {
"module": "account",
"action": "tokennfttx",
"contractaddress": token_contract_address,
"address": account_address,
"page": 1,
"offset": number, # ์์ฒญํ ์ด๋ฒคํธ ๊ฐ์๋งํผ ์กฐํ
"sort": "asc", # ์ต์ ์์ผ๋ก ์ ๋ ฌ
"apikey": API_KEY
}
response = requests.get(API_ENDPOINT, params=params)
data = response.json()
print(data)
# ๊ฒฐ๊ณผ์์ ์์ฒญํ ๊ฐ์์ NFT ์ ๋ณด ์ถ์ถ
if data["status"] == "1" and data["result"]:
nft_list = data["result"][:number] # ์์ฒญํ ๊ฐ์๋งํผ์ ๊ฒฐ๊ณผ๋ง ์ฌ์ฉ
timeStamp = [nft["timeStamp"] for nft in nft_list] # ํ ํฐ ID ๋ฆฌ์คํธ ์์ฑ
return timeStamp # ํ ํฐ ID ๋ฆฌ์คํธ์ from ๋ฆฌ์คํธ๋ฅผ ๋ฐํ
else:
print("No recent NFT transfers found.")
return [] # ๋ ๋น ๋ฆฌ์คํธ๋ฅผ ๋ฐํ
def center_txt(base_img, text, x,y, x1, y1, fs):
image_size = (x1, y1)
image = Image.new('RGBA', image_size, (255, 255, 255, 0))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("Helvetica_Neue_LT_Std_75_Bold.otf", fs)
text_color = (200, 200, 200)
# ํ
์คํธ์ ๊ฒฝ๊ณ ์์ ๊ณ์ฐ
text_bbox = draw.textbbox((0, 0), text, font=font)
text_width = text_bbox[2] - text_bbox[0]
text_height = text_bbox[3] - text_bbox[1]
# ํ
์คํธ๋ฅผ ์ด๋ฏธ์ง ์ค์์ ์ ๋ ฌ
text_x = (image_size[0] - text_width) / 2
text_y = (image_size[1] - text_height) / 2
draw.text((text_x, text_y), text, fill=text_color, font=font)
base_img.paste(image, (x,y), image)
return base_img
red_arr = Image.open("red_arr.png")
blue_arr = Image.open("blue_arr.png")
def run():
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
bot.tree.copy_global_to(guild=discord.Object(id=1207625911709597737))
await bot.tree.sync(guild=discord.Object(id=1192532796967751790))
await bot.tree.sync(guild=discord.Object(id=1207625911709597737))
print("ready")
@app_commands.autocomplete(name=name_auto)
@bot.tree.command()
async def me(interaction: discord.Interaction, name: str):
await interaction.response.defer()
did = interaction.user.id
nid = ad_srch(name)
nid = str(nid)
print(nid)
como = como_srch(nid)
como_img = como_txt(str(como))
base_img = Image.open("base_img2.png")
name_paste_position = (219, 295)
base_img.paste(como_img, name_paste_position, como_img)
obj = obj_srch(nid)
como_img = como_txt(str(obj))
name_paste_position = (219, 205)
base_img.paste(como_img, name_paste_position, como_img)
base_img = names(name, base_img)
token_ids, token_from, token_to = find_trans(nid, 4)
token_name = [None] * len(token_ids) # token_ids์ ๊ธธ์ด๋งํผ token_name ๋ฐฐ์ด ์ด๊ธฐํ
for i in range(len(token_ids)):
token_name[i] = web3_find(int(token_ids[i]))
token_from_name = [0,0,0,0]
token_from_name[0] = ad2id(token_from[0])
token_from_name[1] = ad2id(token_from[1])
token_from_name[2] = ad2id(token_from[2])
token_from_name[3] = ad2id(token_from[3])
token_to_name = [0, 0, 0, 0]
token_to_name[0] = ad2id(token_to[0])
token_to_name[1] = ad2id(token_to[1])
token_to_name[2] = ad2id(token_to[2])
token_to_name[3] = ad2id(token_to[3])
print(token_from_name[0])
print(token_from_name[1])
print(token_from_name[2])
base_img = center_txt(base_img, token_from_name[0], 463, 143, 327, 50, 42)
base_img = center_txt(base_img, token_from_name[1], 463, 288, 327, 50, 42)
base_img = center_txt(base_img, token_from_name[2], 463, 436, 327, 50, 42)
base_img = center_txt(base_img, token_from_name[3], 463, 583, 327, 50, 42)
base_img = center_txt(base_img, token_to_name[0], 909, 143, 327, 50, 42)
base_img = center_txt(base_img, token_to_name[1], 909, 288, 327, 50, 42)
base_img = center_txt(base_img, token_to_name[2], 909, 436, 327, 50, 42)
base_img = center_txt(base_img, token_to_name[3], 909, 583, 327, 50, 42)
base_img = center_txt(base_img, token_name[0], 457, 207, 785, 50, 44)
base_img = center_txt(base_img, token_name[1], 457, 346, 785, 50, 44)
base_img = center_txt(base_img, token_name[2], 457, 494, 785, 50, 44)
base_img = center_txt(base_img, token_name[3], 457, 642, 785, 50, 44)
timeStamp = find_first(nid)
timeStamp = first_time(timeStamp[0])
print(timeStamp)
base_img = names(timeStamp, base_img, 640, 66)
print(str(token_from[0]))
print(str(nid))
if str(token_from[0]) == str(nid).lower():
base_img.paste(blue_arr, (823, 152), blue_arr)
else:
base_img.paste(red_arr, (823, 152), red_arr)
if str(token_from[1]) == str(nid).lower():
base_img.paste(blue_arr, (823, 297), blue_arr)
else:
base_img.paste(red_arr, (823, 297), red_arr)
if str(token_from[2]) == str(nid).lower():
base_img.paste(blue_arr, (823, 444), blue_arr)
else:
base_img.paste(red_arr, (823, 444), red_arr)
if str(token_from[3]) == str(nid).lower():
base_img.paste(blue_arr, (823, 592), blue_arr)
else:
base_img.paste(red_arr, (823, 592), red_arr)
base_img.save("img.png")
#await interaction.response.send_message(f"", ephemeral=False, file=discord.File("img.png"))
await interaction.followup.send(f"", ephemeral=False, file=discord.File("img.png"))
bot.run(token)
import gradio as gr
def greet(name):
return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox")
if __name__ == "__main__":
t1 = threading.Thread(target=demo.launch)
t2 = threading.Thread(target=run)
t1.start()
t2.start()
t1.join()
t2.join() |