facebook data | Unfollow everyone on facebook | Cell 11 | Search

The code uses the selenium cell function to automate two tasks (log in facebook and unfollow everyone facebook) and handles their execution and errors using a series of then and catch blocks.

Cell 10

var importer = require('../Core');
var runSeleniumCell = importer.import("selenium cell");
// Unfollow everyone on facebook?

// https://www.facebook.com/me/following
var loginFacebook, unfollowFacebook;
$.async();
runSeleniumCell([
    'log in facebook',
    'unfollow everyone facebook'
])
    .then(r => {
        loginFacebook = r[0];
        unfollowFacebook = r[1];
        return loginFacebook();
    })
    .then(() => unfollowFacebook())
    .then(r => $.sendResult(r))
    .catch(e => $.sendError(e));

What the code could have been:

const importer = require('../Core');
const { runSeleniumCell } = importer.import('selenium cell');

/**
 * Unfollow everyone on Facebook using Selenium.
 * 
 * @returns {Promise<Array<string>>} A promise resolving to an array of function names.
 */
async function runFacebookUnfollow() {
  // Get the function names from the array
  const [loginFacebook, unfollowFacebook] = [
    'log in facebook',
    'unfollow everyone facebook'
  ];

  try {
    // Run the Selenium cell and get the function results
    const [loginResult, unfollowResult] = await runSeleniumCell([
      loginFacebook,
      unfollowFacebook
    ]);

    // Login using the login function result
    await loginResult();

    // Unfollow everyone using the unfollow function result
    await unfollowResult();

    // Return the result
    return $.sendResult(null);
  } catch (error) {
    // If an error occurs, send the error
    return $.sendError(error);
  }
}

// Run the function
runFacebookUnfollow().catch(e => $.sendError(e));

Code Breakdown

Importing Modules

var importer = require('../Core');
var runSeleniumCell = importer.import('selenium cell');

Selenium Automation

runSeleniumCell([
    'log in facebook',
    'unfollow everyone facebook'
])

Execution and Error Handling

.then(r => {
    loginFacebook = r[0];
    unfollowFacebook = r[1];
    return loginFacebook();
})
.then(() => unfollowFacebook())
.then(r => $.sendResult(r))
.catch(e => $.sendError(e));