autopytic
Improve your RPA python code with wrapper 🤯
Feautes
- Easy to use on existing scripts
- Send email notifications on exception
- Auto-timmings
- Auto-logging
- Auto-documentation code after every robot end
- Auto-progress with recalculation on-the-fly
- Auto-update robot status on management system using your own REST-API
...
Installation
Use the package manager pip to install foobar.
pip install autopytic
pip install python-dotenv
pip install requests
In your main python script localization create file named .pytic with:
# Settings
# Turn on-off debug mode
DEBUG_MODE=false
# Turn on-off error raise after exception
ERROR_RAISE=false
# Email Settings
# Turn on-off send email after exception with log file
SEND_EXCEPTIONS=false
# SMTP HOST ADRESS
SMTP_HOST=
# SMTP PORT
SMTP_PORT=
# SMTP SENDER EMAIL
SENDER_EMAIL=
# SMTP SENDER EMAIL PASSWORD
SENDER_PASS=
# List of email addresses to which messages are sent :: separated by comma
RECIVER_EMAIL=
# Coverage Settings
# Exclude given paths from code coverage (example ./venv):: separated by comma
EXCLUDE_VENV=
# Status Settings
# Default script execute first time in ms (does not need to be edited)
DEFAULT_EXECUTE_TIME=1000000000
# Address to which the response with the robot's status and progress is to be sent
RESPONSE_URL=
# Response refresh rate in ms
# If the robot is fast, it is recommended to lower the rate to indicate status other than 0-100
STATUS_REFRESH_RATE=0.1
# Active status name for response
STATUS_ACTIVE=Aktywny
# Completed status name for response
STATUS_COMPLETED=Zakonczony
# Error status name for response
STATUS_ERROR=Krytyczny
# Returning together with the status of the place where the robot is located
STATUS_WITH_STATE=false
# This form is helpful for previewing progress in the console :: Turn on-off
STATUS_PRINTER=false
Usage example
import time
from autopytic.tools.wrapper import Wrapper
wrapper = Wrapper()
logfile = 'log.txt'
wrapper.robot_path = './robots/1/'
class Robot:
def __init__(self):
pass
@wrapper.register_event(logfile=logfile, description='Run method', start=True)
def run(self):
for i in range(10):
time.sleep(3)
self.checking_files()
self.extract_data()
@wrapper.register_event(logfile=logfile, description='End method', end=True)
def end_robot(self):
pass
@wrapper.register_event(logfile=logfile, description='Checking files')
def checking_files(self):
pass
@wrapper.register_event(logfile=logfile, description='Extract data from file')
def extract_data(self):
pass
r = Robot()
r.run()
r.end_robot()
Console output
Debug mode console output
Tips
Error handling
ERROR_RAISE=false # Wrapper will not return any exception after a failed action easy to debug step actions
ERROR_RAISE=true # Wrapper will return exception after a failed action
Loop handling
If you want to read the code based on loops easier, use in_loop (default false), to avoid too much spam in the documentation, the display loops are slightly shortened:
@Wrapper.register_event(logfile=logfile, description="Say hello", in_loop=True)
def say_hello():
return 'hello'
Email reports
Auto-logging
FAIL | 2021-03-18 20:01:19.479666 | say_hello | (<__main__.Robot object at 0x105d20460>,) | Say hello | - ms | unsupported operand type(s) for +: 'int' and 'str'
PASS | 2021-03-18 20:01:19.789123 | process_and_response | (<__main__.Robot object at 0x105d20460>, <Response [200]>) | Try to scrap something and return value | 0.0019073486328125ms | -
PASS | 2021-03-18 20:01:19.789445 | get_page | (<__main__.Robot object at 0x105d20460>, 'https://www.google.pl/') | Send requests to get scrapping page | 307.56616592407227ms | -
Auto-documentation
The code is automatically documented after each work completion and put into the docs.txt file
Output
Step 0 -> use function run to do Final Run robot method
Step 1 -> use function fetch_from_site to do Fetch something from site
Step 2 -> use function say_hello to do Say hello
Step 3 -> use function get_page to do Send requests to get scrapping page
Step 4 -> use function end to do Final End robot method
Code coverage
To check code coverage use in main directory
python3 -m autopytic coverage
VisualStudio Code Snippet
In order not to focus on writing it every time, it is worth adding a snippet to your IDE as in this case:
"register_event": {
"prefix": "register",
"body": [
"@Wrapper.register_event(logfile=logfile, description='$1')"
],
"description": "Register event"
}
Metadata
Release files for autopytic 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autopytic-1.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / autopytic-1.0-py3-none-any.whl
| Download URL | autopytic-1.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf2103755669c507d0dfec781dbc466e6251a1536bb33d03e0c3b84583d5f228
|
|
BLAKE2b-256 checksum How to use checksums |
8934c3fab20cdf80db0bb2de91f0a04501f08784fb80b7e6e74398a6df92463e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.2
|