Skip to content

Commit

Permalink
Added experimental 'upload to mad' (misc/madupload.py)
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Dec 30, 2014
1 parent cee6a1b commit a9de85a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

WIP:
. (kfsone) Added experimental "upload-to-maddavo" (misc/madupload.py)
. (kfsone) Improved the feedback from run when routes go wrong.
. (kfsone) fixed "--link-ly" causing a 'TypeError' in various places,
. (kfsone) "nav" now supports "--via"; destinations are processed in-order.
Expand Down
24 changes: 0 additions & 24 deletions commands/update_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,30 +371,6 @@ def guidedUpdate(tdb, cmdenv):
saveTemporaryFile(tmpPath)


def uploadUpdated():
try:
import requests
except ImportError:
if platform.system() == "Windows":
prompt = "C:\ThisDir\>"
else:
prompt = "$"
raise SystemExit("""Missing 'requests' module:
You don't appear to have the Python module "requests" installed.
It can be installed with Python's package installer, e.g:
{prompt} pip install requests
For additional help, consult:
Bitbucket Wiki http://kfs.org/td/wiki
Facebook Group http://kfs.org/td/group
ED Forum Thread http://kfs.org/td/thread
""".format(
prompt=prompt
))


######################################################################
# Perform query and populate result set

Expand Down
70 changes: 70 additions & 0 deletions misc/madupload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pathlib
import platform
import re

try:
import requests
except ImportError:
if platform.system() == "Windows":
prompt = "C:\ThisDir\>"
else:
prompt = "$"
raise Exception("""Missing 'requests' module:
----------------------------------------------------------------
You don't appear to have the Python module "requests" installed.
It can be installed with Python's package installer, e.g:
{prompt} pip install requests
For additional help, see:
Bitbucket Wiki http://kfs.org/td/wiki
Facebook Group http://kfs.org/td/group
ED Forum Thread http://kfs.org/td/thread
----------------------------------------------------------------
""".format(
prompt=prompt
))


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


upload_url = 'http://www.davek.com.au/td/uploaddata.asp'
upfile = "updated.prices"


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


if not pathlib.Path(upfile).is_file():
raise SystemExit("ERROR: File not found: {}".format(upfile))

files = {
}
r = requests.post(
upload_url,
files={
'Filename': (
'updated.prices',
open('updated.prices', 'rb'),
'text/plain',
{
"Expires": '300',
}
),
}
)

response = r.text
m = re.search(r'UPLOAD RESULT:\s*(.*?)<br', response, re.IGNORECASE)
if not m:
raise Exception("Unexpected result:\n" + r.text)

resultCode = m.group(1)
if resultCode.startswith("SUCCESS"):
raise SystemExit("Upload complete")

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

0 comments on commit a9de85a

Please sign in to comment.