-
Notifications
You must be signed in to change notification settings - Fork 61
Script that feeds the gurubase.io RAG AI tool with youtube videos #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,7 @@ dev = [ | |
|
|
||
| scripts = [ | ||
| "bs4", | ||
| "selenium", | ||
| ] | ||
|
|
||
| [project.scripts] | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,123 @@ | ||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/python3 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||
| Outputs URLs of ArduPilot YouTube videos from the ArduPilot YouTube channel. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| SPDX-FileCopyrightText: 2024-2025 Amilcar do Carmo Lucas <amilcar.lucas@iav.de> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| SPDX-License-Identifier: GPL-3.0-or-later | ||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||||||||||||
| import time | ||||||||||||||||||||||||||||||||||||||||||
| from os import environ as os_environ | ||||||||||||||||||||||||||||||||||||||||||
| from typing import Union | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| from requests.auth import HTTPProxyAuth | ||||||||||||||||||||||||||||||||||||||||||
| from selenium import webdriver | ||||||||||||||||||||||||||||||||||||||||||
| from selenium.webdriver.common.by import By | ||||||||||||||||||||||||||||||||||||||||||
| from selenium.webdriver.firefox.options import Options | ||||||||||||||||||||||||||||||||||||||||||
| from selenium.webdriver.support import expected_conditions as ec | ||||||||||||||||||||||||||||||||||||||||||
| from selenium.webdriver.support.ui import WebDriverWait | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Define the URL of the YouTube channel | ||||||||||||||||||||||||||||||||||||||||||
| URL = "https://www.youtube.com/@ardupilot19/videos" | ||||||||||||||||||||||||||||||||||||||||||
| USERNAME = "your_username" # Replace with actual username if needed | ||||||||||||||||||||||||||||||||||||||||||
| PASSWORD = "" # Replace with actual password if needed | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # pylint: disable=duplicate-code | ||||||||||||||||||||||||||||||||||||||||||
| def get_env_proxies() -> Union[dict[str, str], None]: | ||||||||||||||||||||||||||||||||||||||||||
| proxies_env = { | ||||||||||||||||||||||||||||||||||||||||||
| "http": os_environ.get("HTTP_PROXY") or os_environ.get("http_proxy"), | ||||||||||||||||||||||||||||||||||||||||||
| "https": os_environ.get("HTTPS_PROXY") or os_environ.get("https_proxy"), | ||||||||||||||||||||||||||||||||||||||||||
| "no_proxy": os_environ.get("NO_PROXY") or os_environ.get("no_proxy"), | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| # Remove None values | ||||||||||||||||||||||||||||||||||||||||||
| proxies_dict: dict[str, str] = {k: v for k, v in proxies_env.items() if v is not None} | ||||||||||||||||||||||||||||||||||||||||||
| # define as None if no proxies are defined in the OS environment variables | ||||||||||||||||||||||||||||||||||||||||||
| proxies = proxies_dict if proxies_dict else None | ||||||||||||||||||||||||||||||||||||||||||
| if proxies: | ||||||||||||||||||||||||||||||||||||||||||
| logging.info("Proxies: %s", proxies) | ||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||
| logging.debug("Proxies: %s", proxies) | ||||||||||||||||||||||||||||||||||||||||||
| return proxies | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # pylint: enable=duplicate-code | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def main() -> None: | ||||||||||||||||||||||||||||||||||||||||||
| logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| proxies = get_env_proxies() | ||||||||||||||||||||||||||||||||||||||||||
| if proxies: | ||||||||||||||||||||||||||||||||||||||||||
| HTTPProxyAuth(USERNAME, PASSWORD) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Setup Firefox in headless mode | ||||||||||||||||||||||||||||||||||||||||||
| options = Options() | ||||||||||||||||||||||||||||||||||||||||||
| options.add_argument("--headless") | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+59
|
||||||||||||||||||||||||||||||||||||||||||
| if proxies: | |
| HTTPProxyAuth(USERNAME, PASSWORD) | |
| # Setup Firefox in headless mode | |
| options = Options() | |
| options.add_argument("--headless") | |
| auth = None | |
| if proxies: | |
| auth = HTTPProxyAuth(USERNAME, PASSWORD) | |
| from selenium.webdriver.common.proxy import Proxy, ProxyType | |
| proxy = Proxy() | |
| proxy.http_proxy = proxies.get("http") | |
| proxy.ssl_proxy = proxies.get("https") | |
| proxy.proxy_type = ProxyType.MANUAL | |
| # Setup Firefox in headless mode | |
| options = Options() | |
| options.add_argument("--headless") | |
| if proxies: | |
| options.proxy = proxy |
Copilot
AI
Apr 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition restricts video_links to 80, but the comment indicates a limit of 100. Please update the condition or comment to align the intended logic.
| if len(video_links) >= 80: # gurubase has a limit of 100 videos | |
| break | |
| if len(video_links) >= 80: # gurubase has a limit of 100 videos | |
| if len(video_links) >= 100: # gurubase has a limit of 100 videos | |
| break | |
| if len(video_links) >= 100: # gurubase has a limit of 100 videos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instantiation of HTTPProxyAuth is not assigned to any variable nor passed to the WebDriver. Ensure that proxy authentication is properly configured for the driver if required.