Esempio n. 1
0
	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://*****:*****@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)