Most of the RPA platforms were built on the .Net framework taking advantage of its close integration with the Microsoft OS. However, given Python’s growing popularity, it is no surprise that new RPA platforms have also started using Python as the choice of language to build RPA frameworks.
TagUI is the leading open-source RPA software 🤖 with thousands of active users, Another example is “RPA Framework” Now maintained by Robocorp providing RPA Framework as a collection of open-source libraries and tools for Robotic Process Automation (RPA).
Automagica is another fast-growing Python Based Open Source RPA library which provides an open-source (robotic) process automation platform. With Automagica, automating cross-platform processes becomes a breeze.
In the previous post, we have discussed “How Automagica can be configured” and Automagica Flow can be used to build RPA Bot.
In this post , We are taking different approach to build rpa bot using the Automagica package and python to perform the required task.
So this is pure pythonic approach to build robot for your work…
Lets get started !
Prerequisite to Build Python RPA Bot Using Automagica
Under the hood Automagica is Build using the popular python library and its provide full support to python.
for getting started you need –
- Anaconda or Python With PiP (Should be 3.7 or Higher )
- Editor of your choice such as Pycharm/VSCode/Spyder etc. to Write your Python code
Creating Virtual Environment
I will suggest creating Virtual Environment so that it’s separated with other projects library, Lets say Automagica (This is optional and you can use your existing env or system default env in case you don’t wish to create one)
You can read more about – Virtual Environment.
Install the Automagica Python library
For installing the Automagica Python Library, All you need to make sure that you have Python 3.7 Installed. (As of now 3.7 is Supported) and then Automagica can be install using pip as below-
pip install automagica --upgrade
You can also pull the automgaica git repository and install an editable version of the package using below-
pip install virtualenv git clone https://github.com/automagica/automagica cd automagica virtualenv create automagica activate automagica pip install -e .
Or Simply using the Command prompt from PyCharm IDE.
Quick Note- When you install following dependencies will also be installed .
Installing collected packages: mimesis, Pillow, click, pycparser, cffi, six, cryptography, mss, pyasn1, pycryptodomex, ply, pysmi, pysnmp, numpy, pytz, python-dateutil, pandas, pyglet, babel, idna, pyOpenSSL, urllib3, selenium, pywin32-ctypes, zipp, importlib-metadata, keyring, pyzmq, Send2Trash, pyrsistent, attrs, jsonschema, ipython-genutils, traitlets, pywin32, jupyter-core, nbformat, tornado, pywinpty, terminado, prometheus-client, jupyter-client, entrypoints, webencodings, pyparsing, packaging, bleach, pandocfilters, pygments, async-generator, nest-asyncio, nbclient, mistune, defusedxml, MarkupSafe, jinja2, jupyterlab-pygments, testpath, nbconvert, argon2-cffi, decorator, parso, jedi, pickleshare, colorama, backcall, wcwidth, prompt-toolkit, ipython, ipykernel, notebook, psutil, jdcal, et-xmlfile, openpyxl, lxml, python-docx, keyboard, future, pyad, mouse, PyPDF2, automagica
Various Supported Activities in Automagica Python Package
- Cryptography – Useful for creating Encrypted Text, Files, Generating Key Based password etc.
- Random – Useful for creating all type of Random Data
- Output – Interacting with Console to print a message
- Browser – Automated Chrome Session to find elements using XPath or other properties.
- Credential Management -Stores credentials locally and securely
- FTP – Used to automate activities for File Transfer
- Keyboard – Simulate keystrokes and Keyboard based actions.
- Mouse – Displays mouse position and perform various activities using element ID (vision)
- Image – Screen Capture
- Folder Operations – File and Folder based activities.
- Delay – For introducing delays
- Word Application – Works with MS Doc. Microsoft Office Word needs to be installed on the system.
- Word File – Works with MS Doc. Microsoft Office Word needs not to be installed on the system.
- Outlook Application – Outlook application operations
- Excel Application – Works with MS Excel Operations. Microsoft ExcelWord needs to be installed on the system.
- Excel File – Works with MS Excel Operations. Microsoft ExcelWord needs not to be installed on the system
- PowerPoint Application – For PowerPoint activity to work, PowerPoint needs to be installed on the system.
- Office 365 – Send email Office Outlook 365
- Salesforce – Activity to make calls to Salesforce REST API.
- E-mail (SMTP) – Email Using SMTP
- Windows OS – Various activities for Windows Operating System.
- Terminal – Runs a command over SSH (Secure Shell)
- SNMP – Retrieves data from an SNMP agent
- Active Directory – Interface to Windows Active Directory
- Utilities – Various activities for the user-based profile.
- System – Low-Level Activities to manage File Operation
- PDF – Extracts the text from a PDF, Merge PDF
- System Monitoring – Runtime Resources information such as CPU
- Image Processing – Various option to perform image activities such as rotate, crop etc.
- Process – Process Management
- Optical Character Recognition (OCR) – Reading Text Using OCR
- Alternative Frameworks – To invoke other Frameworks Execution like UiPath, AutoIt, Robot Framework, Blue Prism, Automation Anywhere
- General – Exception Handling
- SAP GUI – Interaction with SAP Systems
- Portal – Interaction with Automagica Portal
- Vision – This activity can be used to check if a certain element is visible on the screen.Note that this uses Automagica Portal and uses some advanced fuzzy matching algorithms for finding identical elements.
Under the hood, Automagica is built on some of the greatest open-source libraries provided by the other community developers such as requests, selenium etc…
Build your First Python RPA Bot Using Automagica
We are going to create a WebScarpper Bot, Which reads the outlook to get the email attachment for Input Search Term, Search it on Wikipedia and Send Scrapped Data on Pre-Configured email.
In this example following operations will be performed–
- Read Email from Outlook Using Outlook Activities & Save Input Attachment Excel
- Read Input File Using Excel Activities
- Loop Over the Content of Files to get Search Terms
- Open Wikipedia and Search for Given “Search term in Loop”
- Web Scrape Wikipedia Page and Send Result as Email to Configured Email
- Finally, Close all the open application
If you wish to use Automagica Flow to build automation using Visual IDE , Check details here.
from automagica import * SAVE_FOLDER = "Data" WIKI_URL = 'https://www.wikipedia.org' RESULT_MAIL = "firstname.lastname@example.org" # Open Outlook to Read Emails outlook = Outlook() emails = outlook.get_mails(folder_name="Inbox", fields=None) Files = outlook.save_attachments(output_path=desktop_path()) # Excel Files excel = Excel(file_path=desktop_path()+'\Input.xlsx') data = excel.read_worksheet(headers=True) excel.quit() for row in data: browser = Chrome() browser.get(url=WIKI_URL) print("Going to Search for :- " + row['TEXT']) # Find the search bar using the Xpath search_bar = browser.find_element_by_xpath('//*[@id="searchInput"]') #search_bar = browser.find_xpath('//*[@id="searchInput"]') search_bar.send_keys(row['TEXT']) # Submit the query search_bar.submit() wait(seconds=2) # Find the element that holds the text text_element = browser.find_element_by_xpath('//*[@id="mw-content-text"]') # Extract the text from the element wiki_text = text_element.text # Send Email outlook.send_mail(to_address=RESULT_MAIL,subject="Wiki Extracted Text", body=wiki_text) # Quit the browser browser.quit() # Close Outlook outlook.quit()
Congratulation! You have created your first robot using the automagica Python Library, But it’s not done unless we deploy it on Automagica portal for running in unattended mode or scheduled run.
You can lean more about publishing your Bot Automagica Portal Dashboard to schedule or create Jobs on Automagica Portal to run as per your need.
Follow Details here – Deploy Robot on Automagica Portal
Automagica and Docker
As Automagica is fully cross-platform and built with Python, it’s actually quite straightforward to build and run Automagica bots from within containerized environments.
git clone https://automagi.ca/github cd automagica docker build . -t automagica docker run -it -p 8080:8080 automagica
Then browse to http://localhost:8080/vnc.html to access the Automagica desktop.
To get started building your automation, you can run in the command line. Check out command-line documentation for all the