-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added experimental 'upload to mad' (misc/madupload.py)
- Loading branch information
Showing
3 changed files
with
71 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|