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 selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class SpotifyPlaylist(PageObject):
"""Spotify Playlist Page for Selenium Page Object Pattern"""
album_uri = "https://open.spotify.com/album/"
playlist_uri = "https://open.spotify.com/playlist/"
login_uri = "https://spotify.com/login/"
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.get(self.login_uri)
self.username = username
self.password = password
self.login_btn.click()
Using it with:
driver = webdriver.Firefox()
spotify_page = SpotifyPlaylist(driver)
username = "heregoesyourusername"
password = "heregoesyourpassword"
spotify_page.login(username, password)
spotify_page.open_album('56QpDqnTzXqMn3Jjxv73lz')
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 selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class PomodoroPage(PageObject):
"""Spotify Playlist Page for Selenium Page Object Pattern"""
main_uri = "https://tomato-timer.com/"
timer_start = PageElement(css='button[id="timer_start"]')
def start_pomodoro(self):
self.get(self.main_uri)
self.timer_start.click()
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('''window.open("https://google.com/", "_blank");''')
The final script is available at Day-to-Day Automation github repo directory
Snippets
Script for creating new tab at firefox selenium driver:
driver.execute_script('''window.open("https://google.com/", "_blank");''')
Acknowledgements
Auto-promotion
Related links
- Python Selenium Open new tab/focus tab/close tab
- Enabled 'Play DRM' using selenium in Python
- Selenium Waits
- Firefox Profile manager
Thanks!
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
comments powered by Disqus