View Single Post
Old 11-04-2009, 05:44 AM   #15
JvdW
Zealot
JvdW doesn't litterJvdW doesn't litter
 
Posts: 115
Karma: 150
Join Date: Jul 2008
Location: Netherlands Veenendaal
Device: Palm T5, Sony PRS-505, Nook Color
Quote:
Originally Posted by quisvir View Post
Great work Joop!

I don't think there is a bug in Calibre, the only problem I've found is that the calibre-debug command doesn't work if Calibre is running.
Maybe you're running a version older than 0.6.17 since I have had the problem with .19 and .20 and the person who found it can trace it back to .17.

Quote:
I've made a few changes, the script now does this:
- First, it closes calibre. I don't know if calibre has a command line switch for this, so I just use tskill calibre. Optionally, you can add ebook-device eject to prevent data loss.
- Second, date variables are set (no change here, good work on it btw).
- Use Wget to download today's paper - removed some unnecessary parameters, fixed a few others.
- Add news tag, add to calibre database (no change here I think).
- Set calibre to auto-upload to reader (small change here).
- Clean up temporary files
- Start calibre in tray.

In other words, if you have Calibre running (either normally or in the background), the script still works. If it's running, it just kills it and starts it again once it is done.

There are two issues:
- Killing calibre like this is not optimal, I'd rather have the calibre-debug command work while calibre is still running so that killing/closing is not necessary.
- The script only works to download today's paper. So it doesn't work if you try to download after midnight, or for example the next morning. Also, it doesn't work on Sunday. The way I wanted to fix this is by making the script follow the link under the 'Download ePaper' button on the NRC site, so that it always downloads the latest paper. However, I've not (yet) been able to do this with wget.
Nicely cleaned up, thanks.

Maybe its an idea to set a variable to indicate if Calibre was running when the script starts if it wasn't you'll end up with Calibre running when you maybe don't want that.

My idea was to schedule a task slightly past 15:00 on mo-fri and >07:00 at saturdays. That would take care of the what/when is TODAY.

After quite a bit of hacking and reading up I have come up with the following:

Code:
REM try to get the download link from the page and try to figure out what day it is for
for /f "tokens=1-10 delims==> """ %%a in ('findstr /i "Mousedown" nrc.tmp ^| findstr /i epubd') do set url="http://epaper.nrc.nl/%%~c=%%d=%%~e
for /f "tokens=1-10 delims==> """ %%a in ('findstr /i "Mousedown" nrc.tmp ^| findstr ID ^') do for /f "tokens=1 delims=&ft" %%i in ("%%d") do set datum=%%i

REM download the epaper of TODAY ;-)
REM wget --output-document=%TEMP%\nrc-%TODAY%.epub --load-cookies=%TEMP%\nrc.cookies "http://epaper.nrc.nl/downloadfile.php?ID=%TODAY%&ft=epubd"
wget --output-document=%TEMP%\nrc-%datum%.epub --load-cookies=%TEMP%\nrc.cookies %url%
I'm too sure about the stability of the for loops. If they change the website then it needs to be adapted. The previous solution will always work in combination with the right schedule.

Regards,

Joop
JvdW is offline   Reply With Quote