forked from xlanor/CryptoKitties
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.py
executable file
·180 lines (171 loc) · 8.36 KB
/
commands.py
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
#! /usr/bin/env python3
#-*- coding: utf-8 -*-
##
# Cryptokitties cmd.
# Written by xlanor
##
from ghost import Ghost
import urllib.request
from tokens import Tokens
import datetime
import requests
import time
import json
import os
from web3 import Web3, HTTPProvider, IPCProvider
import multiprocessing as mp
from multiprocessing import Pool
from telegram import ReplyKeyboardMarkup,ChatAction,InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler,Job,ConversationHandler
import traceback
import contextlib
class Commands():
def broadcast(bot,update):
ghost = Ghost()
return_array = []
cat_list = ["spock","beard","mauveover","cymric","gold","otaku","saycheese","googly","mainecoon","whixtensions","wingtips","chestnut","jaguar"]
counter = 0
trigger = True
web3 = Web3(HTTPProvider('http://localhost:8545'))
while trigger:
try:
url = "https://api.cryptokitties.co/auctions?offset="+str(counter)+"&limit=100&type=sale&status=open&sorting=cheap&orderBy=current_price&orderDirection=asc"
#sireurl = "https://api.cryptokitties.co/auctions?offset="+str(counter)+"&limit=100&type=sire&status=open&sorting=cheap&orderBy=current_price&orderDirection=asc"
r = requests.get(url).json()
#q = requests.get(sireurl).json()
if counter <= 1000:
if r['auctions']:
for kitten in r['auctions']:
if kitten['kitty']['generation'] <= 7:
if kitten['kitty']['status']['cooldown_index'] < 4:
cattribute_api = "https://api.cryptokitties.co/kitties/"+str(kitten['kitty']['id'])
cattribute = requests.get(cattribute_api).json()
cattribute_list = cattribute['cattributes']
for each in cattribute_list:
if each in cat_list:
result = kitten['current_price']
convertedeth = web3.fromWei(float(result),'ether')
message = " 🐈Name: "
message += str(kitten['kitty']['name']) if kitten['kitty']['name'] else "Null"
message +="\n🏠Address: "
message += str(kitten['kitty']['owner']['address']) if kitten['kitty']['owner']['address'] else "Null"
message += "\n📛ID: "
message += str(kitten['kitty']['id']) if kitten['kitty']['id'] else "Null"
message += "\n🈹Type: Sale "
message += "\n📈Generation: "
message += str(kitten['kitty']['generation']) if kitten['kitty']['generation'] else "Null"
message += "\n📈Cooldown Index: "
message += str(kitten['kitty']['status']['cooldown_index']) if kitten['kitty']['status']['cooldown_index'] else "Null"
message += "\n🚀ETH: "
message += str(convertedeth)
message += "\n💻URL: "
message += "https://www.cryptokitties.co/kitty/"
message += str(kitten['kitty']['id']) if kitten['kitty']['id'] else "Null"
message += "\nCattributes: "
for x in cattribute_list:
if x in cat_list:
message += "<b>"
message += str(x)
message += "</b>"
else:
message += str(x)
message += ", "
message += "\n👨🚀Alerting: @nthwin @iczac @jaynertwx"
filename = "/home/elanor/ftp/files/cryptokitties/images/"+str(kitten['kitty']['id'])+".png"
with ghost.start() as session:
session.open(cattribute['image_url'])
session.capture_to(filename)
"""
svg_filename = "/home/elanor/ftp/files/cryptokitties/images/"+str(kitten['kitty']['id'])+".svg"
f = open(svg_filename,'wb')
f.write(urllib.request.urlopen(cattribute['image_url']).read())
f.close()
cairosvg.svg2png(url=svg_filename, write_to=filename)"""
bot.sendMessage(chat_id=Tokens.channel('livechannel'),text=message,parse_mode='HTML')
bot.sendPhoto(chat_id=Tokens.channel('livechannel'),photo=open(filename,'rb'))
os.remove(filename)
break
scrapednumber = "Nthwin "+str(counter)+" scraped"
counter += 100
bot.sendMessage(chat_id=Tokens.channel('errorchannel'),text=scrapednumber,parse_mode='HTML')
print (str(counter)+" has been scraped")
else:
trigger = False
except:
#API will time out after x amount of requests. need to let it sleep then resume.
catcherror = traceback.format_exc()
bot.sendMessage(chat_id=Tokens.channel('errorchannel'),text=catcherror,parse_mode='HTML')
message = """Timed out API on page number """+str(counter)+"""
Sleeping for 15 seconds"""
bot.sendMessage(chat_id=Tokens.channel('errorchannel'),text=message,parse_mode='HTML')
time.sleep(15)
def kleongbroadcast(bot,update):
ghost = Ghost()
cat_list = ["spock","beard","mauveover","cymric","gold","otaku","saycheese","googly","mainecoon","whixtensions","wingtips","chestnut","jaguar"]
counter = 7188
kleongTrigger = True
web3 = Web3(HTTPProvider('http://localhost:8545'))
while kleongTrigger:
try:
kleong_url1 = "https://api.cryptokitties.co/auctions?offset="+str(counter)+"&limit=100&type=sale&status=open&sorting=cheap&orderBy=current_price&orderDirection=asc"
r = requests.get(kleong_url1).json()
#q = requests.get(sireurl).json()
if counter <= 8388:
if r['auctions']:
for kitten in r['auctions']:
if kitten['kitty']['generation'] <= 2:
if kitten['kitty']['status']['cooldown_index'] <= 1:
cattribute_api = "https://api.cryptokitties.co/kitties/"+str(kitten['kitty']['id'])
cattribute = requests.get(cattribute_api).json()
cattribute_list = cattribute['cattributes']
result = kitten['current_price']
for each in cattribute_list:
if each in cat_list:
convertedeth = web3.fromWei(float(result),'ether')
message = "🐈 Name: "
message += str(kitten['kitty']['name']) if kitten['kitty']['name'] else "Null"
message +="\n🏠Address: "
message += str(kitten['kitty']['owner']['address']) if kitten['kitty']['owner']['address'] else "Null"
message += "\n📛ID: "
message += str(kitten['kitty']['id']) if kitten['kitty']['id'] else "Null"
message += "\n🈹Type: Sale "
message += "\n📈Generation: "
message += str(kitten['kitty']['generation']) if kitten['kitty']['generation'] else "Null"
message += "\n📈Cooldown Index: "
message += str(kitten['kitty']['status']['cooldown_index']) if kitten['kitty']['status']['cooldown_index'] else "Null"
message += "\n🚀ETH: "
message += str(convertedeth)
message += "\n💻URL: "
message += "https://www.cryptokitties.co/kitty/"
message += str(kitten['kitty']['id']) if kitten['kitty']['id'] else "Null"
message += "\nCattributes: "
for x in cattribute_list:
if x in cat_list:
message += "<b>"
message += str(x)
message += "</b>"
else:
message += str(x)
message += ", "
message += "\n👨🚀Alerting: @kelvinleong"
filename = "/home/elanor/ftp/files/cryptokitties/images/"+str(kitten['kitty']['id'])+".png"
with ghost.start() as session:
session.open(cattribute['image_url'])
session.capture_to(filename)
bot.sendMessage(chat_id=Tokens.channel('livechannel'),text=message,parse_mode='HTML')
bot.sendPhoto(chat_id=Tokens.channel('livechannel'),photo=cattribute['image_url'])
bot.sendPhoto(chat_id=Tokens.channel('livechannel'),photo=open(filename,'rb'))
os.remove(filename)
break
counter += 100
print ("Kleong"+ str(counter)+" has been scraped")
else:
kleongTrigger = False
except:
#API will time out after x amount of requests. need to let it sleep then resume.
catcherror = traceback.format_exc()
bot.sendMessage(chat_id=Tokens.channel('errorchannel'),text=catcherror,parse_mode='HTML')
message = """Timed out Kleong API on page number """+str(counter)+"""
Sleeping for 15 seconds"""
bot.sendMessage(chat_id=Tokens.channel('errorchannel'),text=message,parse_mode='HTML')
time.sleep(15)