[Python] Saving passwords for python script and virtual environment in Linux

Discussão em 'Python' iniciado por Stack, Março 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Python script that scrapes a website, stores some data into a Pandas data frame and emails the results as HTML. I'm running this manually, but now I'm trying to automate this. I have a Raspberry Pi that is always on for Open Media Vault.

    This seemed like a good opportunity to learn more about cron jobs and Linux.

    The main concerns I have are how to store my login credentials (which I currently have in a .env file), storing the pickle file that contains cookie data to avoid text message verification, and how to handle package installations (virtual env vs globally on the Linux OS).

    For the passwords, 2 suggestions came up: manually setting them in ~/.bashrc as environment variables which I can bring in using os.getenv(); use chmod 600 to restrict access to .env file.

    For the virtual env, I've never done this in Linux, so I'm kind of clueless and unsure if it would be worth doing? See everything I'm importing:

    import json
    import base64
    import pandas as pd
    import os
    import pickle
    import time
    import re
    import smtplib
    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.common.exceptions import NoSuchElementException, TimeoutException
    from datetime import datetime, timedelta
    from dateutil.relativedelta import relativedelta
    from webdriver_manager.chrome import ChromeDriverManager
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from dotenv import load_dotenv

    Continue reading...

Compartilhe esta Página