MoneyForward Cloud Automates time stamping [Let's let Python do the trouble]

Disclaimer

We are not responsible for any damage caused by the contents of this article. This article was written as a personal hobby and has nothing to do with the company I belong to. In addition, we do not recommend breaking corporate rules.

MoneyForward Cloud Attendance Terms of Service

I checked the Terms of Service, but could not find any mention that prohibits automatic operation from the computer. (If anyone notices that you're overlooking, please let me know. I'll stop right away.)

(6) Acts that place an excessive load on this service, the content sites accessed through this service, and the networks or systems of information providers.

(13) Acts that may interfere with the operation of this service by our company

We have decided that there is no problem because it does not include the process of excessive access.

(16) Other acts that the Company deems inappropriate

Please, Money Forward, don't judge it inappropriate

How I decided to automate

Attendance stamps are made at the same time every morning, and departure stamps are made at the same time. This is a completely while statement. It's not something that people do. So I will automate it. (We are waiting for the Tsukkomi that the meaning of stamping is not good)

Code used

The code is available on Github. Not all the code is included in the article, so if you want to know more, please see the code directly. I think there is a more elegant way, so feel free to throw an Issue or PR. Please. https://github.com/Haruka0522/AutoMFKintai

Overall composition

Access embossed web pages from Python using Selenium ↓ Holiday / weekday judgment using datetime and jpholiday ↓ Click the button when the preset work / leave time is reached

It's simple!

Break through the login screen

Source code (excerpt)

id_box = self.driver.find_element_by_name("employee_session_form[office_account_name]")
id_box.send_keys(self.company_id)

mail_box = self.driver.find_element_by_name("employee_session_form[account_name_or_email]")
mail_box.send_keys(self.mail)

password_box = self.driver.find_element_by_name("employee_session_form[password]")
password_box.send_keys(self.password)

login_button = self.driver.find_element_by_name("commit")
login_button.click()

After accessing the login screen, specify the input box by the name of the element and enter the login information there. The name of this element can be found in developer mode by accessing it in chrome and pressing F12. It was a breakthrough of the login screen that was expected to be difficult, but it was possible to break through easily.

Caution

If you hard-code the password etc. on the source code and upload it to Github by mistake, it will be difficult, so let's take a method such as writing the password etc. in a text file called pass.txt and reading it. If you remove pass.txt from git management with .gitignore, you don't have to worry about accidentally pushing.

Click the stamp button

Source code (excerpt)

actions = ActionChains(self.driver)
actions.move_by_offset(480, 250)
actions.click()
actions.perform()

This is where I struggled soberly. Attempting to click by specifying the element of the stamp button did not work, and since onclick () was written, I tried to execute Javascript directly, but for some reason it did not work. Therefore, although it is not a very good method, I took the method of specifying the coordinates of the screen and clicking. Since the window size of Chrome is fixed in the initial setting, I think that it will work even if the environment changes, but honestly it is not elegant, so I would like to improve it in the future.

Saturdays, Sundays, and holidays, weekday judgment

I don't want to accidentally stamp on Saturdays and Sundays. In my case, I basically work on weekdays, so I set it to stamp only on weekdays.

Source code

def is_holiday(date):
    return date.weekday() >= 5 or jpholiday.is_holiday(date)

I used the datetime library and the jppoliday library to determine weekdays. I used datetime to make simple Saturdays and Sundays, and jppoliday to make holidays.

Reference article

https://qiita.com/hid_tanabe/items/3c5e6e85c6c65f7b38be

Main loop

while True:
    dt_now = datetime.datetime.now()
    if is_holiday(datetime.date.today()):  #Weekday judgment
        continue
    if dt_now.hour == start_time.hour and dt_now.minute == start_time.minute:
        operator.syukkin()
    elif dt_now.hour == end_time.hour and dt_now.minute == end_time.minute:
        operator.taikin()
    else:
        time.sleep(wait_time)

Finally

By running this on a computer that runs for 24 hours (Raspberry Pi seems to be good with power saving), it will be automatically stamped. I would like to be able to handle unique holidays in cooperation with Google Calendar etc., and I would like to have a system that does not require writing such a script in the first place. I have a feeling that I might get angry from all sides, but is that okay ...?

Recommended Posts

MoneyForward Cloud Automates time stamping [Let's let Python do the trouble]
(◎◎) {Let's let Python do the boring things) ......... (Hey? Let's let Python do the homework} (゜) (゜)
[2020 version] Let Python do all the tax and take-home calculations
"Let Python do the boring things" exercise ~ Command line mailer ~
Understanding the python class Struggle (1) Let's move it for the time being
Let's touch Google's Vision API from Python for the time being
Try using FireBase Cloud Firestore in Python for the time being
See python for the first time