Source code for social.twitter

# -*- coding: utf-8 -*-
"""
=====================================================================================
social.twitter module contains classes and methods specific to Twitter social network
=====================================================================================

   .. warning:: Coding style is CamelCase for classes and lowercase_separated_by_underscores A.K.A snake_case for
      methods and variables.
"""
from time import sleep


[docs]class Twitter: """ **Specificity of Twitter** at the moment, the classes specifies the login and post method Twitter. Contain also constant of the social network. """ name = "Twitter" url = "https://twitter.com/" home = "global-new-tweet-button"
[docs] @staticmethod def login_submit(driver, login, password): """ Log in Twitter :param driver: Selenium driver of the bot :param login: Login to use for this bot :param password: Password to use for this bot """ sleep(1) email_input = driver.find_element_by_class_name("email-input") email_input.send_keys(login) sleep(0.25) password_input = driver.find_element_by_name("session[password]") sleep(0.1) password_input.send_keys(password) submit_button = driver.find_element_by_css_selector('input.submit') submit_button.click()
[docs] @staticmethod def post(driver, message): """ Method that defines the actions to post a message on Twitter :param driver: Selenium driver of the bot :param message: Message to post on Twitter """ post_input = driver.find_element_by_id("tweet-box-home-timeline") post_input.click() post_input.send_keys(message) sleep(0.25) submit_button = driver.find_element_by_css_selector('button.tweet-action') submit_button.click()