Skip to content

Commit

Permalink
Windows fix and better error handling for madupload
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Mar 18, 2015
1 parent 8a8e2d6 commit 638600f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions misc/madupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,32 @@
raise SystemExit(
"Usage: {} <filename>\n"
"Uploads 'filename' to Maddavo's site, where filename should be "
"a .prices or Station.csv file.\n"
"a .prices, Station.csv or ShipVendor.csv file.\n"
"\n"
"NOTE to OCR USERS:\n"
"Please upload the .prices file from your OCR DIRECTLY before "
"importing it into TD, not after.".format(sys.argv[0])
)

upfile = sys.argv[1]
uppath = pathlib.Path(upfile)

############################################################################


if not pathlib.Path(upfile).is_file():
raise SystemExit("ERROR: File not found: {}".format(upfile))
if not uppath.exists():
raise SystemExit("ERROR: {}: File not found".format(upfile))
if not uppath.is_file():
raise SystemExit("ERROR: {}: Not a file".format(upfile))

r = requests.post(
upload_url,
files={
'Filename': (
upfile,
open(upfile, 'rb'),
uppath.name,
uppath.open("rb"),
'text/plain',
{
"Expires": '300',
"Expires": '90',
}
),
}
Expand All @@ -76,5 +78,7 @@
if resultCode.startswith("SUCCESS"):
raise SystemExit("Upload complete")

print("Upload failed: {}".format(resultCode))

print("Error response from Maddavo's site: {}".format(resultCode))
with open("tmp/maderror.txt", "w") as out:
print(r.text, file=out)
print("See tmp/maderror.txt for full response.")

0 comments on commit 638600f

Please sign in to comment.