Today at 6 am I've found out that I'm procrastinating for about 1 hour. When I realized that I decided to stop and check my Nozbe account with tasks that I could use for blog-topic. You know based on the article name what topic I've found.

You may ask - how you want to use automation in fight with procrastination?

I've found out that using Pomodoro Technique and special for each of us music gives me more focus than I could ever thought. That's why I'm going to make an automation that will start both of this elements at my browser to get more focused right-away.

I'll use one of the Pomodoro Technique timers and Spotify playlist to play music.

Without further ado, check out this selenium automation I will create!

To The Point

Selenium for Spotify web-player.

First you need to have a spotify playlist that you personally like to listen to get more focused. I have some of my preferred playlists, one of them is Blue Stahli- Antisleep vol1.

Let's create an automation which for now will open this link :

from page_objects import PageObject, PageElement
from import By
from import WebDriverWait
from import expected_conditions as EC

class SpotifyPlaylist(PageObject):

    """Spotify Playlist Page for Selenium Page Object Pattern"""
    album_uri = ""
    playlist_uri = ""
    login_uri = ""

    username = PageElement(css='input[id="login-username"]')
    password = PageElement(css='input[id="login-password"]')
    login_btn = PageElement(css='button[id="g-recaptcha-button"]')

    def open_playlist(self, playlist_id):
        self.get(self.playlist_uri + playlist_id)

    def open_album(self, album_id):
        self.get(self.album_uri + album_id)

    def login(self, username, password):
        self.username = username
        self.password = password

Using it with:

    driver = webdriver.Firefox()
    spotify_page = SpotifyPlaylist(driver)
    username = "heregoesyourusername"
    password = "heregoesyourpassword"
    spotify_page.login(username, password)

It will automatically login and go to album.

Taking into accunt that Spotify is not DRM Free, it needs to have Play DRM settings.

We will cover this in tomorrow topic how to do that because solution is not simplest as it seems.

For now lets move to our second page that we need to make less Procrastination.

Pomodoro APP

I have found that using some pomodoro-technique timer makes me a lot more productive. Let's make a script that will automatically start a pomodoro timer - because that's what I'm currently doing manually.

from page_objects import PageObject, PageElement
from import By
from import WebDriverWait
from import expected_conditions as EC

class PomodoroPage(PageObject):

    """Spotify Playlist Page for Selenium Page Object Pattern"""
    main_uri = ""

    timer_start = PageElement(css='button[id="timer_start"]')

    def start_pomodoro(self):

Now we need to mix them together. Unfortunatelly I've found that making a new tab in browser has some strange issues. To overcome it you can use a javascript code.

The script looks like this:

    driver.execute_script('''"", "_blank");''')

The final script is available at Day-to-Day Automation github repo directory


Script for creating new tab at firefox selenium driver:

    driver.execute_script('''"", "_blank");''')



Related links


That's it :) Comment, share or don't :)

If you have any suggestions what I should blog about in the next articles - please give me a hint :)

See you in the next episode! Cheers!


comments powered by Disqus