View Single Post
Old 01-18-2011, 01:48 AM   #97
m0ngr31
Connoisseur
m0ngr31 could sell banana peel slippers to a Deveel.m0ngr31 could sell banana peel slippers to a Deveel.m0ngr31 could sell banana peel slippers to a Deveel.m0ngr31 could sell banana peel slippers to a Deveel.m0ngr31 could sell banana peel slippers to a Deveel.m0ngr31 could sell banana peel slippers to a Deveel.m0ngr31 could sell banana peel slippers to a Deveel.m0ngr31 could sell banana peel slippers to a Deveel.m0ngr31 could sell banana peel slippers to a Deveel.m0ngr31 could sell banana peel slippers to a Deveel.m0ngr31 could sell banana peel slippers to a Deveel.
 
Posts: 66
Karma: 3056
Join Date: Dec 2010
Device: Kindle Paperwhite
Ok, I was able to get it. This is for windows only though. I'll work on the *nix version soon...

Here's what you'll need to do:
-python-amazon-product-api (It's not too hard to install "easy_install python-amazon-product-api" if you have python setup in your PATH properly, if it has dependency problems, you'll have to install http://users.skynet.be/sbi/libxml-python/ and then run that command again)
-All your mobi files in one directory
-Save simple python script (attached) in the folder where you have your mobi files
-An Amazon Product Advertising account (https://affiliate-program.amazon.com...tail/main.html)
-Put the keys you get from this into the asin_search.py file
-Save this file as a .bat in the same folder as above
Code:
@echo off & setLocal EnableDELAYedExpansion
del temp*.txt>null 2>&1
set "asin1=B00"
set /a count=0
for /f %%a IN ('dir /b *.mobi') do (set /a count=count+1)
echo Number of files: %count%

set /a diff=((9999-%count%) - 1000) + 1
set /a divisor = 32767 / %diff%
set /a diff2=(999 - 100) + 1
set /a divisor2 = 32767 / %diff2%

:Random1
set /a asin2=%random% / %divisor%
if /i %asin2% GTR 9999 goto Random1
if /i %asin2% LSS 1000 goto Random1

:Random2
set /a asin3=%random% / %divisor2%
if /i %asin3% GTR 999 goto Random2
if /i %asin3% LSS 100 goto Random2
set /a temp1=!asin2!

for /f "delims=  " %%b IN ('dir /b *.mobi') do (

C:\Users\m0ngr31\desktop\kindle\mobi2mobi.exe --outfile "%%b" --delexthtype 113 "%%b">null 2>&1
C:\Users\m0ngr31\desktop\kindle\mobi2mobi.exe --outfile "%%b" --delexthtype 501 "%%b">null 2>&1

C:\Users\m0ngr31\desktop\kindle\mobi2mobi.exe "%%b" > temp1.txt
findstr /i "longtitle" temp1.txt > temp2.txt
set /p title1=<temp2.txt
set title1=!title1:~11!

findstr /i "item: 100" temp1.txt > temp3.txt
set /p author1=<temp3.txt
set author1=!author1:~33!

python asin_search.py "!title1!" "!author1!" >temp4.txt

set /p temp2=<temp4.txt
set temp2=!temp2:~0!

call :movement %%b
)

:movement
find /c /i "b0" "temp4.txt">null 2>&1
if !ERRORLEVEL! EQU 0 goto :real
if !errorlevel! equ 1 goto :fake

:fake
C:\Users\m0ngr31\desktop\kindle\mobi2mobi.exe --outfile "%%b" --exthtype 113 --exthdata "!asin1!!asin3!!temp1!" "%%b">null 2>&1
echo Gave a fake ASIN number to: !title1!. It's new number is !asin1!!asin3!!temp1!
set /a temp1=!temp1!+1
goto final

:real
C:\Users\m0ngr31\desktop\kindle\mobi2mobi.exe --outfile "%%b" --exthtype 113 --exthdata "!temp2!" "%%b">null 2>&1
echo Gave a real ASIN number to: !title1!. It's new number is !temp2!

:final
C:\Users\m0ngr31\desktop\kindle\mobi2mobi.exe --outfile "%%b" --addexthtype 501 --exthdata "EBOK" "%%b">null 2>&1
del temp*.txt>null 2>&1
-Change the directory where I am pointing to mobi2mobi.exe (all places)
-Run the file!

Should be pretty straight-forward. It'll go through all the mobi files you have, search for the title and author of every book (so you need to have them correct in the meta info) on the kindle store and if it's there, it'll download the correct ASIN number, if it isn't there, it'll insert a random number.

It was kind of slopped together, and it's not perfect, but it seemed for me. Let me know if you run to any problems.

--edit
It wouldn't let me upload my python file, so save this as asin_search.py in the working directory
Code:
import sys
from amazonproduct import API

AWS_KEY = 'put your own key here'
SECRET_KEY = 'put your secret key here'
api = API(AWS_KEY, SECRET_KEY, "us")
node = api.item_search('KindleStore', Title=sys.argv[1], Author=sys.argv[2])

for book in node.Items.Item:
    print '%s' % (book.ASIN)

Last edited by m0ngr31; 01-18-2011 at 01:50 AM.
m0ngr31 is offline   Reply With Quote