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
2012-09-13 15:27:34 +00:00
import mylar
from mylar import db , logger , helpers , filechecker
def dbUpdate ( ) :
myDB = db . DBConnection ( )
activecomics = myDB . select ( ' SELECT ComicID, ComicName from comics WHERE Status= " Active " or Status= " Loading " order by LastUpdated ASC ' )
2012-10-07 16:20:06 +00:00
logger . info ( ' Starting update for %i active comics ' % len ( activecomics ) )
2012-09-13 15:27:34 +00:00
for comic in activecomics :
comicid = comic [ 0 ]
2012-10-07 16:20:06 +00:00
mylar . importer . addComictoDB ( comicid )
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
def upcoming_update ( ComicID , ComicName , IssueNumber , IssueDate ) :
# here we add to upcoming table...
myDB = db . DBConnection ( )
2012-10-21 15:30:26 +00:00
2012-09-13 15:27:34 +00:00
controlValue = { " ComicID " : ComicID }
2012-10-16 08:16:29 +00:00
newValue = { " ComicName " : str ( ComicName ) ,
" IssueNumber " : str ( IssueNumber ) ,
" 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 ' ]
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"
2012-10-16 08:16:29 +00:00
issuechk = myDB . action ( " SELECT * FROM issues WHERE ComicID=? AND Issue_Number=? " , [ ComicID , IssueNumber ] ) . fetchone ( )
2012-12-31 16:52:16 +00:00
if issuechk is None :
2013-01-03 10:26:39 +00:00
logger . fdebug ( str ( ComicName ) + " 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.
upco_iss = myDB . action ( " SELECT COUNT(*) FROM UPCOMING WHERE ComicID=? " , [ ComicID ] ) . fetchone ( )
if upco_iss > 0 :
print ( " There is " + str ( upco_iss [ 0 ] ) + " of " + str ( ComicName ) + " that ' s not accounted for " )
2013-01-07 19:26:10 +00:00
if hours > 5 :
pullupd = " yes "
logger . fdebug ( " Now Refreshing comic " + str ( ComicName ) + " to make sure it ' s up-to-date " )
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. " )
logger . fdebug ( " Available to be marked for download - checking... " + str ( issuechk [ ' ComicName ' ] ) + " 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-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 "
values = { " Status " : " Wanted " }
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 ' ] )
2012-10-21 15:30:26 +00:00
2013-01-07 18:26:15 +00:00
if issuechk is None :
myDB . upsert ( " upcoming " , newValue , controlValue )
else :
myDB . upsert ( " issues " , values , control )
2013-01-03 10:26:39 +00:00
else :
logger . fdebug ( " Issues don ' t match for some reason... db issue: " + str ( issuechk [ ' Issue_Number ' ] ) + " ...weekly new issue: " + str ( IssueNumber ) )
2012-10-16 08:16:29 +00:00
2012-09-13 15:27:34 +00:00
def weekly_update ( ComicName ) :
# here we update status of weekly table...
myDB = db . DBConnection ( )
2012-10-16 08:16:29 +00:00
controlValue = { " COMIC " : str ( ComicName ) }
2012-09-13 15:27:34 +00:00
if mylar . AUTOWANT_UPCOMING :
newValue = { " STATUS " : " Wanted " }
else :
newValue = { " STATUS " : " Skipped " }
myDB . upsert ( " weekly " , newValue , controlValue )
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 " ,
" ComicName " : " None " }
2012-09-17 05:12:40 +00:00
myDB . upsert ( " comics " , newValue , controlValue )
2012-10-30 10:43:01 +00:00
def nzblog ( IssueID , NZBName ) :
myDB = db . DBConnection ( )
controlValue = { " IssueID " : IssueID }
2012-12-27 15:04:03 +00:00
#print controlValue
2012-10-30 10:43:01 +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 )
2012-09-13 15:27:34 +00:00
def foundsearch ( ComicID , IssueID ) :
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.
2012-09-13 15:27:34 +00:00
myDB = db . DBConnection ( )
comic = myDB . action ( ' SELECT * FROM comics WHERE ComicID=? ' , [ ComicID ] ) . fetchone ( )
issue = myDB . action ( ' SELECT * FROM issues WHERE IssueID=? ' , [ IssueID ] ) . fetchone ( )
CYear = issue [ ' IssueDate ' ] [ : 4 ]
2013-01-06 08:51:44 +00:00
# fc = filechecker.listFiles(comic['ComicLocation'], comic['ComicName'])
# HaveDict = {"ComicID": ComicID}
# newHave = { "Have": fc['comiccount'] }
# myDB.upsert("comics", newHave, HaveDict)
# #---
2012-09-13 15:27:34 +00:00
issue = myDB . action ( ' SELECT * FROM issues WHERE IssueID=? AND ComicID=? ' , [ IssueID , ComicID ] ) . fetchone ( )
2013-01-06 08:51:44 +00:00
# update the status to Snatched (so it won't keep on re-downloading!)
logger . fdebug ( " updating status to snatched " )
controlValue = { " IssueID " : IssueID }
newValue = { " Status " : " Snatched " }
myDB . upsert ( " issues " , newValue , controlValue )
# update the snatched DB
2012-09-13 15:27:34 +00:00
controlValueDict = { " IssueID " : IssueID }
newValueDict = { " Status " : " Snatched " }
2013-01-06 08:51:44 +00:00
logger . fdebug ( " updating snatched db. " )
2012-09-13 15:27:34 +00:00
myDB . upsert ( " issues " , newValueDict , controlValueDict )
snatchedupdate = { " IssueID " : IssueID }
newsnatchValues = { " ComicName " : comic [ ' ComicName ' ] ,
" ComicID " : ComicID ,
" Issue_Number " : issue [ ' Issue_Number ' ] ,
" DateAdded " : helpers . now ( ) ,
" Status " : " Snatched "
}
myDB . upsert ( " snatched " , newsnatchValues , snatchedupdate )
#print ("finished updating snatched db.")
logger . info ( u " Updating now complete for " + str ( comic [ ' ComicName ' ] ) + " issue: " + str ( issue [ ' Issue_Number ' ] ) )
return
def forceRescan ( ComicID ) :
myDB = db . DBConnection ( )
# file check to see if issue exists
rescan = myDB . action ( ' SELECT * FROM comics WHERE ComicID=? ' , [ ComicID ] ) . fetchone ( )
2012-09-18 20:33:09 +00:00
logger . info ( u " Now checking files for " + str ( rescan [ ' ComicName ' ] ) + " ( " + str ( rescan [ ' ComicYear ' ] ) + " ) in " + str ( rescan [ ' ComicLocation ' ] ) )
2013-01-07 20:35:17 +00:00
fc = filechecker . listFiles ( dir = rescan [ ' ComicLocation ' ] , 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 = [ ]
2012-09-13 15:27:34 +00:00
reissues = myDB . action ( ' SELECT * FROM issues WHERE ComicID=? ' , [ ComicID ] ) . fetchall ( )
2012-10-30 10:43:01 +00:00
# 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 . select ( " SELECT * FROM issues WHERE ComicID=? and Status= ' Archived ' " , [ ComicID ] )
if len ( arcissues ) > 0 :
havefiles = len ( arcissues )
2013-01-07 19:26:10 +00:00
logger . fdebug ( " Adjusting have total because of this many archive files: " + str ( len ( arcissues ) ) )
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-01-11 21:20:51 +00:00
#logger.fdebug("temploc: " + str(temploc))
2012-10-25 06:44:51 +00:00
if ' annual ' not in temploc :
2013-02-06 19:55:23 +00:00
#remove the extension here
extensions = ( ' .cbr ' , ' .cbz ' )
if temploc . lower ( ) . endswith ( extensions ) :
2013-02-09 03:34:02 +00:00
#print ("removed extension for issue:" + str(temploc))
2013-02-06 19:55:23 +00:00
temploc = temploc [ : - 4 ]
deccnt = str ( temploc ) . count ( ' . ' )
if deccnt > 1 :
2013-02-09 03:34:02 +00:00
#print ("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-02-09 03:34:02 +00:00
#print "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-02-09 03:34:02 +00:00
#print ("this is a decimal, assuming decimal issue.")
2013-02-06 19:55:23 +00:00
decimalfound = " yes "
reconst = " . " + temploc [ prevstart : start ] + " "
else :
2013-02-09 03:34:02 +00:00
#print ("digit detected.")
2013-02-06 19:55:23 +00:00
digitfound = " yes "
reconst = temploc [ prevstart : start ]
else :
reconst = temploc [ prevstart : start ] + " "
2013-02-09 03:34:02 +00:00
#print "word: " + reconst
2013-02-06 19:55:23 +00:00
tempreconstruct = tempreconstruct + reconst
2013-02-09 03:34:02 +00:00
#print ("tempreconstruct is : " + tempreconstruct)
2013-02-06 19:55:23 +00:00
prevstart = ( start + 1 )
occur + = 1
2013-02-09 03:34:02 +00:00
#print "word: " + temploc[prevstart:]
2013-02-06 19:55:23 +00:00
tempreconstruct = tempreconstruct + temploc [ prevstart : ]
2013-02-09 03:34:02 +00:00
#print ("final filename to use is : " + str(tempreconstruct))
2013-02-06 19:55:23 +00:00
temploc = tempreconstruct
2013-02-09 03:34:02 +00:00
#print("checking " + str(temploc))
2013-02-06 19:55:23 +00:00
fcnew = shlex . split ( str ( temploc ) )
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
2012-12-31 16:52:16 +00:00
int_iss = helpers . decimal_issue ( reiss [ ' Issue_Number ' ] )
2012-10-25 06:44:51 +00:00
issyear = reiss [ ' IssueDate ' ] [ : 4 ]
old_status = reiss [ ' Status ' ]
2012-12-31 16:52:16 +00:00
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 #...
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-02-13 01:27:24 +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-01-06 08:51:44 +00:00
if ' . ' in fcnew [ som ] :
2013-02-13 01:27:24 +00:00
#logger.fdebug("decimal detected...adjusting.")
2013-01-06 08:51:44 +00:00
try :
i = float ( fcnew [ som ] )
except ValueError , TypeError :
#not numeric
2013-01-18 07:32:05 +00:00
#logger.fdebug("NOT NUMERIC - new word: " + str(fcnew[som]))
2013-02-06 19:55:23 +00:00
fcnew [ som ] = fcnew [ som ] . replace ( " . " , " " )
2013-01-06 08:51:44 +00:00
else :
#numeric
pass
2013-01-02 17:56:46 +00:00
if fcnew [ som ] . isdigit ( ) :
2012-12-31 16:52:16 +00:00
#this won't match on decimal issues - need to fix.
2013-01-11 21:20:51 +00:00
#logger.fdebug("digit detected")
2012-09-13 15:27:34 +00:00
if int ( fcnew [ som ] ) > 0 :
2012-10-30 10:43:01 +00:00
# fcdigit = fcnew[som].lstrip('0')
2012-12-31 16:52:16 +00:00
#fcdigit = str(int(fcnew[som]))
fcdigit = int ( fcnew [ som ] ) * 1000
2012-10-30 10:43:01 +00:00
else :
2012-12-31 16:52:16 +00:00
#fcdigit = "0"
fcdigit = 0
elif " . " in fcnew [ som ] :
#this will match on decimal issues
IssueChk = fcnew [ som ]
2013-01-11 21:20:51 +00:00
#logger.fdebug("decimal detected...analyzing if issue")
2012-12-31 16:52:16 +00:00
isschk_find = IssueChk . find ( ' . ' )
isschk_b4dec = IssueChk [ : isschk_find ]
isschk_decval = IssueChk [ isschk_find + 1 : ]
if isschk_b4dec . isdigit ( ) :
2013-01-07 18:26:15 +00:00
#logger.fdebug("digit detected prior to decimal.")
2012-12-31 16:52:16 +00:00
if isschk_decval . isdigit ( ) :
2013-01-07 18:26:15 +00:00
pass
#logger.fdebug("digit detected after decimal.")
2012-12-31 16:52:16 +00:00
else :
2013-01-07 18:26:15 +00:00
#logger.fdebug("not an issue - no digit detected after decimal")
2013-01-06 08:51:44 +00:00
break
2012-12-31 16:52:16 +00:00
else :
2013-01-07 18:26:15 +00:00
#logger.fdebug("not an issue - no digit detected prior to decimal")
2013-01-06 08:51:44 +00:00
break
2013-01-07 18:26:15 +00:00
#logger.fdebug("IssueNumber: " + str(IssueChk))
#logger.fdebug("..before decimal: " + str(isschk_b4dec))
#logger.fdebug("...after decimal: " + str(isschk_decval))
2012-12-31 16:52:16 +00:00
#--let's make sure we don't wipe out decimal issues ;)
if int ( isschk_decval ) == 0 :
iss = isschk_b4dec
intdec = int ( isschk_decval )
else :
if len ( isschk_decval ) == 1 :
iss = isschk_b4dec + " . " + isschk_decval
intdec = int ( isschk_decval ) * 10
else :
iss = isschk_b4dec + " . " + isschk_decval . rstrip ( ' 0 ' )
intdec = int ( isschk_decval . rstrip ( ' 0 ' ) ) * 10
fcdigit = ( int ( isschk_b4dec ) * 1000 ) + intdec
2013-01-07 18:26:15 +00:00
#logger.fdebug("b4dec: " + str(isschk_b4dec))
#logger.fdebug("decval: " + str(isschk_decval))
#logger.fdebug("intdec: " + str(intdec))
#logger.fdebug("let's compare with this issue value: " + str(fcdigit))
2012-12-31 16:52:16 +00:00
else :
# it's a word, skip it.
2013-02-09 03:34:02 +00:00
fcdigit = 19283838380101193
2013-01-11 21:20:51 +00:00
#logger.fdebug("fcdigit: " + str(fcdigit))
#logger.fdebug("int_iss: " + str(int_iss))
2012-12-31 16:52:16 +00:00
if " . " in str ( int_iss ) :
int_iss = helpers . decimal_issue ( int_iss )
2013-01-11 21:20:51 +00:00
#logger.fdebug("this is the int issue:" + str(int_iss))
2012-12-31 16:52:16 +00:00
if int ( fcdigit ) == int_iss :
#if issyear in fcnew[som+1]:
# print "matched on year:" + str(issyear)
2013-01-03 10:01:07 +00:00
#issuedupechk here.
if int ( fcdigit ) in issuedupechk :
logger . fdebug ( " duplicate issue detected - not counting this: " + str ( tmpfc [ ' ComicFilename ' ] ) )
issuedupe = " yes "
break
2013-01-01 20:09:28 +00:00
logger . fdebug ( " matched...issue: " + str ( rescan [ ' ComicName ' ] ) + " --- " + str ( int_iss ) )
2012-12-31 16:52:16 +00:00
havefiles + = 1
haveissue = " yes "
isslocation = str ( tmpfc [ ' ComicFilename ' ] )
issSize = str ( tmpfc [ ' ComicSize ' ] )
logger . fdebug ( " .......filename: " + str ( isslocation ) )
logger . fdebug ( " .......filesize: " + str ( tmpfc [ ' ComicSize ' ] ) )
2013-01-03 10:01:07 +00:00
# to avoid duplicate issues which screws up the count...let's store the filename issues then
# compare earlier...
issuedupechk . append ( int ( fcdigit ) )
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).
2012-09-13 15:27:34 +00:00
som + = 1
2012-10-25 06:44:51 +00:00
if haveissue == " yes " : break
n + = 1
2012-09-13 15:27:34 +00:00
#we have the # of comics, now let's update the db.
2012-10-30 10:43:01 +00:00
#even if we couldn't find the physical issue, check the status.
#if Archived, increase the 'Have' count.
2013-01-03 10:01:07 +00:00
if haveissue == " no " and issuedupe == " no " :
2012-09-13 15:27:34 +00:00
isslocation = " None "
2012-10-30 10:43:01 +00:00
if old_status == " Skipped " :
if mylar . AUTOWANT_ALL :
2012-10-20 07:09:15 +00:00
issStatus = " Wanted "
2012-10-30 10:43:01 +00:00
else :
2012-10-20 07:09:15 +00:00
issStatus = " Skipped "
2012-10-30 10:43:01 +00:00
elif old_status == " Archived " :
havefiles + = 1
issStatus = " Archived "
elif old_status == " Downloaded " :
issStatus = " Archived "
havefiles + = 1
elif old_status == " Wanted " :
issStatus = " Wanted "
else :
issStatus = " Skipped "
2013-01-18 07:32:05 +00:00
controlValueDict = { " IssueID " : reiss [ ' IssueID ' ] }
newValueDict = { " Status " : issStatus }
2012-09-13 15:27:34 +00:00
elif haveissue == " yes " :
issStatus = " Downloaded "
2013-01-18 07:32:05 +00:00
controlValueDict = { " IssueID " : reiss [ ' IssueID ' ] }
newValueDict = { " Location " : isslocation ,
" ComicSize " : issSize ,
" Status " : issStatus
}
2012-09-13 15:27:34 +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
#let's update the total count of comics that was found.
controlValueStat = { " ComicID " : rescan [ ' ComicID ' ] }
newValueStat = { " Have " : havefiles
}
myDB . upsert ( " comics " , newValueStat , controlValueStat )
logger . info ( u " I ' ve found " + str ( havefiles ) + " / " + str ( rescan [ ' Total ' ] ) + " issues. " )
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.
downissues = myDB . action ( " SELECT * FROM issues WHERE ComicID=? and Status= ' Downloaded ' " , [ ComicID ] ) . fetchall ( )
if downissues is None :
pass
else :
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']))
2012-10-30 10:43:01 +00:00
comicpath = os . path . join ( rescan [ ' ComicLocation ' ] , down [ ' Location ' ] )
if os . path . exists ( comicpath ) :
2012-10-30 15:40:41 +00:00
pass
2012-10-30 10:43:01 +00:00
#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 " }
myDB . upsert ( " issues " , newValue , controlValue )
2012-09-13 15:27:34 +00:00
return