#!/usr/bin/python

from pwn import *
from subprocess import check_output as co
import time




con = remote("34.89.220.233",6010)
for i in range(30):
	data = con.recv()
	with open("test.png","wb") as f:
		f.write(data)
	f.close()
	co("zbarimg test.png > test.txt",shell=True)
	bid = int(open("test.txt").read().split(":")[1])
	co("wget https://www.amazon.com/"+str(bid)+"/s?k="+str(bid)+" -O "+str(bid)+".txt",shell=True)
	print (int(bid),i)
	bookdata = co("cat "+str(bid)+".txt | grep -i 'a-size-medium a-color-base a-text-normal'",shell=True)
	pos1 = bookdata.find(">")
	pos2 = bookdata.find("</",pos1)
	bname = bookdata[pos1+1:pos2]
	if ("&#39;" in bname):
		bname = bname.replace("&#39;","'")
	print(bname)
	con.sendline(bname)
	con.recvuntil("Good!")

con.interactive()
