Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from urllib import *
- from string import *
- from shutil import *
- import os
- def parsegoogle(bname,bold):
- a=['']*1000
- b=['']*200
- i=0
- y=0
- flag='n'
- flag2=0
- s=open('search.html','r')
- for line in s.readlines():
- a[i]=line
- i=i+1
- #print a
- for i in range(199):
- if len(a[i])>5:
- if 'Daily Limit Exceeded' in a[i]:
- print 'You used all of the internets for today:('
- exit()
- if "Amazon.com" in a[i]:
- if 'title' in a[i]:
- if 'http://' in a[i+2]:
- if flag=='n':
- book,link= a[i],a[i+2]
- if 'kindle' in bold:
- short=book
- if 'kindle' not in bold:
- junk,short=split(book,'title": "Amazon.com:')
- print short
- flag=raw_input('is this the correct name of the book? y/n ')
- if flag=='n':
- if flag2==0:
- googapi("kindle_"+bold,bname)
- flag2=1
- amazonpage(short,link,bname,bold)
- #if 'title": "A' in line:
- # print line,line+1
- def amazonpage(short,link,bname,bold):
- print link
- flag=0
- writ=open("readinglist.html",'a')
- if 'ebook/dp' in link:
- print 'OMFG'
- link=split(link,'"')
- a=link[3]
- #print link
- flag=1
- sendtohtml(a,short,writ,bname)
- #GET REAL AMAZON PAGE
- print "AMAZON-ing"
- link=split(link,'"')
- a=link[3]
- print a
- if flag==0:
- urlretrieve(a,'amazon.html')
- s=open('amazon.html','r')
- for line in s.readlines():
- if 'ead the <' in line:
- line=split(line,'"')
- line=line[1]
- #print line
- sendtohtml(line,short,writ,bname)
- flag=1
- if "Start reading" in line:
- if flag==0:
- line=split(line,'"')
- line=line[1]
- #print line
- sendtohtml(line,short,writ,bname)
- flag=1
- if flag==1:
- print ''
- print "*******"
- print "success"
- print "*******"
- if flag==0:
- print ''
- print "***************ERROR********************"
- print "Failed to find kindle edition: try again"
- print "***************ERROR********************"
- #parsegoogle(short,link,bname)
- writ.close()
- def sendtohtml(line,short,s,bname):
- asin=split(line,'/')
- asin=asin[5]
- s.write('<a href="')
- s.write( line)
- s.write('" >')
- s.write(short)
- s.write("</a> <br>")
- copy(bname,'../copytokindle/'+asin+'_EBOK.awz')
- def googapi(b,bname):
- print 'googling...'
- key='xxxxSyA9m-IumOmRQ_icrX6tLCE7PVNhcRQV0GU&&'//need to sign up with google apps
- cx='xxxxx8151091691353158:ya-_5tsn7ii&'//need to sign up with google apps
- a='https://www.googleapis.com/customsearch/v1?key='+key+'cx='+cx+'q='
- co=a+b
- #print co
- "GOOOOOOOOOOOOOOOOOGLEING"
- urlretrieve(co,'search.html')
- parsegoogle(bname,b)
- def finddir():
- format()
- os.chdir('ready')
- a= os.getcwd()
- for files in os.walk(a):
- a= files[2]
- for a in range(len(files[2])):
- bname= files[2][a]
- if '.mobi' in bname:
- #print bname
- #print type(bname)
- findbname(bname)
- print "now open your read/readinglist.html and click on each o those links and download the sample"
- print "after your kindle updated, copy your 'copytokindle' directory to the /.palmkindle on your touchpad"
- print "thanks to DCPeterson2000 on precentral.net and joesacher.com"
- def findbname(bname):
- s=open(bname,'r')
- flag=0
- for line in s.readlines():
- if flag==0:
- flag=1
- a= line[:30]
- print a
- googapi(a,bname)
- def format():
- #print ""
- a=open("ready/readinglist.html",'w')
- a.write("<html>")
- a.write("<body>")
- a.write("This is all of your books that have free previews. Click on the link to send to your kindle<br>")
- a.write("\n")
- a.close()
- finddir()
Add Comment
Please, Sign In to add comment