{"id":24360424,"url":"https://github.com/dms-codes/tweet_to_twitter","last_synced_at":"2025-04-15T15:22:06.954Z","repository":{"id":169618413,"uuid":"537672706","full_name":"dms-codes/tweet_to_twitter","owner":"dms-codes","description":"Twitter Automation using Selenium This Python script demonstrates how to automate posting a tweet on Twitter using the Selenium web automation library. It opens a Chrome web browser, logs into a Twitter account, composes a tweet, and posts it.","archived":false,"fork":false,"pushed_at":"2023-10-01T10:15:28.000Z","size":2,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T21:51:08.498Z","etag":null,"topics":["automation","python","selenium","twitter","x"],"latest_commit_sha":null,"homepage":"https://github.com/dms-codes/tweet_to_twitter","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dms-codes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-17T02:04:34.000Z","updated_at":"2024-12-07T18:37:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"352aaaa6-da0d-478f-bdb7-9fd1d61be4fd","html_url":"https://github.com/dms-codes/tweet_to_twitter","commit_stats":null,"previous_names":["dms-codes/tweet_to_twitter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Ftweet_to_twitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Ftweet_to_twitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Ftweet_to_twitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Ftweet_to_twitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dms-codes","download_url":"https://codeload.github.com/dms-codes/tweet_to_twitter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249095155,"owners_count":21211871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","python","selenium","twitter","x"],"created_at":"2025-01-18T21:19:51.177Z","updated_at":"2025-04-15T15:22:06.932Z","avatar_url":"https://github.com/dms-codes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twitter Automation using Selenium\n\nThis Python script demonstrates how to automate posting a tweet on Twitter using the Selenium web automation library. It opens a Chrome web browser, logs into a Twitter account, composes a tweet, and posts it.\n\n## Prerequisites\n\nBefore running the script, make sure you have the following prerequisites installed:\n\n1. [Python](https://www.python.org/downloads/)\n2. [Selenium](https://selenium-python.readthedocs.io/installation.html) library installed. You can install it using `pip`:\n\n   ```bash\n   pip install selenium\n   ```\n\n3. [Google Chrome](https://www.google.com/chrome/) browser installed.\n\n## Usage\n\n1. Import the necessary libraries:\n\n   ```python\n   from selenium import webdriver\n   from selenium.webdriver.chrome.options import Options\n   import time, os\n   ```\n\n2. Configure Chrome options to store cookies and start the browser maximized:\n\n   ```python\n   options = Options()\n   options.add_argument(f\"user-data-dir={os.getcwd()}cookies\")\n   options.add_argument(\"start-maximize\")\n   ```\n\n   - The `user-data-dir` argument is used to specify the directory to store user data, including cookies, to maintain your Twitter login session.\n\n3. Create a Chrome webdriver instance:\n\n   ```python\n   driver = webdriver.Chrome(options=options)\n   ```\n\n4. Navigate to the Twitter website:\n\n   ```python\n   driver.get(\"https://twitter.com\")\n   ```\n\n5. Wait for the Twitter page to load:\n\n   ```python\n   time.sleep(2)\n   ```\n\n6. Locate the tweet input field and send a tweet:\n\n   ```python\n   sendmessage = driver.find_element_by_xpath(\"*//*[@contenteditable='true']\")\n   sendmessage.send_keys(\"test\")\n   ```\n\n7. Find and click the tweet button:\n\n   ```python\n   kliktweet = driver.find_element_by_xpath(\"//div[@data-testid='tweetButtonInline']\")\n   kliktweet.click()\n   ```\n\n8. Wait for a specified time (e.g., 60 seconds) to ensure the tweet is posted:\n\n   ```python\n   time.sleep(60)\n   ```\n\n9. Quit the Chrome driver:\n\n   ```python\n   driver.quit()\n   ```\n\n10. Customize the script to meet your specific automation needs, such as logging in with your Twitter account and posting the desired content.\n\n## Notes\n\n- This script logs into Twitter using an existing account's session data. Make sure to replace `os.getcwd()` with the appropriate directory path if needed.\n- Be cautious while automating actions on websites to comply with their terms of service.\n\n## License\n\nThis script is provided under the [MIT License](LICENSE).\n```\n\nYou can customize the script and README.md file further to suit your specific requirements and ensure you have the correct WebDriver for Chrome installed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdms-codes%2Ftweet_to_twitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdms-codes%2Ftweet_to_twitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdms-codes%2Ftweet_to_twitter/lists"}