[PYTHON] Display a screen that requires login to digital signage

Thing you want to do

I want to display the screen of an external service that requires login together with the signage that displays the image file as a slide show. It's a little difficult to understand, but it looks like the following.

What to use

Overall flow

  1. Launch Chrome using Selenium
  2. Access external services and log in automatically (with Selenium)
  3. Go to the screen you want to display and capture the image (with Selenium)
  4. Save the image in the folder for public signage (with Selenium)
  5. Periodically execute the above flow using the task scheduler

Source code

It would be helpful if you could read the file name, save destination, login information, etc. as appropriate.

import os
import sys
import time
import datetime
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import chromedriver_binary

# File Name
now = datetime.datetime.now()
filename = "image/screen_" + now.strftime('%Y%m%d_%H%M%S') + ".png "
FILENAME = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)

# set driver and url
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
url = 'https://xxxx/xxxx/'
driver.get(url)

# ID/Enter PASS (Adjustment required for each site)
id = driver.find_element_by_name("xxxx-xxxx")
id.send_keys("xxxx")
password = driver.find_element_by_name("xxxx-xxxx")
password.send_keys("xxxx")
time.sleep(1)

#Click the login button (this requires adjustment for each site)
login_button = driver.find_element_by_name("xxxx")
login_button.click()

# get width and height of the page
w = driver.execute_script("return document.body.scrollWidth;")
h = driver.execute_script("return document.body.scrollHeight;")

# set window size
driver.set_window_size(1920,1080)
time.sleep(1)

# Get Screen Shot
print ("Get Screen Shot")
driver.save_screenshot(FILENAME)

# Close Web Browser
driver.quit()

Summary

For the time being, I was able to do what I wanted to do with the above flow. After that, I'm currently doing it in a local environment, so I want to move this to a server environment. Now that I understand the general flow, I feel that I can manage it by investigating the rest.

A little note

In my environment, I assigned the signage publishing folder to the network drive, but when I started python directly with the task scheduler, the access to the network drive did not work, so I created a batch file separately. So I assigned a network drive in batch and then started python and it worked. So, at present, the mechanism is such that the batch file is executed regularly.

Recommended Posts

Display a screen that requires login to digital signage
Create a Django login screen
Linux screen distribution on Ubuntu Memo that wants to be a Linux screen distribution YouTuber
Creating a login screen with Django allauth
I made a script to display emoji
Creating software that mirrors the Android screen to a PC 2 Real-time touch edition
A story about implementing a login screen with django
[Wagtail] Add a login page to the Wagtail project
Prompt to give a synonym for each login
[pyqtgraph] Created a class to display the crosshairs that follow the cursor and their coordinates