Skip to content

blooregardq/python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 

Repository files navigation

python

its nothing big from selenium import webdriver from selenium.webdriver.common.by import By import time

Configuration

target_username = "thecheshirechatbot" # Username to monitor (no @) my_username = "johnny_dapple_seed" # Your Threads username (no @) auto_reply = "🀑" # The emoji to reply with

Track replied comment IDs (simple deduplication)

replied_to = set()

Set up the Chrome driver (make sure ChromeDriver is installed and on PATH)

driver = webdriver.Chrome()

Step 1: Go to Threads and wait for manual login

driver.get("https://www.threads.net") input("🟒 Please log in manually, then press Enter here to continue...")

Step 2: Visit your profile

driver.get(f"https://www.threads.net/@{my_username}") time.sleep(5)

print(f"πŸ” Monitoring comments on posts by @{my_username} for comments from @{target_username}...")

Main loop

while True: try: # Find all post links posts = driver.find_elements(By.CSS_SELECTOR, "a[href*='/@'][href*='/post/']") post_urls = list(set([p.get_attribute("href") for p in posts]))

    for post_url in post_urls:
        driver.get(post_url)
        time.sleep(4)

        # Try to expand hidden replies if available
        try:
            expand_buttons = driver.find_elements(By.XPATH, "//button[contains(text(),'View')]")
            for btn in expand_buttons:
                btn.click()
                time.sleep(1)
        except:
            pass

        # Grab all visible comment blocks
        comments = driver.find_elements(By.CSS_SELECTOR, "div[role='article']")

        for comment in comments:
            try:
                user_elem = comment.find_element(By.CSS_SELECTOR, "a[href*='/@']")
                username = user_elem.text.strip('@')

                if username == target_username:
                    # Use innerHTML fragment to hash comment ID
                    comment_id = comment.get_attribute("innerHTML")[:100]

                    if comment_id in replied_to:
                        continue  # already replied

                    # Extract and print comment content
                    comment_text_elem = comment.find_element(By.CSS_SELECTOR, "div[dir='auto']")
                    comment_text = comment_text_elem.text.strip()
                    print(f"πŸ’¬ @{target_username} said: \"{comment_text}\"")

                    # Reply with emoji
                    reply_button = comment.find_element(By.XPATH, ".//button[contains(text(),'Reply')]")
                    reply_button.click()
                    time.sleep(1)

                    reply_box = driver.find_element(By.TAG_NAME, "textarea")
                    reply_box.send_keys(auto_reply)
                    time.sleep(1)

                    post_button = driver.find_element(By.XPATH, "//button[contains(text(),'Post')]")
                    post_button.click()

                    print(f"βœ… Replied to @{target_username} with 🀑")
                    replied_to.add(comment_id)

                    time.sleep(2)

            except Exception as e:
                print(f"⚠️ Skipping one comment due to error: {e}")
                continue

    print("πŸ”„ Sleeping 60 seconds before checking again...\n")
    time.sleep(60)

except KeyboardInterrupt:
    print("πŸ›‘ Script interrupted by user. Exiting.")
    break

except Exception as e:
    print(f"🚨 Error during loop: {e}")
    time.sleep(60)

About

its nothing big

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published