<commit_before># The Facebook Online Friend Tracker
# Author: <NAME>

import argparse
import csv
import os
import time

from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

def main():
  print('\nStarting script...')
  parser = argparse.ArgumentParser()
  parser.add_argument('--user', dest='facebook_username', required=True, help='the email that you login to facebook with')
  parser.add_argument('--pass', dest='facebook_password', required=True, help='the password that you login to facebook with')
  parser.add_argument('--path', dest='path_to_csv_file', required=True, help='the path to the csv file')

  args = parser.parse_args()
  facebook_username = args.facebook_username
  facebook_password = args.facebook_password
  path_to_csv_file = args.path_to_csv_file

  # Verify that the CSV file exists before scraping
  print('Verifying that the CSV file exists...')
  if os.path.exists(path_to_csv_file):
    print(path_to_csv_file + ' has been found.')
  else:
    print('[WARNING] ' + path_to_csv_file + ' does not exist. Creating a new CSV file now...')
    path_to_csv_file = os.path.join(os.getcwd(), 'facebook_online_friend_tracker_data.csv')
    with open(path_to_csv_file, 'w') as f:
      writer = csv.writer(f)
      writer.writerow(['Timestamp', 'Number of Online Friends'])
      print('New CSV file created at: ' + path_to_csv_file)

  # Initialize Chrome WebDriver and change default timeout
  print('\nInitializing Chrome WebDriver...')
  driver = webdriver.Chrome()
  driver.implicitly_wait(120)

  # Go to www.facebook.com and log in using the provided credentials
  print('Logging into Facebook...')
  driver.get('https://www.facebook.com/')
  emailBox = driver.find_element_by_id('email')
  emailBox.send_keys(facebook_username)
  passwordBox = driver.find_element_by_id('pass')
  passwordBox.send_keys(facebook_password)
  passwordBox.send_keys(Keys.RETURN)

  # Wait for Facebook to update the number of friends dynamically via an ajax call
  print('Waiting for Facebook to update friends list... (This takes approximately 2 minutes.)')
  script = '''var open = window.XMLHttpRequest.prototype.open;
              function openReplacement(method, url, async, user, password) {
                var syncMode = async !== false ? 'async' : 'sync';
                if (url === '/ajax/chat/buddy_list.php') {
                  var done = document.createElement('div');
                  done.id = 'doneScraping';
                  document.body.appendChild(done);
                }
                return open.apply(this, arguments);
              }
              window.XMLHttpRequest.prototype.open = openReplacement;'''
  driver.execute_script(script)
  doneScraping = driver.find_element_by_id('doneScraping')
  time.sleep(5)

  # Scrape the number of online friends
  onlineFriendsCount = int(driver.find_element_by_xpath('//*[@id="fbDockChatBuddylistNub"]/a/span[2]/span').text.strip('()'))
  print('\nDone! Detected ' + str(onlineFriendsCount) + ' online friends.')

  # Close Chrome WebDriver
  driver.close()

  # Get current time
  today = datetime.now().strftime('%Y/%m/%d %H:%M:%S')

  # Append row to the CSV file
  with open(path_to_csv_file, 'a') as f:
    writer = csv.writer(f)
    writer.writerow([today, onlineFriendsCount])
    print('Added: ' + today + ' -> ' + str(onlineFriendsCount) + ' to the spreadsheet.')
<commit_msg>Updated login flow to use click instead of Enter press.<commit_after># The Facebook Online Friend Tracker
# Author: <NAME>

import argparse
import csv
import os
import time

from datetime import datetime
from selenium import webdriver

def main():
  print('\nStarting script...')
  parser = argparse.ArgumentParser()
  parser.add_argument('--user', dest='facebook_username', required=True, help='the email that you login to facebook with')
  parser.add_argument('--pass', dest='facebook_password', required=True, help='the password that you login to facebook with')
  parser.add_argument('--path', dest='path_to_csv_file', required=True, help='the path to the csv file')

  args = parser.parse_args()
  facebook_username = args.facebook_username
  facebook_password = args.facebook_password
  path_to_csv_file = args.path_to_csv_file

  # Verify that the CSV file exists before scraping
  print('Verifying that the CSV file exists...')
  if os.path.exists(path_to_csv_file):
    print(path_to_csv_file + ' has been found.')
  else:
    print('[WARNING] ' + path_to_csv_file + ' does not exist. Creating a new CSV file now...')
    path_to_csv_file = os.path.join(os.getcwd(), 'facebook_online_friend_tracker_data.csv')
    with open(path_to_csv_file, 'w') as f:
      writer = csv.writer(f)
      writer.writerow(['Timestamp', 'Number of Online Friends'])
      print('New CSV file created at: ' + path_to_csv_file)

  # Initialize Chrome WebDriver and change default timeout
  print('\nInitializing Chrome WebDriver...')
  driver = webdriver.Chrome()
  driver.implicitly_wait(120)

  # Go to www.facebook.com and log in using the provided credentials
  print('Logging into Facebook...')
  driver.get('https://www.facebook.com/')
  emailBox = driver.find_element_by_id('email')
  emailBox.send_keys(facebook_username)
  passwordBox = driver.find_element_by_id('pass')
  passwordBox.send_keys(<PASSWORD>)
  driver.find_element_by_id('loginbutton').click()

  # Wait for Facebook to update the number of friends dynamically via an ajax call
  print('Waiting for Facebook to update friends list... (This takes approximately 2 minutes.)')
  script = '''var open = window.XMLHttpRequest.prototype.open;
              function openReplacement(method, url, async, user, password) {
                var syncMode = async !== false ? 'async' : 'sync';
                if (url === '/ajax/chat/buddy_list.php') {
                  var done = document.createElement('div');
                  done.id = 'doneScraping';
                  document.body.appendChild(done);
                }
                return open.apply(this, arguments);
              }
              window.XMLHttpRequest.prototype.open = openReplacement;'''
  driver.execute_script(script)
  doneScraping = driver.find_element_by_id('doneScraping')
  time.sleep(5)

  # Scrape the number of online friends
  onlineFriendsCount = int(driver.find_element_by_xpath('//*[@id="fbDockChatBuddylistNub"]/a/span[2]/span').text.strip('()'))
  print('\nDone! Detected ' + str(onlineFriendsCount) + ' online friends.')

  # Close Chrome WebDriver
  driver.close()

  # Get current time
  today = datetime.now().strftime('%Y/%m/%d %H:%M:%S')

  # Append row to the CSV file
  with open(path_to_csv_file, 'a') as f:
    writer = csv.writer(f)
    writer.writerow([today, onlineFriendsCount])
    print('Added: ' + today + ' -> ' + str(onlineFriendsCount) + ' to the spreadsheet.')

{'fraction_non_alphanumeric': 0.11893896177980605, 'fraction_numerical': 0.0017113519680547634, 'mean_word_length': 3.358607830950901, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6361998', 'n_tokens_mistral': 2187, 'n_tokens_neox': 2046, 'n_words': 533}