Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Added custom exceptions file to allow for user-based exceptions, as w…
Browse files Browse the repository at this point in the history
…ell as being able to maintain a base file in exceptions.csv
  • Loading branch information
evilhero committed Oct 20, 2012
1 parent 150dcd7 commit c9acfb4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 28 deletions.
21 changes: 21 additions & 0 deletions custom_exceptions_sample.csv
@@ -0,0 +1,21 @@
# Mylar Custom Exception listings
# In an effort to map ComicVine to GCD correctly, use this.
#
#
# Make changes/additions, and rename this file to 'custom_exceptions.csv'.
#
#
# Required Format, : code, ComicVineID, GCDComicID, GCDComicIDs (for volume spanning series)
# ----Format Breakdown
# code = # of volumes in series to be checked minus 1 (if there are 4 volumes in a series, put 3)
# = 99 is mismatched names. If a series won't match on GCD, this is what you would put.
# ComicVineID = the ComicVineID (taken from the searchresults, or the ..Loading.. detail screen)
# GCDComicID = the correct GCD Comic ID that Mylar is to match with.
# GCDComicIDs = put the GCD Comic ID's here for the given multiple volume spanning series seperated by a '/'
# use 'none' if you are not using an option (yes, it's necessary)
#
#-----Volume Spanning Series-----

#-----Mismatched Names------
#test
99,1111,22222,none
20 changes: 8 additions & 12 deletions exceptions.csv
@@ -1,16 +1,12 @@
#Mylar Exception listings
# In an effort to map ComicVine to GCD correctly, use this.
# Mylar Exception listings
# In an effort to map ComicVine to GCD correctly, this file will be imported into Mylar.
#----
#Required Format : code, ComicVineID, GCDComicID, GCDComicIDs (for volume spanning series)
#----Format Breakdown
#code = # of volumes in series to be checked minus 1 (if there are 4 volumes in a series, put 3)
= 99 is mismatched names. If a series won't match on GCD, this is what you would put.
#ComicVineID = the ComicVineID (taken from the searchresults, or the ..Loading.. detail screen)
#GCDComicID = the correct GCD Comic ID that Mylar is to match with.
#GCDComicIDs = put the GCD Comic ID's here for the given multiple volume spanning series seperated by a '/'
#use 'none' if you are not using an option (yes, it's necessary)
#--------
#--------
#
######### DO NOT USE THIS FILE TO ADD YOUR OWN EXCEPTIONS! ###########
# USE custom_exceptions.csv FOR USER-ADDED EXCEPTIONS. #
# NOT DOING THIS WILL RESULT IN LOSING YOUR USER-ADDED EXCEPTIONS. #
######################################################################
#
#-----Volume Spanning Series-----
#Fantastic Four
4,2045,none,1482/10251/6029/11218/62349
Expand Down
48 changes: 32 additions & 16 deletions mylar/__init__.py
Expand Up @@ -521,30 +521,46 @@ def dbcheck():
# c.execute('CREATE TABLE IF NOT EXISTS weekly (SHIPDATE, PUBLISHER text, ISSUE text, COMIC VARCHAR(150), EXTRA text, STATUS text)')

#new
logger.info(u"Populating Exception listings into Mylar....")
c.execute('DROP TABLE IF EXISTS exceptions')

c.execute('CREATE TABLE IF NOT EXISTS exceptions (variloop TEXT, ComicID TEXT, NewComicID TEXT, GComicID TEXT)')

EXCEPTIONS_FILE = os.path.join(DATA_DIR, 'exceptions.csv')
# for Mylar-based Exception Updates....
i = 0
EXCEPTIONS = []
EXCEPTIONS.append('exceptions.csv')
EXCEPTIONS.append('custom_exceptions.csv')

if not os.path.exists(EXCEPTIONS_FILE):
try:
while (i <= 1):
#EXCEPTIONS_FILE = os.path.join(DATA_DIR, 'exceptions.csv')
EXCEPTIONS_FILE = os.path.join(DATA_DIR, EXCEPTIONS[i])

if not os.path.exists(EXCEPTIONS_FILE):
try:
csvfile = open(str(EXCEPTIONS_FILE), "rb")
except (OSError,IOError):
if i == 1:
logger.error("No Custom Exceptions found. Using base exceptions only.")
else:
logger.error("Could not locate " + str(EXCEPTIONS[i]) + " file. Make sure it's in datadir: " + DATA_DIR)
break
else:
csvfile = open(str(EXCEPTIONS_FILE), "rb")
except OSError:
logger.error('Could not locate exceptions.csv file. Check in datadir: ' + DATA_DIR)
else:
csvfile = open(str(EXCEPTIONS_FILE), "rb")
if i == 0:
logger.info(u"Populating Base Exception listings into Mylar....")
elif i == 1:
logger.info(u"Populating Custom Exception listings into Mylar....")

creader = csv.reader(csvfile, delimiter=',')
creader = csv.reader(csvfile, delimiter=',')

for row in creader:
try:
c.execute("INSERT INTO exceptions VALUES (?,?,?,?);", row)
except Exception, e:
#print ("Error - invald arguments...-skipping")
pass
csvfile.close()
for row in creader:
try:
c.execute("INSERT INTO exceptions VALUES (?,?,?,?);", row)
except Exception, e:
#print ("Error - invald arguments...-skipping")
pass
csvfile.close()
i+=1

#c.executemany("INSERT INTO exceptions VALUES (?, ?);", to_db)

Expand Down

0 comments on commit c9acfb4

Please sign in to comment.