I had a script that when I run as my user – it could find all commands. This was in a Fedora environment.
The solution was to wrap it in shell like this
[jon2allen@jons-bad-ass-fedora-server-37 python]$ cat run_news.sh #!/bin/bash source /home/jon2allen/.bashrc python3 /home/jon2allen/python/news1_test.py
sourcing the .bashrc
The command has several subprocess shell. before I sourced .bashrc – yt-dlp could not be found. and fabric. etc.
[jon2allen@jons-bad-ass-fedora-server-37 python]$ cat news1_test.py import subprocess from datetime import datetime class CustomDate: def __init__(self, date=None): if date is None: self.date = datetime.now() elif isinstance(date, datetime): self.date = date else: raise ValueError("Date must be a datetime object or None") def return_date(self): month_abbreviations = { 1: "Jan.", 2: "Feb.", 3: "March", 4: "April", 5: "May", 6: "June", 7: "July", 8: "Aug.", 9: "Sept.", 10: "Oct.", 11: "Nov.", 12: "Dec." } month = month_abbreviations[self.date.month] day = self.date.day year = self.date.year return f"{month} {day}, {year}" def print_date(self): print(self.return_date()) def search_youtube(search_query): command_str = f'yt-dlp ytsearch2:"{search_query}" --get-id --get-title' try: result = subprocess.run(command_str, capture_output=True, shell=True, text=True, check=True) lines = result.stdout.strip().split("\n") if len(lines) != 4: raise ValueError(f"Unexpected output length: expected 4 lines, got {len(lines)}") # Return the 4 lines as a tuple return tuple(lines) except subprocess.CalledProcessError as e: raise RuntimeError(f"yt-dlp command failed with error: {e.stderr}") from e except Exception as e: raise RuntimeError(f"Failed to run yt-dlp command: {e}") from e def fabric_call(youtubid): command_str = f'yt https://www.youtube.com/watch?v={youtubid} | fabric -sp newscast' print (command_str) try: result = subprocess.run(command_str, capture_output=True, shell=True, text=True, check=True) lines = result.stdout return (lines) except subprocess.CalledProcessError as e: raise RuntimeError(f"yt/fabric command failed with error: {e.stderr}") from e except Exception as e: raise RuntimeError(f"Failed to run yt/fabric command: {e}") from e # Example usage if __name__ == "__main__": date1 = CustomDate() search_str = 'PBS News Hour full episode, ' + date1.return_date() print("search: " + search_str) result = search_youtube(search_str) print(result) if result[0].find('live') < 0 : print("result0: ", result[0], result[1]) if result[0].find(date1.return_date()) > -1: print("found date") print(fabric_call(result[1])) if result[2].find('live') < 0 : print("result2: ", result[2], result[3]) if result[2].find(date1.return_date()) > -1: print("found date" ) print(fabric_call(result[3]))
This script pulls down the daily PBS News Hour transcript using yt-dlp. and uses fabric to get an ai summary of the newscast. I have to run it round 8pm Eastern.
The fabric prompt:
# IDENTITY and PURPOSE You are an AI assistant tasked with summarizing newscasts. Your role involves meticulously analyzing newscast content to identify major topics and extract key supporting facts. You will then organize this information into a structured summary, ensuring clarity and accuracy in your representation of the news. You must adhere to specific formatting guidelines to present the summary in a clear and readable manner. You are responsible for not only understanding the content of the newscast but also interpreting the instructions provided to ensure that your output perfectly matches the requested format and includes the appropriate number of supporting facts for each topic. Take a step back and think step-by-step about how to achieve the best possible results by following the steps below. # STEPS - Analyze the provided newscast text. - Identify the major topics discussed. - Extract 3 to 5 supporting facts for each major topic. - Organize the summary by topic, listing supporting facts under each. # OUTPUT INSTRUCTIONS - Only output Markdown. - All sections should be Heading level 1. - Subsections should be one Heading level higher than their parent section. - All bullets should have their own paragraph. - Ensure you follow ALL these instructions when creating your output. # INPUT INPUT: