Guest User

kindlehacks

a guest
Aug 24th, 2011
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.60 KB | None | 0 0
  1. from urllib import *
  2. from string import *
  3. from shutil import *
  4. import os
  5.  
  6. def parsegoogle(bname,bold):
  7.    
  8.    
  9.     a=['']*1000
  10.     b=['']*200
  11.     i=0
  12.     y=0
  13.     flag='n'
  14.     flag2=0
  15.     s=open('search.html','r')
  16.     for line in s.readlines():
  17.         a[i]=line
  18.         i=i+1
  19.     #print a
  20.     for i in range(199):
  21.         if len(a[i])>5:
  22.            
  23.             if 'Daily Limit Exceeded' in a[i]:
  24.                 print 'You used all of the internets for today:('
  25.                 exit()
  26.  
  27.    
  28.             if "Amazon.com" in a[i]:
  29.  
  30.                 if 'title' in a[i]:
  31.                     if 'http://' in a[i+2]:
  32.                         if flag=='n':
  33.                            
  34.                             book,link= a[i],a[i+2]
  35.                  
  36.                             if 'kindle' in bold:
  37.                                 short=book
  38.                             if 'kindle' not in bold:
  39.                                 junk,short=split(book,'title": "Amazon.com:')
  40.                             print short
  41.                            
  42.                             flag=raw_input('is this the correct name of the book? y/n ')
  43.    
  44.  
  45.    
  46.     if flag=='n':
  47.         if flag2==0:
  48.             googapi("kindle_"+bold,bname)
  49.         flag2=1
  50.     amazonpage(short,link,bname,bold)
  51.        
  52.         #if 'title": "A' in line:
  53.          #   print line,line+1
  54.    
  55.    
  56.    
  57.  
  58.    
  59. def amazonpage(short,link,bname,bold):
  60.     print link
  61.     flag=0
  62.     writ=open("readinglist.html",'a')
  63.     if 'ebook/dp' in link:
  64.         print 'OMFG'
  65.         link=split(link,'"')
  66.         a=link[3]
  67.         #print link
  68.        
  69.         flag=1
  70.         sendtohtml(a,short,writ,bname)
  71.    
  72.  
  73.    
  74.     #GET REAL AMAZON PAGE
  75.     print "AMAZON-ing"
  76.     link=split(link,'"')
  77.     a=link[3]
  78.     print a
  79.    
  80.     if flag==0:
  81.         urlretrieve(a,'amazon.html')
  82.         s=open('amazon.html','r')
  83.         for line in s.readlines():
  84.            
  85.             if 'ead the <' in line:
  86.                 line=split(line,'"')
  87.                 line=line[1]
  88.                 #print line
  89.                 sendtohtml(line,short,writ,bname)
  90.                 flag=1
  91.             if "Start reading" in line:
  92.                 if flag==0:
  93.                     line=split(line,'"')
  94.                     line=line[1]
  95.                     #print line
  96.  
  97.                     sendtohtml(line,short,writ,bname)
  98.                     flag=1
  99.            
  100.     if flag==1:
  101.         print ''
  102.         print "*******"
  103.         print "success"
  104.         print "*******"
  105.     if flag==0:
  106.         print ''
  107.         print "***************ERROR********************"
  108.         print "Failed to find kindle edition: try again"
  109.         print "***************ERROR********************"
  110.        
  111.         #parsegoogle(short,link,bname)
  112.     writ.close()
  113. def sendtohtml(line,short,s,bname):
  114.    
  115.    
  116.     asin=split(line,'/')
  117.     asin=asin[5]
  118.     s.write('<a href="')
  119.     s.write( line)
  120.     s.write('" >')
  121.    
  122.     s.write(short)
  123.     s.write("</a> <br>")
  124.     copy(bname,'../copytokindle/'+asin+'_EBOK.awz')
  125.        
  126.  
  127. def googapi(b,bname):
  128.    
  129.     print 'googling...'
  130.  
  131.     key='xxxxSyA9m-IumOmRQ_icrX6tLCE7PVNhcRQV0GU&&'//need to sign up with google apps
  132.     cx='xxxxx8151091691353158:ya-_5tsn7ii&'//need to sign up with google apps
  133.     a='https://www.googleapis.com/customsearch/v1?key='+key+'cx='+cx+'q='
  134.    
  135.  
  136.     co=a+b
  137.     #print co
  138.     "GOOOOOOOOOOOOOOOOOGLEING"
  139.     urlretrieve(co,'search.html')
  140.     parsegoogle(bname,b)
  141.    
  142.  
  143. def finddir():
  144.     format()
  145.     os.chdir('ready')
  146.     a= os.getcwd()
  147.    
  148.     for files in os.walk(a):
  149.         a= files[2]
  150.     for a in range(len(files[2])):
  151.         bname= files[2][a]
  152.         if '.mobi' in bname:
  153.             #print bname
  154.             #print type(bname)
  155.             findbname(bname)
  156.     print "now open your read/readinglist.html and click on each o those links and download the sample"
  157.     print "after your kindle updated, copy your 'copytokindle' directory to the /.palmkindle on your touchpad"
  158.     print "thanks to DCPeterson2000 on precentral.net and joesacher.com"
  159.            
  160.    
  161.  
  162.  
  163.  
  164. def findbname(bname):
  165.     s=open(bname,'r')
  166.     flag=0
  167.     for line in s.readlines():
  168.         if flag==0:
  169.             flag=1
  170.             a= line[:30]
  171.             print a
  172.             googapi(a,bname)
  173.  
  174.                
  175. def format():
  176.     #print ""
  177.     a=open("ready/readinglist.html",'w')
  178.     a.write("<html>")
  179.     a.write("<body>")
  180.     a.write("This is all of your books that have free previews.  Click on the link to send to your kindle<br>")
  181.     a.write("\n")
  182.     a.close()
  183.  
  184. finddir()
Add Comment
Please, Sign In to add comment