Skip to content

Commit

Permalink
display info/error messages when exporting results
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzy69 committed May 24, 2017
1 parent 0da68c8 commit 5b648e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions .json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
27 changes: 18 additions & 9 deletions application/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ def exportResults(self):
"""
Export table/model data to csv or json file on disk drive
"""
filePath, fileType = QtWidgets.QFileDialog.getSaveFileName(self, "Export results", "/mnt/ramdisk/results", filter="CSV files (*.csv);;JSON files (*.json)")
data = []
model = self.sitesModel
for i in range(model.rowCount()):
Expand All @@ -295,11 +294,21 @@ def exportResults(self):
"URL": url,
"Rank": rank,
})
if "csv" in fileType:
with open(filePath + ".csv", 'w') as f:
w = csv.DictWriter(f, ["URL", "Rank"])
w.writeheader()
w.writerows(data)
else:
with open(filePath + ".json", 'w') as f:
f.write(json.dumps(data))
if not data:
return
filePath, fileType = QtWidgets.QFileDialog.getSaveFileName(self, "Export results", "/mnt/ramdisk/results", filter="CSV files (*.csv);;JSON files (*.json)")
try:
if "csv" in fileType:
ft = "csv"
with open(filePath + ".csv", 'w') as f:
w = csv.DictWriter(f, ["URL", "Rank"])
w.writeheader()
w.writerows(data)
else:
ft = "json"
with open(filePath + ".json", 'w') as f:
f.write(json.dumps(data))
except Exception as e:
QtWidgets.QMessageBox.warning(self, "Error", str(e))
return
QtWidgets.QMessageBox.information(self, "Info", "Successfully exported results to {}".format(filePath + "." + ft))

0 comments on commit 5b648e9

Please sign in to comment.