├── requirements.txt ├── Dockerfile ├── cookie.json ├── LICENSE ├── README.md └── post-check.py /requirements.txt: -------------------------------------------------------------------------------- 1 | certifi==2020.4.5.1 2 | chardet==3.0.4 3 | idna==2.9 4 | requests==2.23.0 5 | tabulate==0.8.7 6 | urllib3==1.26.5 7 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python 2 | 3 | WORKDIR /post 4 | COPY requirements.txt /post 5 | RUN pip install -r requirements.txt 6 | COPY . /post 7 | 8 | ENV PKG="RH080789165GB" 9 | CMD ["/bin/bash"] 10 | 11 | # RUN "python3 post-check.py -pn ${pkg}" 12 | 13 | -------------------------------------------------------------------------------- /cookie.json: -------------------------------------------------------------------------------- 1 | { 2 | "request_key": "0_GEbL1pKkfv9XKQJiaYh9lJwxUx8amd1sxWZjoI8Pk0nklD0BbGetPmjDrME754cRlJvu1PS2SHRJpNFuMD9YKLt7J_Zv62--phykoTMAc1", 3 | "verification_key": "NiM5voZvLxVJImb39ZlAixk6YLPleFjAYlEic7M1SOCqJ0WrQnufnXovwlskRJnEPcqqldf43EezGwODhekXthoYiSKPjcdAFqYsrLXR8Qk1" 4 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Yoav Ramon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Prerequisites 2 | - Python 3.6 and above 3 | - install requirements (use: `pip install -r requirements.txt`) 4 | ## Usage 5 | For Basic usage just enter your package number: 6 | ```bash 7 | python ./post-check.py -pn RH080789165GB 8 | ``` 9 | Should output: 10 | ```text 11 | Date Description Postal Unit City 12 | 23/04/2020 Unclaimed and will be returned to the sender Zemenhoff Tel Aviv Yaffo 13 | 29/03/2020 A second notice was left for the addressee Zemenhoff Tel Aviv Yaffo 14 | 23/03/2020 A notice was left for the addressee Zemenhoff Tel Aviv Yaffo 15 | 19/03/2020 Arrived at the postal unit for delivery to addressee (shelf no ג-3170) Zemenhoff Tel Aviv Yaffo 16 | ``` 17 | For extended usage see: 18 | ```text 19 | usage: post-check.py [-h] -pn PACKAGE_NUMBER [-ih] [-pj] [-cf COOKIE_FILE] 20 | 21 | optional arguments: 22 | -h, --help show this help message and exit 23 | -pn PACKAGE_NUMBER, --package-number PACKAGE_NUMBER 24 | Package number 25 | Optionally, the PKG environment variable may be used instead 26 | -ih, --is-heb Print in hebrew 27 | -pj, --print-json Print json instead of table 28 | -cf COOKIE_FILE, --cookie-file COOKIE_FILE 29 | Cookie file 30 | ``` 31 | This code can be automated with cron if you want to check your package status each day. 32 | 33 | **Don't spam the post-il site!** 34 | 35 | ## TODO list 36 | * Check multiple packages in one command 37 | * Save cache of previous status of package and update only if that status changed 38 | -------------------------------------------------------------------------------- /post-check.py: -------------------------------------------------------------------------------- 1 | from tabulate import tabulate 2 | import requests 3 | import argparse 4 | import pprint 5 | import json 6 | import os 7 | 8 | class EnvDefault(argparse.Action): 9 | def __init__(self, envvar, required=True, default=None, **kwargs): 10 | if not default and envvar: 11 | if envvar in os.environ: 12 | default = os.environ[envvar] 13 | if required and default: 14 | required = False 15 | super(EnvDefault, self).__init__(default=default, required=required, 16 | **kwargs) 17 | 18 | def __call__(self, parser, namespace, values, option_string=None): 19 | setattr(namespace, self.dest, values) 20 | 21 | def _parse_args(): 22 | parser = argparse.ArgumentParser() 23 | parser.add_argument('-pn', '--package-number', type=str, required=True, help='Package number, you may use the PKG environment variable as well', 24 | action=EnvDefault, envvar="PKG") 25 | parser.add_argument('-ih', '--is-heb', action='store_true', required=False, help='Print in hebrew') 26 | parser.add_argument('-pj', '--print-json', action='store_true', required=False, help='Print json instead of table') 27 | parser.add_argument('-cf', '--cookie-file', type=str, required=False, default='cookie.json', help='Cookie file') 28 | 29 | return parser.parse_args() 30 | 31 | 32 | def _get_state_list(item_code, request_key, verification_key, is_heb): 33 | url = "https://mypost.israelpost.co.il/umbraco/Surface/ItemTrace/GetItemTrace" 34 | payload = f"itemCode={item_code}{'&lcid=1037' if is_heb else ''}&__RequestVerificationToken={request_key}" 35 | headers = { 36 | 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 37 | 'Cookie': f'__RequestVerificationToken={verification_key};', 38 | } 39 | 40 | response = requests.request("POST", url, headers=headers, data=payload) 41 | return json.loads(response.text) 42 | 43 | 44 | def _check_response(response): 45 | if response['ReturnCode'] != 0: 46 | print(f"Got the following error: {response['ErrorDescription']}") 47 | return False 48 | else: 49 | return True 50 | 51 | 52 | def _print_response(response, print_json): 53 | if print_json: 54 | pprint.pprint(response) 55 | else: 56 | print(tabulate(tabular_data=response['Result']['itemcodeinfo']['InfoLines'], 57 | headers=response['Result']['itemcodeinfo']['ColumnHeaders'], 58 | tablefmt="plain", 59 | stralign='right')) 60 | 61 | 62 | if __name__ == "__main__": 63 | args = _parse_args() 64 | 65 | cookie = json.load(open(args.cookie_file)) 66 | post_response = _get_state_list(args.package_number, cookie['request_key'], cookie['verification_key'], args.is_heb) 67 | if _check_response(post_response): 68 | _print_response(post_response, args.print_json) 69 | else: 70 | print('Failed to get package information') 71 | --------------------------------------------------------------------------------