|
#1
|
||||
|
||||
Youtube live chat listening bot written in python (firefly)
Hi so here is a quick script which will listen to live Youtube chat stream.
You can do a number of things with this script. At the moment the script will have all the username and their message to a database. Remember if you wana run this script in headless mode you need to comment out driver = webdriver.Firefox() so it will look like this #driver = webdriver.Firefox() and remove the hash from #driver = webdriver.Firefox(options=options) so it will look like this driver = webdriver.Firefox(options=options). This script runs on Python3 both on Ubuntu 18.04 64bit LTS and Windows 10 64bit Code:
# Module Imports import mariadb import sys import os from datetime import datetime from selenium.webdriver.firefox.options import Options as FirefoxOptions from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.common.exceptions import NoSuchElementException from time import sleep from itertools import count # Connect to MariaDB Platform try: conn = mariadb.connect( user="root", password="", host="localhost", port=3306, database="ytchat" ) except mariadb.Error as e: print(f"Error connecting to MariaDB Platform: {e}") sys.exit(1) # Get Cursor cur = conn.cursor() def ytc(user,mess): cur.execute( "INSERT INTO mess (user,mess,added) VALUES (?, ?, ?)", (user, mess, datetime.now())) conn.commit() string = 'KZWVvBbjOuU' options = FirefoxOptions() options.add_argument("--headless") driver = webdriver.Firefox() #driver = webdriver.Firefox(options=options) driver.get('https://www.youtube.com/live_chat?is_popout=1&v='+ str(string)) driver.maximize_window() sleep(4) messages = driver.find_elements_by_xpath('//*[@id="message"]') last_message_text = messages[0].text while (True): messages = driver.find_elements_by_xpath('//*[@id="message"]') driver.get('https://www.youtube.com/live_chat?is_popout=1&v='+ str(string)) try: number =1 for number in count(1): user = driver.find_elements_by_xpath('//*[@id="author-name"]')[number].text mess = driver.find_elements_by_xpath('//*[@id="message"]')[number].text print(user) print(mess) ytc(user,mess) sleep(5) except NoSuchElementException: sleep(10) number =1 for number in count(1): user = driver.find_elements_by_xpath('//*[@id="author-name"]')[number].text mess = driver.find_elements_by_xpath('//*[@id="message"]')[number].text print(user) print(mess) ytc(user,mess) sleep(5)
__________________
Please Support Majority Report You can contact me on Skype live:phesadent.elect but please let me know first. If you are ever need me desperately then please email me at dan.oak44@gmail.com and I will contact u within a week. Due to free time I'm able to help interested member's with their tracker. Please Note! Depending on your requests I will charge you for my assistance for Tracker installs and mods. All my mods are custom and prices will very depending on the request. I'm able to install any tracker and mods including themes. Please PM me Last edited by firefly007; 11th November 2021 at 16:35. |
|
|