Welcome to Social project documentation!

Indices and tables

About Social

social

Data harvesting, traffic creation, content diffusion and click automation. Hopefully could help you automatize marketing task. First developments are on Facebook, LinkedIn and Twitter. Rely on selenium and eventually Gecko driver. Bots are instantiation of Thread(inheritance) with specific methods and attributes. Therefore many bots can be launched in parallel.

Warning

For some reasons, social networks are full of tricky popups advertising for their last features. Those ones are unpredictable web object and therefore hard to manage. One solution might be to start the bots first without the headless option to check the presence of popups.

Platforms

The package itself can used theoretically on any platforms running Mozilla, eventually with the corresponding gecko driver and of course Python 3. This repository was only tested on OSX.

Features

Implement the features listed below:
  • Instantiation of bots as threads, therefore multiple bots can start working in parallel.
  • Integration in pytest test framework.
  • integration in Sphinx doc autodocumentation framework.
  • Rocket.Chat sniffing
  • LinkedIn posting
  • Twitter posting
  • Facebook posting
  • Deletion of Rocket.Chat+ emojis in messages for more interoperability
  • Configuration to the extreme with a JSON file
  • SonarQube code review
  • Abseil python app for production to build with bazel
  • Sniffer and Trafficker instances are LinkedIn by their origin

Configuration

Configuration is stored in configuration.json that has to be in the current working directory. The desired structure is the following:

{
  "Trafficker": {
    "Facebook": {
      "login": "TOTO",
      "password": "XXXXXXXXX",
      "page": "https://www.facebook.com/Wexample/"
    },
    "Twitter": {
      "login": "TOTO",
      "password": "XXXXXXXXX",
      "page": null
    },
    "LinkedIn": {
      "login": "TOTO",
      "password": "XXXXXXXXX",
      "page": "https://www.linkedin.com/company/11076082/admin/updates/"
    }
  },
  "Sniffer": {
    "Rocket.Chat+": {
      "login": "TOTO",
      "password": "XXXXXXXXX",
      "URL": "https://chat.wexample.com",
      "channel": "GENERAL"
    }
  },
  "database": {
    "folder": "../sqlite3",
    "filename": "traffic.sqlite3"
  },
  "logging": {
    "format": "%(asctime)s -- %(name)s -- %(levelname)s -- %(message)s"
  },
  "Firefox": {
    "geckoDriverBinary": "geckodriver",
    "firefoxBinary": "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
  }
}

bot module

social.bot module containing classes and methods common to all types of bots

This Bot inherit from Thread, therefore, they can all run in parallel. They communicate via the SQLite 3 database

Warning

Coding style is CamelCase for classes and lowercase_separated_by_underscores A.K.A snake_case for methods and variables.

class social.bot.Bot(login, password)[source]

Common class of all the bot in the trafficker module, inherit from Thread

Constructor of the Bot class
param login:Login to use for this Bot
param password:Password to use for this Bot
raise TypeError:
 If the database_directory or database has the wrong type
log(log_string)[source]
Common logging method to all bots
param log_string:
 Log this string passed in parameter
exception social.bot.BotException[source]

Specific exception raised by the Bot class

sniffer module

social.sniffer module containing Sniffer classes and methods

The Sniffer retrieves hashtaged posts from the desired Rocket.Chat channel.
In between is a sqlite3 base with all messages and required metadata

Warning

Coding style is CamelCase for classes and lowercase_separated_by_underscores A.K.A snake_case for methods and variables.

class social.sniffer.Sniffer(rc_user, rc_password)[source]

The Sniffer, listen to Rocket.Chat, search the #public in messages to load them in sqlite3 base

Constructor of the Sniffer class
param rc_user:User of the account that sniff on Rocket.Chat
param rc_password:
 Password of the user account that sniff on Rocket.Chat
raise SnifferException:
 If general channel not found
insert_message(_id, origin, message, first_except=False)[source]
Function inserting in the social database, table message, with or without sqlite3.IntegrityError for UNIQUE

CONSTRAINT depending on first_except

param _id:Id of the message coming from Rocket.Chat
param origin:username of the robot account
param message:The message itself
param first_except:
 Kwarg, default is False, True for first iteration only
run()[source]

Starting the internal methods of the Sniffer Thread

exception social.sniffer.SnifferException[source]

Specific exception raised by the Sniffer class

trafficker module

social.trafficker module containing Trafficker classes and methods

This Trafficker contains the required classes and methods for spreading content posts
over multiple networks such as Facebook, LinkedIn and Twitter.

Warning

Coding style is CamelCase for classes and lowercase_separated_by_underscores A.K.A snake_case for methods and variables.

class social.trafficker.Trafficker(social_network, login, password, origin, url=None, headless=True)[source]

Class of the Trafficker social automaton to spread a post on social networks

Constructor of the Trafficker class
param social_network:
 Class being the social network specificity
param login:Login to use for this Trafficker
param password:Password to use for this Trafficker
param origin:Origin of the message to post
param url:URL to post on, kwarg default is None
raise TypeError:
 Raised if the first argument social_network is not an object type
run()[source]

Start posting messages in the social network

wait_home_icon()[source]

Wait until home icon appears

exception social.trafficker.TraffickerException[source]

Specific exception raised by the Trafficker class

facebook module

social.facebook module contains classes and methods specific to Facebook social network

Warning

Coding style is CamelCase for classes and lowercase_separated_by_underscores A.K.A snake_case for methods and variables.

class social.facebook.Facebook[source]
Specificity of Facebook at the moment, the classes specifies the login and post method Facebook. Contain also
constant of the social network.
static login_submit(driver, login, password)[source]
Log in Facebook
param driver:Selenium driver of the bot
param login:Login to use for this bot
param password:Password to use for this bot
static post(driver, message)[source]
Method that defines the actions to post a message on Facebook
param driver:Selenium driver of the bot
param message:Message to post on Facebook

twitter module

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.

class social.twitter.Twitter[source]
Specificity of Twitter at the moment, the classes specifies the login and post method Twitter. Contain also
constant of the social network.
static login_submit(driver, login, password)[source]
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
static post(driver, message)[source]
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

linkedin module

social.linkedin module contains classes and methods specific to LinkedIn social network

Warning

Coding style is CamelCase for classes and lowercase_separated_by_underscores A.K.A snake_case for methods and variables.

class social.linkedin.LinkedIn[source]
Specificity of LinkedIn at the moment, the classes specifies the login and post method Twitter. Contain also
constant of the social network.
static login_submit(driver, login, password)[source]
Log in LinkedIn
param driver:Selenium driver of the bot
param login:Login to use for this bot
param password:Password to use for this bot
static post(driver, message)[source]
Method that defines the actions to post a message on LinkedIn
param driver:Selenium driver of the bot
param message:Message to post on linkedIn

configuration module

social.utils.CONFIG initialize the CONFIG object based on the configuration JSON