@ -1,7 +1,7 @@
from fanficfare import geturls
from fanficfare import geturls
from os import listdir , remove , rename , utime , errno , devnull
from os import listdir , remove , rename , utime , errno , devnull
from os . path import isfile , join
from os . path import isfile , join
from subprocess import check_output , STDOUT , call
from subprocess import check_output , STDOUT , call , PIPE
import logging
import logging
from optparse import OptionParser
from optparse import OptionParser
import re
import re
@ -24,6 +24,7 @@ equal_chapters = re.compile('.* already contains \d* chapters.')
chapter_difference = re . compile ( ' .* contains \ d* chapters, more than source: \ d*. ' )
chapter_difference = re . compile ( ' .* contains \ d* chapters, more than source: \ d*. ' )
bad_chapters = re . compile ( " .* doesn ' t contain any recognizable chapters, probably from a different source. Not updating. " )
bad_chapters = re . compile ( " .* doesn ' t contain any recognizable chapters, probably from a different source. Not updating. " )
no_url = re . compile ( ' No story URL found in epub to update. ' )
no_url = re . compile ( ' No story URL found in epub to update. ' )
more_chapters = re . compile ( " .*File \ (.* \ .epub \ ) Updated \ (.* \ ) more recently than Story \ (.* \ ) - Skipping " )
def parse_url ( url ) :
def parse_url ( url ) :
@ -86,11 +87,11 @@ def main(user, password, server, label, inout_file, path ):
try :
try :
if path :
if path :
try :
try :
res = check_output ( ' calibredb search " Identifiers: {} " {} ' . format ( url , path ) , shell = True , stderr = STDOUT )
res = check_output ( ' calibredb search " Identifiers: {} " {} ' . format ( url , path ) , shell = True , stderr = STDOUT ,stdin = PIPE , )
storyId = res
storyId = res
print " \t Story is in calibre with id {} " . format ( storyId )
print " \t Story is in calibre with id {} " . format ( storyId )
print " \t Exporting file "
print " \t Exporting file "
res = check_output ( ' calibredb export {} --dont-save-cover --dont-write-opf --single-dir --to-dir " {} " {} ' . format ( storyId , loc , path ) , shell = True )
res = check_output ( ' calibredb export {} --dont-save-cover --dont-write-opf --single-dir --to-dir " {} " {} ' . format ( storyId , loc , path ) , shell = True , stdin = PIPE , stderr = STDOUT )
cur = get_files ( loc , " .epub " , True ) [ 0 ]
cur = get_files ( loc , " .epub " , True ) [ 0 ]
print ' \t Downloading with fanficfare, updating file " {} " ' . format ( cur )
print ' \t Downloading with fanficfare, updating file " {} " ' . format ( cur )
moving = " "
moving = " "
@ -98,29 +99,27 @@ def main(user, password, server, label, inout_file, path ):
#story is not in calibre
#story is not in calibre
cur = url
cur = url
moving = ' cd " {} " && ' . format ( loc )
moving = ' cd " {} " && ' . format ( loc )
print ' {} fanficfare -u " {} " --update-cover ' . format ( moving , cur )
res = check_output ( ' {} fanficfare -u " {} " --update-cover ' . format ( moving , cur ) , shell = True , stderr = STDOUT )
res = check_output ( ' {} fanficfare -u " {} " --update-cover ' . format ( moving , cur ) , shell = True , stderr = STDOUT , stdin = PIPE , )
check_regexes ( res )
check_regexes ( res )
if chapter_difference . search ( res ) or more_chapters . search ( res ) :
if chapter_difference . search ( res ) :
print " \t Forcing download update \n "
print " \t Forcing download update \n "
res = check_output ( ' {} fanficfare -u " {} " --force --update-cover ' . format ( moving , cur ) , shell = True , stderr = STDOUT )
res = check_output ( ' {} fanficfare -u " {} " --force --update-cover ' . format ( moving , cur ) , shell = True , stderr = STDOUT ,stdin = PIPE , )
check_regexes ( res )
check_regexes ( res )
cur = get_files ( loc , ' .epub ' , True ) [ 0 ]
cur = get_files ( loc , ' .epub ' , True ) [ 0 ]
if storyId :
if storyId :
print " \t Removing {} from library " . format ( storyId )
print " \t Removing {} from library " . format ( storyId )
res = check_output ( ' calibredb remove {} {} ' . format ( storyId , path ) , shell = True , stderr = STDOUT )
res = check_output ( ' calibredb remove {} {} ' . format ( storyId , path ) , shell = True , stderr = STDOUT ,stdin = PIPE , )
print " \t Adding {} to library " . format ( cur )
print " \t Adding {} to library " . format ( cur )
res = check_output ( ' calibredb add " {} " {} ' . format ( cur , path ) , shell = True , stderr = STDOUT )
res = check_output ( ' calibredb add " {} " -d {} ' . format ( cur , path ) , shell = True , stderr = STDOUT , stdin = PIPE , )
res = check_output ( ' calibredb search " Identifiers: {} " {} ' . format ( url , path ) , shell = True , stderr = STDOUT )
res = check_output ( ' calibredb search " Identifiers: {} " {} ' . format ( url , path ) , shell = True , stderr = STDOUT ,stdin = PIPE , )
print " \t Added {} to library with id {} " . format ( cur , res )
print " \t Added {} to library with id {} " . format ( cur , res )
remove ( cur )
remove ( cur )
else :
else :
res = check_output ( ' cd " {} " && fanficfare -u " {} " --update-cover ' . format ( loc , url ) , shell = True , stderr = STDOUT )
res = check_output ( ' cd " {} " && fanficfare -u " {} " --update-cover ' . format ( loc , url ) , shell = True , stderr = STDOUT ,stdin = PIPE , )
check_regexes ( res )
check_regexes ( res )
cur = get_files ( loc , ' .epub ' , True ) [ 0 ]
cur = get_files ( loc , ' .epub ' , True ) [ 0 ]
name = get_files ( loc , ' .epub ' , False ) [ 0 ]
name = get_files ( loc , ' .epub ' , False ) [ 0 ]