Skip to content

Commit

Permalink
updated v0.7.3
Browse files Browse the repository at this point in the history
- Now constantly checks for updated version incase your porder version is not udpated.
- Aded a reorder tool for users to reoder an exiting order or failed order.
  • Loading branch information
samapriya committed May 16, 2020
1 parent 4c004f7 commit a57bf0b
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 3 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ http://doi.org/10.5281/zenodo.3781275
* [idcheck](#idcheck)
* [bundles](#bundles)
* [order](#order)
* [reorder](#reorder)
* [cancel](#cancel)
* [orderstate list](#orderstate-list)
* [ordersize](#ordersize)
Expand Down Expand Up @@ -333,6 +334,24 @@ A simple setup with Top of Atmospher reflectance and a few indices along with em

![porder_indices](https://user-images.githubusercontent.com/6677629/61171621-48da3880-a548-11e9-8ab9-c3a3658c7d5b.png)


### reorder
This tool allows you to reorder an existing order with the same item ids and tools. This is tyring to look into the overall strucutre of existing orders and maybe ueful to reorder if an order fails for example.

```
usage: porder reorder [-h] --url URL [--notification NOTIFICATION]
optional arguments:
-h, --help show this help message and exit
Required named arguments.:
--url URL Order url to be ordered
Optional named arguments:
--notification NOTIFICATION
Use "email" to get an email notification
```

### cancel
You can cancel a queued order or cancel all queued orders, before the status changes to running. Simply put you can cancel a specific order before it starts running or cancel all of your queued orders.

Expand Down Expand Up @@ -433,6 +452,10 @@ A simple setup would be

## Changelog

### v0.7.3
- Now constantly checks for updated version incase your porder version is not udpated.
- Aded a reorder tool for users to reoder an exiting order or failed order.

### v0.7.1
- ID check tool now works with/without geometry, pass an idlist, and item and asset type to check.
- Order size tool is optimized for speed.
Expand Down
Binary file removed dist/porder-0.7.2.tar.gz
Binary file not shown.
Binary file not shown.
Binary file added dist/porder-0.7.3.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion porder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = 'Samapriya Roy'
__email__ = '[email protected]'
__version__ = '0.7.2'
__version__ = '0.7.3'
24 changes: 23 additions & 1 deletion porder/porder.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
from .ordstat import ostat
from .async_downloader import asyncdownload
from .idcheck import idc
from .resubmit import reorder
from planet.api.auth import find_api_key
if str(platform.python_version()) > "3.3.0":
from .async_down import downloader
Expand All @@ -109,7 +110,15 @@

# Get package version
def porder_version():
print(pkg_resources.get_distribution("porder").version)
url='https://pypi.org/project/porder/'
source = requests.get(url)
html_content = source.text
soup = BeautifulSoup(html_content, "html.parser")
company = soup.find('h1')
if not pkg_resources.get_distribution("porder").version == company.string.strip().split(' ')[-1]:
print("\n"+"=========================================================================")
print('Current version of porder is {} upgrade to lastest version: {}'.format(pkg_resources.get_distribution("porder").version,company.string.strip().split(' ')[-1]))
print("=========================================================================")
def version_from_parser(args):
porder_version()

Expand Down Expand Up @@ -304,6 +313,10 @@ def order_from_parser(args):
azure=args.azure,
gcs=args.gcs)

#Reorer an old or failed order
def reorder_from_parser(args):
reorder(url=args.url, notification=args.notification)

# Cancel an order or all order
def cancel(id):
headers = {'Content-Type': 'application/json'}
Expand Down Expand Up @@ -392,6 +405,8 @@ def multiproc_from_parser(args):
subprocess.call("python multiproc_pydl.py "+args.url+" "+args.local+" ",shell=True)
else:
subprocess.call("python multiproc_pydl.py "+args.url+" "+args.local+" "+args.ext,shell=True)
porder_version()
print('')

spacing=" "

Expand Down Expand Up @@ -492,6 +507,13 @@ def main(args=None):

parser_order.set_defaults(func=order_from_parser)

parser_reorder = subparsers.add_parser('reorder', help='Reorder an existing order')
required_named = parser_reorder.add_argument_group('Required named arguments.')
required_named.add_argument('--url', help='Order url to be ordered', required=True)
optional_named = parser_reorder.add_argument_group('Optional named arguments')
optional_named.add_argument('--notification', help='Use "email" to get an email notification',default=None)
parser_reorder.set_defaults(func=reorder_from_parser)

parser_cancel = subparsers.add_parser('cancel',help='Cancel queued order(s)')
parser_cancel.add_argument('--id',help='order id you want to cancel use "all" to cancel all')
parser_cancel.set_defaults(func=cancel_from_parser)
Expand Down
100 changes: 100 additions & 0 deletions porder/resubmit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
__copyright__ = """
Copyright 2019 Samapriya Roy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
__license__ = "Apache 2.0"


import requests
import json
import clipboard
import sys
from datetime import date
from planet.api.auth import find_api_key

# Get Planet API and Authenticate SESSION
try:
PL_API_KEY = find_api_key()
except:
print("Failed to get Planet Key")
sys.exit()
SESSION = requests.Session()
SESSION.auth = (PL_API_KEY, "")

base_payload = {
"name": [],
"order_type": "partial",
"products": [],
"tools": [],
"delivery": {},
}

order_url = "https://api.planet.com/compute/ops/orders/v2"


def reorder(url, notification):
submitted_order = SESSION.get(url)
if submitted_order.status_code == 200:
payload = submitted_order.json()
if notification is not None and notification == "email":
base_payload.update({"notifications": {"email": True}})
today = date.today()
base_payload["name"] = payload["name"].replace(
payload["name"], payload["name"] + "-resubmit-" + str(today)
)
base_payload["products"] = payload["products"]
if "tools" in payload:
base_payload["tools"] = payload["tools"]
else:
base_payload.pop("tools", None)
if "delivery" in payload:
base_payload["delivery"] = payload["delivery"]
if "notifications" in payload:
base_payload["notifications"] = payload["notifications"]
payload_final = json.dumps(base_payload)
# print(payload_final)
headers = {"content-type": "application/json", "cache-control": "no-cache"}
response = SESSION.post(order_url, data=payload_final, headers=headers)
if response.status_code == 202:
content = response.json()
try:
clipboard.copy(str(order_url) + "/" + str(content["id"]))
print(
"Order created at "
+ str(order_url)
+ "/"
+ str(content["id"] + " and url copied to clipboard")
)
return str(order_url) + "/" + str(content["id"])
except Exception:
print(
"Headless Setup: Order created at "
+ str(order_url)
+ "/"
+ str(content["id"])
)
elif response.status_code == 400:
print("Failed with response: Bad request")
print(response.json()["general"][0]["message"])
elif response.status_code == 401:
print("Failed with response: Forbidden")
elif response.status_code == 409:
print("Failed with response: MaxConcurrency")
else:
print(response.text)


# reorder(url='https://api.planet.com/compute/ops/orders/v2/495cddcf-d8bf-406b-96e7-d679e162471e',notification='email')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def readme():
return f.read()
setuptools.setup(
name='porder',
version='0.7.2',
version='0.7.3',
packages=['porder'],
url='https://github.com/samapriya/porder',
package_data={'': ['bundles.json']},
Expand Down

0 comments on commit a57bf0b

Please sign in to comment.