Add support for frequent delivery addresses via .json files

This commit is contained in:
Enrique Barcelli 2024-08-14 01:38:21 +08:00
parent 15614329c4
commit 79240557a1
Signed by: kikobar
GPG key ID: 006C13A68E25D3B7
5 changed files with 25 additions and 9 deletions

2
.gitignore vendored
View file

@ -1,5 +1,7 @@
# Sensitive files
config.py
*.json
*.JSON
# ---> Python
# Byte-compiled / optimized / DLL files

View file

@ -0,0 +1,8 @@
{
"default_delivery_name" : "Lisa Doe",
"default_delivery_number" : "87654321",
"default_delivery_email" : "",
"default_delivery_address" : "2 Orchard Turn, Singapore 238801",
"default_delivery_pincode" : "238801",
"default_delivery_remark" : ""
}

View file

@ -12,7 +12,10 @@ These Python scripts allow to place, track and delete delivery requests using th
* Copy the file `config-sample.py` to `config.py`.
* Edit `config.py` with your credentials and defaults.
* To place a delivery request, run `python3 req_delivery.py` and follow the instructions of the script.
* Inside the folder `JSON files` copy the `default_address.json.sample` to `default_address.json`.
* Edit `default_address.json` with your defaults for the delivery address.
* Using `default_address.json` as a template, you may create personalised `.json` files for your frequent delivery addresses.
* To place a delivery request, run `python3 req_delivery.py <address.json>` and follow the instructions of the script. If you leave the parameter `<address.json>` blank, the script will use the data from `default_address.json`.
* To track the status of a delivery request, run `python3 track.py <track_id>`, where `<track_id>` is the uParcel trucking code of your delivery.
* To cancel a delivery request, run `python3 cancel_delivery.py <order_id>`, where `<order_id>` is the Order ID you provided when you made the request *(note that this is NOT the `<track_id>`)*.

View file

@ -22,10 +22,4 @@ default_pickup_address = "1 Scotts Road, Singapore 228208"
default_pickup_pincode = "228208"
default_pickup_remark = ""
default_vehicle = "all"
default_delivery_name = "Lisa Doe"
default_delivery_number = "87654321"
default_delivery_email = ""
default_delivery_address = "2 Orchard Turn, Singapore 238801"
default_delivery_pincode = "238801"
default_delivery_remark = ""

View file

@ -5,7 +5,16 @@ from push import *
import sys
import base64
def req_delivery():
def req_delivery(address_file='default_address.json'):
f = open("JSON files/"+address_file)
address = json.load(f)
f.close()
default_delivery_name = address['default_delivery_name']
default_delivery_number = address['default_delivery_number']
default_delivery_email = address['default_delivery_email']
default_delivery_address = address['default_delivery_address']
default_delivery_pincode = address['default_delivery_pincode']
default_delivery_remark = address['default_delivery_remark']
order_id = int(input('Enter the Order ID: ') or '1')
url = base_url + "api/merchant/auth/"
payload = json.dumps({
@ -123,5 +132,5 @@ def req_delivery():
})))
if __name__ == '__main__':
req_delivery()
req_delivery(sys.argv[1])