Skip to main content

A autopytic package

Project description

autopytic

Improve your RPA python code with wrapper 🤯

Feautes

- Easy to use on existing scripts
- Auto-emails notifications at exception
- Auto-handling statuses on base worflow
- Auto-generate code timmings and save into file
- Auto-generate logs writer base on used functions workflow
- 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
- Auto-uploading logs into server using your own REST-API
- Auto-fetch config json from server using your own REST-API
- Simple VSC snippets to be fastest RPA Developers in the entire word...
...

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
# Disalbled status name for response
STATUS_DISABLED=Wyłączony
# 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

# Logs Settings

# Address to upload logs into server
UPLOAD_LOGS_URL=

# Config Settings

# Addres to fetch json config from server
GET_CONFIG_URL=

Usage example

from autopytic.tools.wrapper import Wrapper
from random import randint
import time

Robot = Wrapper(robot_path='',log_file='logs.txt')


class _Robot:
    @Robot.register_event(description='Initialized robot')
    def __init__(self):
        pass

    @Robot.register_event(description='Run robot method', start=True)
    def run(self):
        Robot.info(Robot.config['type'])
        time.sleep(3)
        self.check_file()
        time.sleep(3)


    @Robot.register_event(description='Checking file')
    def check_file(self):
        pass

    @Robot.register_event(description='End method', end=True)
    def end(self):
        pass


r = _Robot()

try:
    r.run()
    r.end()
except KeyboardInterrupt:
    # Disabled by Manual
    r.end()
except Exception as e:
    # Disabled by Exception
    r.end()
    raise Exception(e)

Console output

alt text

Debug mode console output

alt text

Tips

Error handling

ERROR_RAISE=false # Wrapper will not return any exception after a failed action easy to debug step actions

alt text

ERROR_RAISE=true # Wrapper will return exception after a failed action

alt text

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:

@Robot.register_event(description="Say hello", in_loop=True)
def say_hello():
        return 'hello'

alt text

Email reports

alt text

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

alt text

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:

	"init_robot": {
		"prefix": "init",
		"body": [
			"from autopytic.tools.wrapper import Wrapper",
			"",
			"Robot = Wrapper(robot_path='${1:robot_path}',log_file='logs.txt')",
			"",
			"",
			"class Robot:",
			"    @Robot.register_event(description='Initialized robot')",
			"    def __init__(self):",
			"        pass",
			"",
			"    @Robot.register_event(description='Run robot method', start=True)",
			"    def run(self):",
			"        pass",
			"",
			"    @Robot.register_event(description='End method', end=True)",
			"    def end(self):",
			"        pass",
			"",
			"",
			"r = Robot()",
			"",
			"try:",
			"    r.run()",
			"    r.end()",
			"except (KeyboardInterrupt, Exception) as e:",
			"    r.end()"
		],
		"description": "Initialize new robot"
	},
	"register_event": {
		"prefix": "register",
		"body": [
			"@Robot.register_event(${1:description})"
		],
		"description": "Register new robot event"
	},
	"function_with_register": {
		"prefix": "_def",
		"body": [
			"@Robot.register_event(description='${1:description}')",
			"def ${2:method_name}(self):",
			"   pass",
			""
		],
		"description": "New method with registered event"
	}

alt text

alt text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

autopytic-1.4.3-py3-none-any.whl (10.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page