2012-09-13 15:27:34 +00:00
# This file is part of Mylar.
#
# Mylar is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Mylar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mylar. If not, see <http://www.gnu.org/licenses/>.
import time
2013-01-07 19:26:10 +00:00
import datetime
2012-09-13 15:27:34 +00:00
from xml . dom . minidom import parseString
import urllib2
import shlex
2012-09-14 17:29:01 +00:00
import re
2012-10-30 10:43:01 +00:00
import os
2013-08-06 03:20:09 +00:00
import itertools
2012-09-13 15:27:34 +00:00
import mylar
from mylar import db , logger , helpers , filechecker
2013-07-01 05:19:15 +00:00
def dbUpdate ( ComicIDList = None ) :
2012-09-13 15:27:34 +00:00
myDB = db . DBConnection ( )
2013-07-30 04:57:37 +00:00
#print "comicidlist:" + str(ComicIDList)
2013-07-01 05:19:15 +00:00
if ComicIDList is None :
comiclist = myDB . select ( ' SELECT ComicID, ComicName from comics WHERE Status= " Active " or Status= " Loading " order by LastUpdated ASC ' )
else :
comiclist = ComicIDList
2012-09-13 15:27:34 +00:00
2013-07-01 05:19:15 +00:00
logger . info ( ' Starting update for %i active comics ' % len ( comiclist ) )
2012-09-13 15:27:34 +00:00
2013-07-01 05:19:15 +00:00
for comic in comiclist :
if ComicIDList is None :
comicid = comic [ 0 ]
else :
comicid = comic
print " comicid " + str ( comicid )
2013-02-17 10:31:18 +00:00
mismatch = " no "
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
if not mylar . CV_ONLY or comicid [ : 1 ] == " G " :
CV_EXcomicid = myDB . action ( " SELECT * from exceptions WHERE ComicID=? " , [ comicid ] ) . fetchone ( )
if CV_EXcomicid is None : pass
else :
if CV_EXcomicid [ ' variloop ' ] == ' 99 ' :
mismatch = " yes "
if comicid [ : 1 ] == " G " :
mylar . importer . GCDimport ( comicid )
else :
mylar . importer . addComictoDB ( comicid , mismatch )
2013-02-17 10:31:18 +00:00
else :
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
if mylar . CV_ONETIMER == 1 :
2013-04-07 19:18:26 +00:00
logger . fdebug ( " CV_OneTimer option enabled... " )
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
#in order to update to JUST CV_ONLY, we need to delete the issues for a given series so it's a clean refresh.
2013-04-07 19:18:26 +00:00
logger . fdebug ( " Gathering the status of all issues for the series. " )
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
issues = myDB . select ( ' SELECT * FROM issues WHERE ComicID=? ' , [ comicid ] )
2013-07-30 04:57:37 +00:00
if mylar . ANNUALS_ON :
issues + = myDB . select ( ' SELECT * FROM annuals WHERE ComicID=? ' , [ comicid ] )
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
#store the issues' status for a given comicid, after deleting and readding, flip the status back to what it is currently.
2013-04-07 19:18:26 +00:00
logger . fdebug ( " Deleting all issue data. " )
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
myDB . select ( ' DELETE FROM issues WHERE ComicID=? ' , [ comicid ] )
2013-07-30 04:57:37 +00:00
myDB . select ( ' DELETE FROM annuals WHERE ComicID=? ' , [ comicid ] )
2013-04-07 19:18:26 +00:00
logger . fdebug ( " Refreshing the series and pulling in new data using only CV. " )
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
mylar . importer . addComictoDB ( comicid , mismatch )
issues_new = myDB . select ( ' SELECT * FROM issues WHERE ComicID=? ' , [ comicid ] )
2013-07-30 04:57:37 +00:00
annuals = [ ]
ann_list = [ ]
if mylar . ANNUALS_ON :
annuals_list = myDB . select ( ' SELECT * FROM annuals WHERE ComicID=? ' , [ ComicID ] )
ann_list + = annuals_list
issues_new + = annuals_list
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
icount = 0
2013-04-07 19:18:26 +00:00
logger . fdebug ( " Attempting to put the Status ' back how they were. " )
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
for issue in issues :
for issuenew in issues_new :
2013-07-30 04:57:37 +00:00
if issuenew [ ' IssueID ' ] == issue [ ' IssueID ' ] and issuenew [ ' Status ' ] != issue [ ' Status ' ] :
#if the status is now Downloaded, keep status.
if issuenew [ ' Status ' ] == ' Downloaded ' : break
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
#change the status to the previous status
ctrlVAL = { ' IssueID ' : issue [ ' IssueID ' ] }
newVAL = { ' Status ' : issue [ ' Status ' ] }
2013-07-30 04:57:37 +00:00
if any ( d [ ' IssueID ' ] == str ( issue [ ' IssueID ' ] ) for d in ann_list ) :
logger . fdebug ( " annual detected for " + str ( issue [ ' IssueID ' ] ) + " #: " + str ( issue [ ' Issue_Number ' ] ) )
myDB . upsert ( " Annuals " , newVAL , ctrlVAL )
else :
myDB . upsert ( " Issues " , newVAL , ctrlVAL )
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
icount + = 1
break
2013-04-07 19:18:26 +00:00
logger . info ( " In converting data to CV only, I changed the status of " + str ( icount ) + " issues. " )
FIX:(#304) Index out of range on recheck, FIX:(#303) Comicvine link updated on details page, FIX:(#302) Query rate (Search Delay) Added as a configuration option, FIX:(#300) Version number error on searching when no version number, FIX:(#297) Manual Rename of Files working, FIX:(#294) 'AU' issue problems should be resolved now, FIX:(#290) V#(year) and Vol#(year) added to filechecking, IMP: ComicVine data use only now as a hidden option (cv_only = 1 in config.ini), IMP: added as options for file naming, IMP: Rough drafting of Annuals (annuals_on = 1 in config.ini), Other fixes..
2013-04-06 09:43:18 +00:00
mylar . CV_ONETIMER = 0
else :
mylar . importer . addComictoDB ( comicid , mismatch )
time . sleep ( 5 ) #pause for 5 secs so dont hammer CV and get 500 error
2012-09-13 15:27:34 +00:00
logger . info ( ' Update complete ' )
def latest_update ( ComicID , LatestIssue , LatestDate ) :
# here we add to comics.latest
myDB = db . DBConnection ( )
2012-10-16 08:16:29 +00:00
latestCTRLValueDict = { " ComicID " : ComicID }
newlatestDict = { " LatestIssue " : str ( LatestIssue ) ,
" LatestDate " : str ( LatestDate ) }
myDB . upsert ( " comics " , newlatestDict , latestCTRLValueDict )
2012-09-13 15:27:34 +00:00
2013-04-08 16:31:41 +00:00
def upcoming_update ( ComicID , ComicName , IssueNumber , IssueDate , forcecheck = None ) :
2012-09-13 15:27:34 +00:00
# here we add to upcoming table...
myDB = db . DBConnection ( )
2013-07-30 04:57:37 +00:00
dspComicName = ComicName #to make sure that the word 'annual' will be displayed on screen
if ' annual ' in ComicName . lower ( ) :
adjComicName = re . sub ( " \\ bannual \\ b " , " " , ComicName . lower ( ) ) # for use with comparisons.
logger . fdebug ( " annual detected - adjusting name to : " + adjComicName )
else :
adjComicName = ComicName
2012-09-13 15:27:34 +00:00
controlValue = { " ComicID " : ComicID }
2013-07-30 04:57:37 +00:00
newValue = { " ComicName " : adjComicName ,
2012-10-16 08:16:29 +00:00
" IssueNumber " : str ( IssueNumber ) ,
2013-07-30 04:57:37 +00:00
" DisplayComicName " : dspComicName ,
2012-10-16 08:16:29 +00:00
" IssueDate " : str ( IssueDate ) }
2012-10-21 15:30:26 +00:00
2013-01-01 20:09:28 +00:00
#let's refresh the artist here just to make sure if an issue is available/not.
mismatch = " no "
CV_EXcomicid = myDB . action ( " SELECT * from exceptions WHERE ComicID=? " , [ ComicID ] ) . fetchone ( )
if CV_EXcomicid is None : pass
else :
if CV_EXcomicid [ ' variloop ' ] == ' 99 ' :
mismatch = " yes "
2013-01-07 19:26:10 +00:00
lastupdatechk = myDB . action ( " SELECT * FROM comics WHERE ComicID=? " , [ ComicID ] ) . fetchone ( )
if lastupdatechk is None :
pullupd = " yes "
else :
c_date = lastupdatechk [ ' LastUpdated ' ]
2013-03-29 04:02:35 +00:00
if c_date is None :
logger . error ( lastupdatechk [ ' ComicName ' ] + " failed during a previous add /refresh. Please either delete and readd the series, or try a refresh of the series. " )
return
2013-01-07 19:26:10 +00:00
c_obj_date = datetime . datetime . strptime ( c_date , " % Y- % m- %d % H: % M: % S " )
n_date = datetime . datetime . now ( )
absdiff = abs ( n_date - c_obj_date )
hours = ( absdiff . days * 24 * 60 * 60 + absdiff . seconds ) / 3600.0
# no need to hammer the refresh
# let's check it every 5 hours (or more)
#pullupd = "yes"
2013-07-30 04:57:37 +00:00
if ' annual ' in ComicName . lower ( ) :
if mylar . ANNUALS_ON :
issuechk = myDB . action ( " SELECT * FROM annuals WHERE ComicID=? AND Issue_Number=? " , [ ComicID , IssueNumber ] ) . fetchone ( )
2013-07-31 06:34:07 +00:00
else :
logger . fdebug ( " Annual detected, but annuals not enabled. Ignoring result. " )
return
2013-07-30 04:57:37 +00:00
else :
issuechk = myDB . action ( " SELECT * FROM issues WHERE ComicID=? AND Issue_Number=? " , [ ComicID , IssueNumber ] ) . fetchone ( )
2013-01-07 19:26:10 +00:00
2012-12-31 16:52:16 +00:00
if issuechk is None :
2013-07-30 04:57:37 +00:00
logger . fdebug ( adjComicName + " Issue: " + str ( IssueNumber ) + " not present in listings to mark for download...updating comic and adding to Upcoming Wanted Releases. " )
2013-02-06 19:55:23 +00:00
# we need to either decrease the total issue count, OR indicate that an issue is upcoming.
2013-02-27 08:28:40 +00:00
upco_results = myDB . action ( " SELECT COUNT(*) FROM UPCOMING WHERE ComicID=? " , [ ComicID ] ) . fetchall ( )
upco_iss = upco_results [ 0 ] [ 0 ]
#logger.info("upco_iss: " + str(upco_iss))
if int ( upco_iss ) > 0 :
#logger.info("There is " + str(upco_iss) + " of " + str(ComicName) + " that's not accounted for")
2013-02-18 17:39:00 +00:00
newKey = { " ComicID " : ComicID }
2013-02-27 08:28:40 +00:00
newVal = { " not_updated_db " : str ( upco_iss ) }
2013-02-18 17:39:00 +00:00
myDB . upsert ( " comics " , newVal , newKey )
2013-02-27 08:28:40 +00:00
elif int ( upco_iss ) < = 0 and lastupdatechk [ ' not_updated_db ' ] :
2013-02-18 17:39:00 +00:00
#if not_updated_db has a value, and upco_iss is > 0, let's zero it back out cause it's updated now.
newKey = { " ComicID " : ComicID }
2013-02-27 08:28:40 +00:00
newVal = { " not_updated_db " : " " }
2013-02-18 17:39:00 +00:00
myDB . upsert ( " comics " , newVal , newKey )
2013-04-08 16:31:41 +00:00
if hours > 5 or forcecheck == ' yes ' :
2013-01-07 19:26:10 +00:00
pullupd = " yes "
2013-03-08 01:36:36 +00:00
logger . fdebug ( " Now Refreshing comic " + ComicName + " to make sure it ' s up-to-date " )
2013-01-07 19:26:10 +00:00
if ComicID [ : 1 ] == " G " : mylar . importer . GCDimport ( ComicID , pullupd )
else : mylar . importer . addComictoDB ( ComicID , mismatch , pullupd )
else :
logger . fdebug ( " It hasn ' t been longer than 5 hours since we last did this...let ' s wait so we don ' t hammer things. " )
return
2013-01-07 18:26:15 +00:00
elif issuechk [ ' Issue_Number ' ] == IssueNumber :
2013-01-03 10:26:39 +00:00
logger . fdebug ( " Comic series already up-to-date ... no need to refresh at this time. " )
2013-07-30 04:57:37 +00:00
logger . fdebug ( " Available to be marked for download - checking... " + adjComicName + " Issue: " + str ( issuechk [ ' Issue_Number ' ] ) )
2012-12-31 16:52:16 +00:00
logger . fdebug ( " ...Existing status: " + str ( issuechk [ ' Status ' ] ) )
2012-10-16 08:16:29 +00:00
control = { " IssueID " : issuechk [ ' IssueID ' ] }
2013-01-15 22:41:00 +00:00
newValue [ ' IssueID ' ] = issuechk [ ' IssueID ' ]
2012-10-21 15:30:26 +00:00
if issuechk [ ' Status ' ] == " Snatched " :
values = { " Status " : " Snatched " }
newValue [ ' Status ' ] = " Snatched "
elif issuechk [ ' Status ' ] == " Downloaded " :
values = { " Status " : " Downloaded " }
newValue [ ' Status ' ] = " Downloaded "
2013-04-26 03:45:02 +00:00
#if the status is Downloaded and it's on the pullist - let's mark it so everyone can bask in the glory
2013-01-01 20:32:22 +00:00
elif issuechk [ ' Status ' ] == " Wanted " :
values = { " Status " : " Wanted " }
newValue [ ' Status ' ] = " Wanted "
2012-10-21 15:30:26 +00:00
else :
values = { " Status " : " Skipped " }
newValue [ ' Status ' ] = " Skipped "
2012-12-31 16:52:16 +00:00
#was in wrong place :(
2013-01-15 22:41:00 +00:00
if mylar . AUTOWANT_UPCOMING :
2013-01-07 18:26:15 +00:00
#for issues not in db - to be added to Upcoming table.
if issuechk is None :
newValue [ ' Status ' ] = " Wanted "
logger . fdebug ( " ...Changing Status to Wanted and throwing it in the Upcoming section since it ' s not published yet. " )
#this works for issues existing in DB...
elif issuechk [ ' Status ' ] == " Skipped " :
newValue [ ' Status ' ] = " Wanted "
2013-07-01 05:19:15 +00:00
values = { " Status " : " Wanted " }
2013-01-07 18:26:15 +00:00
logger . fdebug ( " ...New status of Wanted " )
elif issuechk [ ' Status ' ] == " Wanted " :
logger . fdebug ( " ...Status already Wanted .. not changing. " )
else :
logger . fdebug ( " ...Already have issue - keeping existing status of : " + issuechk [ ' Status ' ] )
if issuechk is None :
myDB . upsert ( " upcoming " , newValue , controlValue )
else :
2013-05-04 01:57:19 +00:00
logger . fdebug ( " --attempt to find errant adds to Wanted list " )
logger . fdebug ( " UpcomingNewValue: " + str ( newValue ) )
logger . fdebug ( " UpcomingcontrolValue: " + str ( controlValue ) )
2013-07-01 05:19:15 +00:00
if issuechk [ ' IssueDate ' ] == ' 0000-00-00 ' and newValue [ ' IssueDate ' ] != ' 0000-00-00 ' :
logger . fdebug ( " Found a 0000-00-00 issue - force updating series to try and get it proper. " )
dateVal = { " IssueDate " : newValue [ ' IssueDate ' ] ,
" ComicName " : issuechk [ ' ComicName ' ] ,
" Status " : newValue [ ' Status ' ] ,
" IssueNumber " : issuechk [ ' Issue_Number ' ] }
logger . fdebug ( " updating date in upcoming table to : " + str ( newValue [ ' IssueDate ' ] ) )
logger . fdebug ( " ComicID: " + str ( controlValue ) )
myDB . upsert ( " upcoming " , dateVal , controlValue )
logger . fdebug ( " Temporarily putting the Issue Date for " + str ( issuechk [ ' Issue_Number ' ] ) + " to " + str ( newValue [ ' IssueDate ' ] ) )
values = { " IssueDate " : newValue [ ' IssueDate ' ] }
#if ComicID[:1] == "G": mylar.importer.GCDimport(ComicID,pullupd='yes')
#else: mylar.importer.addComictoDB(ComicID,mismatch,pullupd='yes')
2013-07-30 04:57:37 +00:00
if ' annual ' in ComicName . lower ( ) :
myDB . upsert ( " annuals " , values , control )
else :
myDB . upsert ( " issues " , values , control )
2013-04-26 03:45:02 +00:00
if issuechk [ ' Status ' ] == ' Downloaded ' :
logger . fdebug ( " updating Pull-list to reflect status. " )
2013-05-04 01:57:19 +00:00
downstats = { " Status " : issuechk [ ' Status ' ] ,
" ComicID " : issuechk [ ' ComicID ' ] }
return downstats
2013-01-03 10:26:39 +00:00
else :
2013-02-25 20:25:10 +00:00
logger . fdebug ( " Issues don ' t match for some reason...weekly new issue: " + str ( IssueNumber ) )
2012-10-16 08:16:29 +00:00
2012-09-13 15:27:34 +00:00
2013-05-04 01:57:19 +00:00
def weekly_update ( ComicName , IssueNumber , CStatus , CID ) :
2012-09-13 15:27:34 +00:00
# here we update status of weekly table...
2013-04-26 03:45:02 +00:00
# added Issue to stop false hits on series' that have multiple releases in a week
# added CStatus to update status flags on Pullist screen
2012-09-13 15:27:34 +00:00
myDB = db . DBConnection ( )
2013-04-26 03:45:02 +00:00
issuecheck = myDB . action ( " SELECT * FROM weekly WHERE COMIC=? AND ISSUE=? " , [ ComicName , IssueNumber ] ) . fetchone ( )
if issuecheck is not None :
controlValue = { " COMIC " : str ( ComicName ) ,
" ISSUE " : str ( IssueNumber ) }
if CStatus :
2013-05-04 01:57:19 +00:00
newValue = { " STATUS " : CStatus ,
" ComicID " : CID }
2013-04-26 03:45:02 +00:00
else :
if mylar . AUTOWANT_UPCOMING :
newValue = { " STATUS " : " Wanted " }
else :
newValue = { " STATUS " : " Skipped " }
myDB . upsert ( " weekly " , newValue , controlValue )
2012-09-13 15:27:34 +00:00
2013-01-02 16:57:28 +00:00
def newpullcheck ( ComicName , ComicID ) :
2012-09-24 05:17:29 +00:00
# When adding a new comic, let's check for new issues on this week's pullist and update.
2013-01-02 16:57:28 +00:00
mylar . weeklypull . pullitcheck ( ComicName , ComicID )
2012-09-24 05:17:29 +00:00
return
2012-09-17 05:12:40 +00:00
def no_searchresults ( ComicID ) :
# when there's a mismatch between CV & GCD - let's change the status to
# something other than 'Loaded'
myDB = db . DBConnection ( )
controlValue = { " ComicID " : ComicID }
2013-01-11 21:20:51 +00:00
newValue = { " Status " : " Error " ,
2013-03-14 08:33:16 +00:00
" LatestDate " : " Error " ,
" LatestIssue " : " Error " }
2012-09-17 05:12:40 +00:00
myDB . upsert ( " comics " , newValue , controlValue )
2013-07-01 05:19:15 +00:00
def nzblog ( IssueID , NZBName , ComicName , SARC = None , IssueArcID = None ) :
2012-10-30 10:43:01 +00:00
myDB = db . DBConnection ( )
2013-05-25 06:18:00 +00:00
newValue = { " NZBName " : NZBName }
2013-04-12 02:14:27 +00:00
if IssueID is None or IssueID == ' None ' :
#if IssueID is None, it's a one-off download from the pull-list.
#give it a generic ID above the last one so it doesn't throw an error later.
2013-05-25 06:18:00 +00:00
print " SARC detected as: " + str ( SARC )
if mylar . HIGHCOUNT == 0 :
IssueID = ' 900000 '
else :
IssueID = int ( mylar . HIGHCOUNT ) + 1
if SARC :
IssueID = ' S ' + str ( IssueArcID )
newValue [ ' SARC ' ] = SARC
2013-04-12 02:14:27 +00:00
2012-10-30 10:43:01 +00:00
controlValue = { " IssueID " : IssueID }
2012-12-27 15:04:03 +00:00
#print controlValue
2013-05-25 06:18:00 +00:00
#newValue['NZBName'] = NZBName
2012-12-27 15:04:03 +00:00
#print newValue
2012-10-30 10:43:01 +00:00
myDB . upsert ( " nzblog " , newValue , controlValue )
2013-07-10 01:45:10 +00:00
def foundsearch ( ComicID , IssueID , mode = None , down = None , provider = None ) :
2013-01-06 08:51:44 +00:00
# When doing a Force Search (Wanted tab), the resulting search calls this to update.
# this is all redudant code that forceRescan already does.
# should be redone at some point so that instead of rescanning entire
# series directory, it just scans for the issue it just downloaded and
# and change the status to Snatched accordingly. It is not to increment the have count
# at this stage as it's not downloaded - just the .nzb has been snatched and sent to SAB.
2013-07-01 05:19:15 +00:00
logger . info ( " comicid: " + str ( ComicID ) )
logger . info ( " issueid: " + str ( IssueID ) )
2012-09-13 15:27:34 +00:00
myDB = db . DBConnection ( )
comic = myDB . action ( ' SELECT * FROM comics WHERE ComicID=? ' , [ ComicID ] ) . fetchone ( )
2013-07-01 05:19:15 +00:00
if mode == ' want_ann ' :
issue = myDB . action ( ' SELECT * FROM annuals WHERE IssueID=? ' , [ IssueID ] ) . fetchone ( )
else :
issue = myDB . action ( ' SELECT * FROM issues WHERE IssueID=? ' , [ IssueID ] ) . fetchone ( )
2012-09-13 15:27:34 +00:00
CYear = issue [ ' IssueDate ' ] [ : 4 ]
2013-05-15 09:04:26 +00:00
if down is None :
# update the status to Snatched (so it won't keep on re-downloading!)
logger . fdebug ( " updating status to snatched " )
2013-07-30 04:57:37 +00:00
logger . fdebug ( " provider is " + provider )
2013-05-15 09:04:26 +00:00
controlValue = { " IssueID " : IssueID }
newValue = { " Status " : " Snatched " }
2013-07-01 05:19:15 +00:00
if mode == ' want_ann ' :
myDB . upsert ( " annuals " , newValue , controlValue )
else :
myDB . upsert ( " issues " , newValue , controlValue )
2013-05-15 09:04:26 +00:00
# update the snatched DB
snatchedupdate = { " IssueID " : IssueID ,
2013-07-30 04:57:37 +00:00
" Status " : " Snatched " ,
" Provider " : provider
}
2013-07-01 05:19:15 +00:00
if mode == ' want_ann ' :
IssueNum = " Annual " + issue [ ' Issue_Number ' ]
else :
IssueNum = issue [ ' Issue_Number ' ]
2013-05-15 09:04:26 +00:00
newsnatchValues = { " ComicName " : comic [ ' ComicName ' ] ,
" ComicID " : ComicID ,
2013-07-01 05:19:15 +00:00
" Issue_Number " : IssueNum ,
2013-05-15 09:04:26 +00:00
" DateAdded " : helpers . now ( ) ,
" Status " : " Snatched "
}
myDB . upsert ( " snatched " , newsnatchValues , snatchedupdate )
else :
2013-07-01 05:19:15 +00:00
if mode == ' want_ann ' :
IssueNum = " Annual " + issue [ ' Issue_Number ' ]
else :
IssueNum = issue [ ' Issue_Number ' ]
2013-05-15 09:04:26 +00:00
snatchedupdate = { " IssueID " : IssueID ,
2013-07-30 04:57:37 +00:00
" Status " : " Downloaded " ,
" Provider " : provider
}
2013-05-15 09:04:26 +00:00
newsnatchValues = { " ComicName " : comic [ ' ComicName ' ] ,
" ComicID " : ComicID ,
2013-07-01 05:19:15 +00:00
" Issue_Number " : IssueNum ,
2013-05-15 09:04:26 +00:00
" DateAdded " : helpers . now ( ) ,
" Status " : " Downloaded "
}
myDB . upsert ( " snatched " , newsnatchValues , snatchedupdate )
2013-07-01 05:19:15 +00:00
controlValue = { " IssueID " : IssueID }
newValue = { " Status " : " Downloaded " }
myDB . upsert ( " issues " , newValue , controlValue )
2012-09-13 15:27:34 +00:00
#print ("finished updating snatched db.")
2013-07-01 05:19:15 +00:00
logger . info ( u " Updating now complete for " + comic [ ' ComicName ' ] + " issue: " + str ( IssueNum ) )
2012-09-13 15:27:34 +00:00
return
2013-02-17 10:31:18 +00:00
def forceRescan ( ComicID , archive = None ) :
2012-09-13 15:27:34 +00:00
myDB = db . DBConnection ( )
# file check to see if issue exists
rescan = myDB . action ( ' SELECT * FROM comics WHERE ComicID=? ' , [ ComicID ] ) . fetchone ( )
2013-03-08 01:36:36 +00:00
logger . info ( u " Now checking files for " + rescan [ ' ComicName ' ] + " ( " + str ( rescan [ ' ComicYear ' ] ) + " ) in " + str ( rescan [ ' ComicLocation ' ] ) )
2013-02-17 10:31:18 +00:00
if archive is None :
fc = filechecker . listFiles ( dir = rescan [ ' ComicLocation ' ] , watchcomic = rescan [ ' ComicName ' ] , AlternateSearch = rescan [ ' AlternateSearch ' ] )
else :
fc = filechecker . listFiles ( dir = archive , watchcomic = rescan [ ' ComicName ' ] , AlternateSearch = rescan [ ' AlternateSearch ' ] )
2012-09-13 15:27:34 +00:00
iscnt = rescan [ ' Total ' ]
havefiles = 0
fccnt = int ( fc [ ' comiccount ' ] )
issnum = 1
fcnew = [ ]
2012-10-25 06:44:51 +00:00
fn = 0
2013-01-03 10:01:07 +00:00
issuedupechk = [ ]
2013-07-01 05:19:15 +00:00
annualdupechk = [ ]
2013-04-07 18:06:36 +00:00
issueexceptdupechk = [ ]
2012-09-13 15:27:34 +00:00
reissues = myDB . action ( ' SELECT * FROM issues WHERE ComicID=? ' , [ ComicID ] ) . fetchall ( )
2013-08-06 00:53:10 +00:00
issID_to_ignore = [ ]
2013-08-06 03:20:09 +00:00
issID_to_ignore . append ( str ( ComicID ) )
2012-10-25 06:44:51 +00:00
while ( fn < fccnt ) :
haveissue = " no "
2013-01-03 10:01:07 +00:00
issuedupe = " no "
2012-09-24 05:17:29 +00:00
try :
2012-10-25 06:44:51 +00:00
tmpfc = fc [ ' comiclist ' ] [ fn ]
2012-09-24 05:17:29 +00:00
except IndexError :
break
2013-02-09 03:34:02 +00:00
temploc = tmpfc [ ' JusttheDigits ' ] . replace ( ' _ ' , ' ' )
# temploc = tmpfc['ComicFilename'].replace('_', ' ')
2012-10-25 06:44:51 +00:00
temploc = re . sub ( ' [ \ # \' ] ' , ' ' , temploc )
2013-03-02 01:46:49 +00:00
logger . fdebug ( " temploc: " + str ( temploc ) )
2013-07-01 05:19:15 +00:00
if ' annual ' not in temploc . lower ( ) :
2013-02-06 19:55:23 +00:00
#remove the extension here
extensions = ( ' .cbr ' , ' .cbz ' )
if temploc . lower ( ) . endswith ( extensions ) :
2013-07-01 05:19:15 +00:00
logger . fdebug ( " removed extension for issue: " + str ( temploc ) )
2013-07-30 04:57:37 +00:00
temploc = temploc [ : - 4 ]
2013-02-06 19:55:23 +00:00
deccnt = str ( temploc ) . count ( ' . ' )
2013-08-04 05:57:21 +00:00
if deccnt > 1 :
2013-03-02 01:46:49 +00:00
#logger.fdebug("decimal counts are :" + str(deccnt))
2013-02-06 19:55:23 +00:00
#if the file is formatted with '.' in place of spaces we need to adjust.
#before replacing - check to see if digits on either side of decimal and if yes, DON'T REMOVE
occur = 1
prevstart = 0
digitfound = " no "
decimalfound = " no "
tempreconstruct = ' '
while ( occur < = deccnt ) :
n = occur
start = temploc . find ( ' . ' )
while start > = 0 and n > 1 :
start = temploc . find ( ' . ' , start + len ( ' . ' ) )
n - = 1
2013-03-02 01:46:49 +00:00
#logger.fdebug("occurance " + str(occur) + " of . at position: " + str(start))
2013-02-06 19:55:23 +00:00
if temploc [ prevstart : start ] . isdigit ( ) :
if digitfound == " yes " :
2013-08-04 05:57:21 +00:00
logger . fdebug ( " this is a decimal, assuming decimal issue. " )
2013-02-06 19:55:23 +00:00
decimalfound = " yes "
reconst = " . " + temploc [ prevstart : start ] + " "
else :
2013-08-04 05:57:21 +00:00
logger . fdebug ( " digit detected. " )
2013-02-06 19:55:23 +00:00
digitfound = " yes "
reconst = temploc [ prevstart : start ]
else :
reconst = temploc [ prevstart : start ] + " "
2013-08-04 05:57:21 +00:00
logger . fdebug ( " word: " + reconst )
2013-02-06 19:55:23 +00:00
tempreconstruct = tempreconstruct + reconst
2013-08-04 05:57:21 +00:00
logger . fdebug ( " tempreconstruct is : " + tempreconstruct )
2013-02-06 19:55:23 +00:00
prevstart = ( start + 1 )
occur + = 1
2013-08-04 05:57:21 +00:00
logger . fdebug ( " word: " + temploc [ prevstart : ] )
2013-03-02 01:46:49 +00:00
tempreconstruct = tempreconstruct + " " + temploc [ prevstart : ]
2013-08-04 05:57:21 +00:00
logger . fdebug ( " final filename to use is : " + str ( tempreconstruct ) )
2013-02-06 19:55:23 +00:00
temploc = tempreconstruct
2013-03-02 01:46:49 +00:00
#logger.fdebug("checking " + str(temploc))
2013-07-30 04:57:37 +00:00
#fcnew_b4 = shlex.split(str(temploc))
fcnew_af = re . findall ( ' [^ \ ()]+ ' , temploc )
fcnew = shlex . split ( fcnew_af [ 0 ] )
2012-10-25 06:44:51 +00:00
fcn = len ( fcnew )
n = 0
while ( n < = iscnt ) :
2012-09-13 15:27:34 +00:00
som = 0
2012-10-25 06:44:51 +00:00
try :
reiss = reissues [ n ]
except IndexError :
break
2013-07-01 05:19:15 +00:00
# int_iss, iss_except = helpers.decimal_issue(reiss['Issue_Number'])
int_iss = helpers . issuedigits ( reiss [ ' Issue_Number ' ] )
2012-10-25 06:44:51 +00:00
issyear = reiss [ ' IssueDate ' ] [ : 4 ]
old_status = reiss [ ' Status ' ]
2013-07-01 05:19:15 +00:00
issname = reiss [ ' IssueName ' ]
2013-01-11 21:20:51 +00:00
#logger.fdebug("integer_issue:" + str(int_iss) + " ... status: " + str(old_status))
2013-01-07 19:58:34 +00:00
#if comic in format of "SomeSeries 5(c2c)(2013).cbr" whatever...it'll die.
#can't distinguish the 5(c2c) to tell it's the issue #...
2013-04-02 08:56:24 +00:00
fnd_iss_except = ' None '
#print ("Issue, int_iss, iss_except: " + str(reiss['Issue_Number']) + "," + str(int_iss) + "," + str(iss_except))
2013-01-07 19:58:34 +00:00
2013-08-04 05:57:21 +00:00
2012-09-13 15:27:34 +00:00
while ( som < fcn ) :
#counts get buggered up when the issue is the last field in the filename - ie. '50.cbr'
2013-07-11 03:37:52 +00:00
#logger.fdebug("checking word - " + str(fcnew[som]))
2013-01-13 20:26:45 +00:00
if " .cbr " in fcnew [ som ] . lower ( ) :
2012-09-13 15:27:34 +00:00
fcnew [ som ] = fcnew [ som ] . replace ( " .cbr " , " " )
2013-01-13 20:26:45 +00:00
elif " .cbz " in fcnew [ som ] . lower ( ) :
2012-09-13 15:27:34 +00:00
fcnew [ som ] = fcnew [ som ] . replace ( " .cbz " , " " )
2013-01-13 20:26:45 +00:00
if " (c2c) " in fcnew [ som ] . lower ( ) :
2013-01-07 19:58:34 +00:00
fcnew [ som ] = fcnew [ som ] . replace ( " (c2c) " , " " )
get_issue = shlex . split ( str ( fcnew [ som ] ) )
2013-01-08 04:24:00 +00:00
if fcnew [ som ] != " " :
fcnew [ som ] = get_issue [ 0 ]
2013-07-01 05:19:15 +00:00
if som + 1 < len ( fcnew ) and len ( fcnew [ som + 1 ] ) == 2 :
2013-07-10 01:45:10 +00:00
#print "fcnew[som+1]: " + str(fcnew[som+1])
#print "fcnew[som]: " + str(fcnew[som])
2013-07-01 05:19:15 +00:00
if ' au ' in fcnew [ som + 1 ] . lower ( ) :
#if the 'AU' is in 005AU vs 005 AU it will yield different results.
fcnew [ som ] = fcnew [ som ] + ' AU '
fcnew [ som + 1 ] = ' 93939999919190933 '
logger . info ( " AU Detected seperate from issue - combining and continuing " )
elif ' ai ' in fcnew [ som + 1 ] . lower ( ) :
#if the 'AI' is in 005AI vs 005 AI it will yield different results.
fcnew [ som ] = fcnew [ som ] + ' AI '
fcnew [ som + 1 ] = ' 93939999919190933 '
logger . info ( " AI Detected seperate from issue - combining and continuing " )
2013-07-30 04:57:37 +00:00
#sometimes scanners refuse to use spaces between () and lump the issue right at the start
#mylar assumes it's all one word in this case..let's dump the brackets.
2013-08-04 05:57:21 +00:00
fcdigit = helpers . issuedigits ( fcnew [ som ] )
2013-07-01 05:19:15 +00:00
2013-08-06 03:20:09 +00:00
#logger.fdebug("fcdigit: " + str(fcdigit))
#logger.fdebug("int_iss: " + str(int_iss))
2013-07-01 05:19:15 +00:00
2012-12-31 16:52:16 +00:00
if int ( fcdigit ) == int_iss :
2013-07-01 05:19:15 +00:00
logger . fdebug ( " issue match - fcdigit: " + str ( fcdigit ) + " ... int_iss: " + str ( int_iss ) )
if ' - ' in temploc and temploc . find ( reiss [ ' Issue_Number ' ] ) > temploc . find ( ' - ' ) :
logger . fdebug ( " I ' ve detected a possible Title in the filename " )
logger . fdebug ( " the issue # has occured after the -, so I ' m assuming it ' s part of the Title " )
break
2013-04-07 18:06:36 +00:00
for d in issuedupechk :
2013-07-01 05:19:15 +00:00
if int ( d [ ' fcdigit ' ] ) == int ( fcdigit ) :
2013-04-07 18:06:36 +00:00
logger . fdebug ( " duplicate issue detected - not counting this: " + str ( tmpfc [ ' ComicFilename ' ] ) )
2013-07-01 05:19:15 +00:00
logger . fdebug ( " is a duplicate of " + d [ ' filename ' ] )
logger . fdebug ( " fcdigit: " + str ( fcdigit ) + " === dupedigit: " + str ( d [ ' fcdigit ' ] ) )
2013-04-07 18:06:36 +00:00
issuedupe = " yes "
break
if issuedupe == " no " :
logger . fdebug ( " matched...issue: " + rescan [ ' ComicName ' ] + " # " + str ( reiss [ ' Issue_Number ' ] ) + " --- " + str ( int_iss ) )
havefiles + = 1
haveissue = " yes "
isslocation = str ( tmpfc [ ' ComicFilename ' ] )
issSize = str ( tmpfc [ ' ComicSize ' ] )
logger . fdebug ( " .......filename: " + str ( isslocation ) )
logger . fdebug ( " .......filesize: " + str ( tmpfc [ ' ComicSize ' ] ) )
# to avoid duplicate issues which screws up the count...let's store the filename issues then
# compare earlier...
issuedupechk . append ( { ' fcdigit ' : int ( fcdigit ) ,
2013-07-01 05:19:15 +00:00
' filename ' : tmpfc [ ' ComicFilename ' ] } )
2012-12-31 16:52:16 +00:00
break
#else:
# if the issue # matches, but there is no year present - still match.
# determine a way to match on year if present, or no year (currently).
2013-04-02 08:56:24 +00:00
2013-07-01 05:19:15 +00:00
if issuedupe == " yes " :
logger . fdebug ( " I should break out here because of a dupe. " )
break
som + = 1
if haveissue == " yes " or issuedupe == " yes " : break
n + = 1
else :
# annual inclusion here.
#logger.fdebug("checking " + str(temploc))
reannuals = myDB . action ( ' SELECT * FROM annuals WHERE ComicID=? ' , [ ComicID ] ) . fetchall ( )
an_cnt = myDB . action ( " SELECT COUNT(*) FROM issues WHERE ComicID=? " , [ ComicID ] ) . fetchall ( )
fcnew = shlex . split ( str ( temploc ) )
fcn = len ( fcnew )
anncnt = an_cnt [ 0 ] [ 0 ]
n = 0
while ( n < anncnt ) :
som = 0
try :
reann = reannuals [ n ]
except IndexError :
break
int_iss , iss_except = helpers . decimal_issue ( reann [ ' Issue_Number ' ] )
issyear = reann [ ' IssueDate ' ] [ : 4 ]
old_status = reann [ ' Status ' ]
while ( som < fcn ) :
#counts get buggered up when the issue is the last field in the filename - ie. '50$
#logger.fdebug("checking word - " + str(fcnew[som]))
if " .cbr " in fcnew [ som ] . lower ( ) :
fcnew [ som ] = fcnew [ som ] . replace ( " .cbr " , " " )
elif " .cbz " in fcnew [ som ] . lower ( ) :
fcnew [ som ] = fcnew [ som ] . replace ( " .cbz " , " " )
if " (c2c) " in fcnew [ som ] . lower ( ) :
fcnew [ som ] = fcnew [ som ] . replace ( " (c2c) " , " " )
get_issue = shlex . split ( str ( fcnew [ som ] ) )
if fcnew [ som ] != " " :
fcnew [ som ] = get_issue [ 0 ]
if fcnew [ som ] . lower ( ) == ' annual ' :
logger . fdebug ( " Annual detected. " )
if fcnew [ som + 1 ] . isdigit ( ) :
ann_iss = fcnew [ som + 1 ]
logger . fdebug ( " Annual # " + str ( ann_iss ) + " detected. " )
2013-08-06 00:53:10 +00:00
fcdigit = helpers . issuedigits ( ann_iss )
2013-07-01 05:19:15 +00:00
logger . fdebug ( " fcdigit: " + str ( fcdigit ) )
logger . fdebug ( " int_iss: " + str ( int_iss ) )
if int ( fcdigit ) == int_iss :
logger . fdebug ( " annual match - issue : " + str ( int_iss ) )
for d in annualdupechk :
if int ( d [ ' fcdigit ' ] ) == int ( fcdigit ) :
logger . fdebug ( " duplicate annual issue detected - not counting this: " + str ( tmpfc [ ' ComicFilename ' ] ) )
issuedupe = " yes "
break
if issuedupe == " no " :
logger . fdebug ( " matched...annual issue: " + rescan [ ' ComicName ' ] + " # " + str ( reann [ ' Issue_Number ' ] ) + " --- " + str ( int_iss ) )
havefiles + = 1
haveissue = " yes "
isslocation = str ( tmpfc [ ' ComicFilename ' ] )
issSize = str ( tmpfc [ ' ComicSize ' ] )
logger . fdebug ( " .......filename: " + str ( isslocation ) )
logger . fdebug ( " .......filesize: " + str ( tmpfc [ ' ComicSize ' ] ) )
# to avoid duplicate issues which screws up the count...let's store the filename issues then
# compare earlier...
annualdupechk . append ( { ' fcdigit ' : int ( fcdigit ) } )
break
2012-09-13 15:27:34 +00:00
som + = 1
2012-10-25 06:44:51 +00:00
if haveissue == " yes " : break
n + = 1
2013-07-01 05:19:15 +00:00
if issuedupe == " yes " : pass
else :
#we have the # of comics, now let's update the db.
#even if we couldn't find the physical issue, check the status.
if ' annual ' in temploc . lower ( ) :
2013-08-06 00:53:10 +00:00
iss_id = reann [ ' IssueID ' ]
2013-07-01 05:19:15 +00:00
else :
2013-08-06 00:53:10 +00:00
iss_id = reiss [ ' IssueID ' ]
logger . fdebug ( " issueID to write to db: " + str ( iss_id ) )
controlValueDict = { " IssueID " : iss_id }
2013-07-01 05:19:15 +00:00
#if Archived, increase the 'Have' count.
if archive :
issStatus = " Archived "
2013-08-06 00:53:10 +00:00
# if haveissue == "no" and issuedupe == "no":
# isslocation = "None"
# if old_status == "Skipped":
# if mylar.AUTOWANT_ALL:
# issStatus = "Wanted"
# else:
# issStatus = "Skipped"
# elif old_status == "Archived":
# havefiles+=1
# issStatus = "Archived"
# elif old_status == "Downloaded":
# issStatus = "Archived"
# havefiles+=1
# elif old_status == "Wanted":
# issStatus = "Wanted"
# elif old_status == "Ignored":
# issStatus = "Ignored"
# elif old_status == "Snatched": #this is needed for torrents, or else it'll keep on queuing..
# issStatus = "Snatched"
# else:
# issStatus = "Skipped"
#
# newValueDict = {"Status": issStatus }
2013-07-01 05:19:15 +00:00
elif haveissue == " yes " :
issStatus = " Downloaded "
newValueDict = { " Location " : isslocation ,
" ComicSize " : issSize ,
" Status " : issStatus
}
2013-08-06 03:20:09 +00:00
issID_to_ignore . append ( str ( iss_id ) )
2013-08-06 00:53:10 +00:00
2013-07-01 05:19:15 +00:00
if ' annual ' in temploc . lower ( ) :
myDB . upsert ( " annuals " , newValueDict , controlValueDict )
2012-10-30 10:43:01 +00:00
else :
2013-07-01 05:19:15 +00:00
myDB . upsert ( " issues " , newValueDict , controlValueDict )
2012-10-25 06:44:51 +00:00
fn + = 1
2012-09-13 15:27:34 +00:00
2013-08-06 00:53:10 +00:00
logger . fdebug ( " IssueID ' s to ignore: " + str ( issID_to_ignore ) )
2013-08-06 03:20:09 +00:00
2013-08-06 00:53:10 +00:00
#here we need to change the status of the ones we DIDN'T FIND above since the loop only hits on FOUND issues.
update_iss = [ ]
2013-08-06 03:20:09 +00:00
tmpsql = " SELECT * FROM issues WHERE ComicID=? AND IssueID not in ( {seq} ) " . format ( seq = ' , ' . join ( [ ' ? ' ] * ( len ( issID_to_ignore ) - 1 ) ) )
chkthis = myDB . action ( tmpsql , issID_to_ignore ) . fetchall ( )
# chkthis = None
2013-08-06 00:53:10 +00:00
if chkthis is None :
pass
else :
for chk in chkthis :
old_status = chk [ ' Status ' ]
logger . fdebug ( " old_status: " + str ( old_status ) )
if old_status == " Skipped " :
if mylar . AUTOWANT_ALL :
issStatus = " Wanted "
else :
issStatus = " Skipped "
elif old_status == " Archived " :
issStatus = " Archived "
elif old_status == " Downloaded " :
issStatus = " Archived "
elif old_status == " Wanted " :
issStatus = " Wanted "
elif old_status == " Ignored " :
issStatus = " Ignored "
elif old_status == " Snatched " : #this is needed for torrents, or else it'll keep on queuing..
issStatus = " Snatched "
else :
issStatus = " Skipped "
logger . fdebug ( " new status: " + str ( issStatus ) )
update_iss . append ( { " IssueID " : chk [ ' IssueID ' ] ,
" Status " : issStatus } )
if len ( update_iss ) > 0 :
i = 0
#do it like this to avoid DB locks...
for ui in update_iss :
controlValueDict = { " IssueID " : ui [ ' IssueID ' ] }
newStatusValue = { " Status " : ui [ ' Status ' ] }
myDB . upsert ( " issues " , newStatusValue , controlValueDict )
i + = 1
2013-08-06 03:20:09 +00:00
logger . info ( " Updated the status of " + str ( i ) + " issues for " + rescan [ ' ComicName ' ] + " ( " + str ( rescan [ ' ComicYear ' ] ) + " ) that weren ' t found. " )
2012-09-13 15:27:34 +00:00
2013-04-10 02:28:27 +00:00
logger . info ( " Total files located: " + str ( havefiles ) )
foundcount = havefiles
arcfiles = 0
# if filechecker returns 0 files (it doesn't find any), but some issues have a status of 'Archived'
# the loop below won't work...let's adjust :)
arcissues = myDB . action ( " SELECT count(*) FROM issues WHERE ComicID=? and Status= ' Archived ' " , [ ComicID ] ) . fetchall ( )
if int ( arcissues [ 0 ] [ 0 ] ) > 0 :
arcfiles = arcissues [ 0 ] [ 0 ]
havefiles = havefiles + arcfiles
logger . fdebug ( " Adjusting have total to " + str ( havefiles ) + " because of this many archive files: " + str ( arcfiles ) )
2013-07-30 04:57:37 +00:00
ignorecount = 0
if mylar . IGNORE_HAVETOTAL : # if this is enabled, will increase Have total as if in Archived Status
ignores = myDB . action ( " SELECT count(*) FROM issues WHERE ComicID=? AND Status= ' Ignored ' " , [ ComicID ] ) . fetchall ( )
if int ( ignores [ 0 ] [ 0 ] ) > 0 :
ignorecount = ignores [ 0 ] [ 0 ]
havefiles = havefiles + ignorecount
logger . fdebug ( " Adjusting have total to " + str ( havefiles ) + " because of this many Ignored files: " + str ( ignorecount ) )
2012-09-13 15:27:34 +00:00
2012-10-30 10:43:01 +00:00
#now that we are finished...
#adjust for issues that have been marked as Downloaded, but aren't found/don't exist.
#do it here, because above loop only cycles though found comics using filechecker.
2013-04-10 02:28:27 +00:00
downissues = myDB . select ( " SELECT * FROM issues WHERE ComicID=? and Status= ' Downloaded ' " , [ ComicID ] )
2012-10-30 10:43:01 +00:00
if downissues is None :
pass
else :
2013-04-10 02:28:27 +00:00
archivedissues = 0 #set this to 0 so it tallies correctly.
2012-10-30 10:43:01 +00:00
for down in downissues :
#print "downlocation:" + str(down['Location'])
2012-12-31 16:52:16 +00:00
#remove special characters from
#temploc = rescan['ComicLocation'].replace('_', ' ')
#temploc = re.sub('[\#\'\/\.]', '', temploc)
#print ("comiclocation: " + str(rescan['ComicLocation']))
#print ("downlocation: " + str(down['Location']))
2013-03-29 04:02:35 +00:00
if down [ ' Location ' ] is None :
logger . fdebug ( " location doesn ' t exist which means file wasn ' t downloaded successfully, or was moved. " )
controlValue = { " IssueID " : down [ ' IssueID ' ] }
newValue = { " Status " : " Archived " }
myDB . upsert ( " issues " , newValue , controlValue )
2013-04-10 02:28:27 +00:00
archivedissues + = 1
2012-10-30 15:40:41 +00:00
pass
2012-10-30 10:43:01 +00:00
else :
2013-03-29 04:02:35 +00:00
comicpath = os . path . join ( rescan [ ' ComicLocation ' ] , down [ ' Location ' ] )
if os . path . exists ( comicpath ) :
pass
#print "Issue exists - no need to change status."
else :
#print "Changing status from Downloaded to Archived - cannot locate file"
controlValue = { " IssueID " : down [ ' IssueID ' ] }
newValue = { " Status " : " Archived " }
2013-04-10 02:28:27 +00:00
myDB . upsert ( " issues " , newValue , controlValue )
archivedissues + = 1
totalarc = arcfiles + archivedissues
2013-04-10 15:59:12 +00:00
havefiles = havefiles + archivedissues #arcfiles already tallied in havefiles in above segment
2013-04-10 02:28:27 +00:00
logger . fdebug ( " I ' ve changed the status of " + str ( archivedissues ) + " issues to a status of Archived, as I now cannot locate them in the series directory. " )
#let's update the total count of comics that was found.
controlValueStat = { " ComicID " : rescan [ ' ComicID ' ] }
newValueStat = { " Have " : havefiles
}
myDB . upsert ( " comics " , newValueStat , controlValueStat )
2013-07-30 04:57:37 +00:00
logger . info ( u " I ' ve physically found " + str ( foundcount ) + " issues, ignored " + str ( ignorecount ) + " issues, and accounted for " + str ( totalarc ) + " in an Archived state. Total Issue Count: " + str ( havefiles ) + " / " + str ( rescan [ ' Total ' ] ) )
2012-10-30 10:43:01 +00:00
2012-09-13 15:27:34 +00:00
return