diff --git a/README.md b/README.md index 57e1096..377fc88 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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. @@ -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. diff --git a/dist/porder-0.7.2.tar.gz b/dist/porder-0.7.2.tar.gz deleted file mode 100644 index d6bab19..0000000 Binary files a/dist/porder-0.7.2.tar.gz and /dev/null differ diff --git a/dist/porder-0.7.2-py3-none-any.whl b/dist/porder-0.7.3-py3-none-any.whl similarity index 58% rename from dist/porder-0.7.2-py3-none-any.whl rename to dist/porder-0.7.3-py3-none-any.whl index db822a9..ef3fed2 100644 Binary files a/dist/porder-0.7.2-py3-none-any.whl and b/dist/porder-0.7.3-py3-none-any.whl differ diff --git a/dist/porder-0.7.3.tar.gz b/dist/porder-0.7.3.tar.gz new file mode 100644 index 0000000..5cb3148 Binary files /dev/null and b/dist/porder-0.7.3.tar.gz differ diff --git a/porder/__init__.py b/porder/__init__.py index ac2323e..f5a6e0b 100644 --- a/porder/__init__.py +++ b/porder/__init__.py @@ -2,4 +2,4 @@ __author__ = 'Samapriya Roy' __email__ = 'samapriya.roy@gmail.com' -__version__ = '0.7.2' +__version__ = '0.7.3' diff --git a/porder/porder.py b/porder/porder.py index e2fe821..3b11f45 100644 --- a/porder/porder.py +++ b/porder/porder.py @@ -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 @@ -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() @@ -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'} @@ -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=" " @@ -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) diff --git a/porder/resubmit.py b/porder/resubmit.py new file mode 100644 index 0000000..2080f6f --- /dev/null +++ b/porder/resubmit.py @@ -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') diff --git a/setup.py b/setup.py index b362f6f..5361cbc 100644 --- a/setup.py +++ b/setup.py @@ -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']},