0% found this document useful (0 votes)
3 views5 pages

Python Scripts RPA

The document explains three Python scripts: a Keypress Macro Converter that transforms input strings into macro-based keypress formats for RPA tools, a Business Days Calculator that counts the number of business days between two dates, and a Hexadecimal Addition script that converts hexadecimal strings to integers and performs arithmetic. Each script includes a detailed line-by-line explanation of its purpose, code, and use cases. These scripts are useful for automating tasks in RPA environments, payroll systems, and low-level programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Python Scripts RPA

The document explains three Python scripts: a Keypress Macro Converter that transforms input strings into macro-based keypress formats for RPA tools, a Business Days Calculator that counts the number of business days between two dates, and a Hexadecimal Addition script that converts hexadecimal strings to integers and performs arithmetic. Each script includes a detailed line-by-line explanation of its purpose, code, and use cases. These scripts are useful for automating tasks in RPA environments, payroll systems, and low-level programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Script Explanation Document: Keypress Macro Converter, Business Days Calculator &

Hexadecimal Addition

Script 1: Keypress Macro Converter

Script Purpose

This Python script transforms a given input string ( str1 ) into a macro-based keypress format that is
commonly used in RPA (Robotic Process Automation) tools such as Automation Anywhere. The output string
( str2 ) contains special syntax to simulate keypresses, especially for uppercase letters and special
characters that require a SHIFT key.

Script Code and Line-by-Line Explanation

str1 = 'Sap@123$'

• Defines the original input string containing uppercase letters, numbers, and special characters.

special_char_map = {
'!': '{SHIFT DOWN}1{SHIFT UP}',
'@': '{SHIFT DOWN}2{SHIFT UP}',
'#': '{SHIFT DOWN}3{SHIFT UP}',
'$': '{SHIFT DOWN}4{SHIFT UP}',
'%': '{SHIFT DOWN}5{SHIFT UP}',
'^': '{SHIFT DOWN}6{SHIFT UP}',
'&': '{SHIFT DOWN}7{SHIFT UP}',
'*': '{SHIFT DOWN}8{SHIFT UP}',
'(': '{SHIFT DOWN}9{SHIFT UP}',
')': '{SHIFT DOWN}0{SHIFT UP}'
}

• Creates a dictionary that maps each special character to its respective macro representation.
• These macros simulate holding the SHIFT key and pressing the associated number key.

str2 = ''

• Initializes an empty string that will store the transformed output.

for i in str1:

• Begins a loop to iterate over each character in the original string.

1
if i in special_char_map:
str2 = str2 + special_char_map[i]

• If the character is a special symbol, append its corresponding macro from the dictionary to str2 .

elif [Link]():
i = [Link]()
str2 = str2 + '{SHIFT DOWN}' + i + '{SHIFT UP}'

• If the character is an uppercase letter:


• Convert it to lowercase (for keypress simulation).
• Wrap it with {SHIFT DOWN} and {SHIFT UP} to simulate typing with the SHIFT key.

else:
str2 = str2 + i

• If the character is a lowercase letter or digit, append it as-is to the output.

print(str2)

• Prints the final converted macro string.

Example Input and Output

Input: 'Sap@123$'

Output:

{SHIFT DOWN}s{SHIFT UP}ap{SHIFT DOWN}2{SHIFT UP}123{SHIFT DOWN}4{SHIFT UP}

Use Case

This script is particularly useful when automating typing operations in RPA environments, where special
characters and capital letters must be handled with SHIFT key macros to accurately simulate human input.

Script 2: Business Days Calculator

Script Purpose

This script calculates the number of business days (Monday to Friday) between two given dates, entered as
strings in the format YYYY-MM-DD . Weekends (Saturday and Sunday) are excluded.

2
Script Code and Line-by-Line Explanation

from datetime import datetime, timedelta

• Imports datetime and timedelta classes from the datetime module to work with dates and
perform date arithmetic.

def business_days_between(start_date_str, end_date_str):

• Defines a function that takes two date strings as input arguments.

start_date = [Link](start_date_str, "%Y-%m-%d")


end_date = [Link](end_date_str, "%Y-%m-%d")

• Converts the input strings to datetime objects using the strptime function and the YYYY-MM-
DD format.

if start_date > end_date:


start_date, end_date = end_date, start_date

• Ensures start_date is always before or equal to end_date by swapping if necessary.

business_days = 0
current_date = start_date

• Initializes a counter to keep track of business days and sets current_date to start iterating from
start_date .

while current_date <= end_date:

• Starts a loop from the start date to the end date (inclusive).

if current_date.weekday() < 5:
business_days += 1

• Checks if the current day is a weekday (0–4 = Monday to Friday). If so, increments the business day
counter.

current_date = current_date + timedelta(days=1)

• Advances the current date by one day.

3
return business_days

• Returns the total count of business days between the two dates.

start = input("Enter start date (YYYY-MM-DD): ")


end = input("Enter end date (YYYY-MM-DD): ")

• Accepts user input for the start and end dates.

days = business_days_between(start, end)


print(days)

• Calls the function and prints the number of business days between the entered dates.

Example

Input:

Enter start date (YYYY-MM-DD): 2024-06-01


Enter end date (YYYY-MM-DD): 2024-06-10

Output:

Use Case

Useful in payroll systems, attendance tracking, and deadline calculators where only working days need to
be considered.

Script 3: Hexadecimal Addition

Script Purpose

This script demonstrates how to convert a hexadecimal string to an integer, perform arithmetic on it, and
convert the result back to a hexadecimal.

4
Script Code and Line-by-Line Explanation

hex1 = '0x1A'

• Defines a hexadecimal number as a string.


• This represents the hexadecimal value of an HTML innerText — commonly captured from screen
scraping or data reading in RPA environments. '0x1A' represents 26 in decimal.

int1 = int(hex1, 16)

• Converts the hexadecimal string to an integer ( 26 ) using base 16.

int2 = int1 + 15

• Adds 15 to the integer value. 26 + 15 = 41 .

hex2 = hex(int2)

• Converts the resulting integer ( 41 ) back to a hexadecimal string.


• hex2 can represent the hexadecimal value of an actual blank text box, often used for validation
or field comparison in RPA. Result is '0x29' .

print(hex2)

• Prints the resulting hexadecimal string: 0x29

print(int(hex2, 16))

• Converts hex2 back to an integer ( 41 ) and prints it to confirm the conversion is accurate.

Example Output

0x29
41

Use Case

Useful in low-level programming, memory address calculations, color code manipulations, and any system
that requires switching between decimal and hexadecimal representations.

You might also like