mirror of https://github.com/evilhero/mylar
IMP: Changed from io.open to csv for export method, consolidated sql query into one line, will create alternate file if cannot remove pre-existing csv file
This commit is contained in:
parent
7cb179d21f
commit
e685002c05
|
@ -665,10 +665,11 @@ class WebInterface(object):
|
||||||
def wanted_Export(self,mode):
|
def wanted_Export(self,mode):
|
||||||
import unicodedata
|
import unicodedata
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
wantlist = myDB.select("SELECT * FROM issues WHERE Status=? AND ComicName NOT NULL", [mode])
|
wantlist = myDB.select("select b.ComicName, b.ComicYear, a.Issue_Number, a.IssueDate, a.ComicID, a.IssueID from issues a inner join comics b on a.ComicID=b.ComicID where a.status=? and b.ComicName is not NULL", [mode])
|
||||||
if wantlist is None:
|
if wantlist is None:
|
||||||
logger.info("There aren't any issues marked as " + mode + ". Aborting Export.")
|
logger.info("There aren't any issues marked as " + mode + ". Aborting Export.")
|
||||||
return
|
return
|
||||||
|
|
||||||
#write out a wanted_list.csv
|
#write out a wanted_list.csv
|
||||||
logger.info("gathered data - writing to csv...")
|
logger.info("gathered data - writing to csv...")
|
||||||
wanted_file = os.path.join(mylar.DATA_DIR, str(mode) + "_list.csv")
|
wanted_file = os.path.join(mylar.DATA_DIR, str(mode) + "_list.csv")
|
||||||
|
@ -676,32 +677,32 @@ class WebInterface(object):
|
||||||
try:
|
try:
|
||||||
os.remove(wanted_file)
|
os.remove(wanted_file)
|
||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
pass
|
wanted_file_new = os.path.join(mylar.DATA_DIR, str(mode) + '_list-1.csv')
|
||||||
|
logger.warn('%s already exists. Writing to: %s' % (wanted_file, wanted_file_new))
|
||||||
|
wanted_file = wanted_file_new
|
||||||
|
|
||||||
wcount=0
|
wcount=0
|
||||||
try:
|
with open(wanted_file, 'wb+') as f:
|
||||||
f = io.open(wanted_file, mode="w+", encoding="utf-8")
|
try:
|
||||||
except IOError:
|
fieldnames = ['SeriesName','SeriesYear','IssueNumber','IssueDate','ComicID','IssueID']
|
||||||
logger.info("Error opening {}. Is it being used by another program?".format(wanted_file))
|
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
||||||
return
|
writer.writeheader()
|
||||||
|
for want in wantlist:
|
||||||
|
writer.writerow({'SeriesName': want['ComicName'],
|
||||||
|
'SeriesYear': want['ComicYear'],
|
||||||
|
'IssueNumber': want['Issue_Number'],
|
||||||
|
'IssueDate': want['IssueDate'],
|
||||||
|
'ComicID': want['ComicID'],
|
||||||
|
'IssueID': want['IssueID']})
|
||||||
|
wcount += 1
|
||||||
|
except IOError as Argument:
|
||||||
|
logger.info("Error writing value to {}. {}".format(wanted_file, Argument))
|
||||||
|
except Exception as Argument:
|
||||||
|
logger.info("Unknown error: {}".format(Argument))
|
||||||
|
if wcount > 0:
|
||||||
|
logger.info('Successfully wrote to csv file %s entries from your %s list.' % (wcount, mode))
|
||||||
else:
|
else:
|
||||||
with f:
|
logger.info('Nothing written to csv file for your %s list.' % mode)
|
||||||
try:
|
|
||||||
f.write(u"SeriesName,SeriesYear,IssueNumber,IssueDate,ComicID,IssueID\n")
|
|
||||||
for want in wantlist:
|
|
||||||
wantcomic = myDB.selectone("SELECT * FROM comics WHERE ComicID=?", [want['ComicID']]).fetchone()
|
|
||||||
exceptln = u'{},{},{},{},{},{}\n'.format(wantcomic['ComicName'], wantcomic['ComicYear'],
|
|
||||||
want['Issue_Number'], want['IssueDate'],
|
|
||||||
want['ComicID'], want['IssueID'])
|
|
||||||
wcount += 1
|
|
||||||
f.write(exceptln)
|
|
||||||
f.flush()
|
|
||||||
logger.debug(exceptln)
|
|
||||||
except IOError as Argument:
|
|
||||||
logger.info("Error writing value to {}. {}".format(wanted_file, Argument))
|
|
||||||
except Exception as Argument:
|
|
||||||
logger.info("Unknown error: {}".format(Argument))
|
|
||||||
logger.info("Successfully wrote to csv file " + str(wcount) + " entries from your " + mode + " list.")
|
|
||||||
|
|
||||||
raise cherrypy.HTTPRedirect("home")
|
raise cherrypy.HTTPRedirect("home")
|
||||||
wanted_Export.exposed = True
|
wanted_Export.exposed = True
|
||||||
|
@ -5439,7 +5440,6 @@ class WebInterface(object):
|
||||||
|
|
||||||
|
|
||||||
def orderThis(self, **kwargs):
|
def orderThis(self, **kwargs):
|
||||||
logger.info('here')
|
|
||||||
return
|
return
|
||||||
orderThis.exposed = True
|
orderThis.exposed = True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue