#!/usr/bin/env python3 """ Module to submit FTC harassing call and Do Not Call complaints. Call like so: python3 -- ftc.py --call_name "Maryland" --call_number "443-347-5935" --call_datetime "June 14, 2021 13:42" """ # For the endless list of Chrome options to keep the scripts # running see https://stackoverflow.com/a/52340526. import time import sys import glob import errno import os.path from random import randint from packaging import version from dateutil import parser import selenium from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.options import Options def get_option(argv, option): """ Helper function to return an option's argument or None. """ argc = len(argv) for i in range(0, argc-1): if (argv[i] == option and i+1 < argc): return argv[i+1] return None def get_chrome(): """ Helper function to locate chrome browser. """ if os.path.isfile('/usr/bin/chromium-browser'): return '/usr/bin/chromium-browser' if os.path.isfile('/usr/bin/chromium'): return '/usr/bin/chromium' if os.path.isfile('/usr/bin/chrome'): return '/usr/bin/chrome' if os.path.isfile('/usr/bin/google-chrome'): return '/usr/bin/google-chrome' return None def print_screen(driver, numerator): """ Helper function to take a screenshot """ print_screen.counter += 1 # document.body.scrollHeight driver.execute_script("window.scrollTo(0, 0);") if numerator == 0: driver.execute_script("window.scrollTo(0, 250*0);") elif numerator == 1: driver.execute_script("window.scrollTo(0, 250*1);") elif numerator == 2: driver.execute_script("window.scrollTo(0, 250*2);") elif numerator == 3: driver.execute_script("window.scrollTo(0, 250*3);") elif numerator == 4: driver.execute_script("window.scrollTo(0, 250*4);") elif numerator == 5: driver.execute_script("window.scrollTo(0, 250*5);") elif numerator == 6: driver.execute_script("window.scrollTo(0, 250*6);") elif numerator == 7: driver.execute_script("window.scrollTo(0, 250*7);") elif numerator == 8: driver.execute_script("window.scrollTo(0, 250*8);") else: driver.execute_script("window.scrollTo(0, 250*10);") driver.save_screenshot('screenshots/ftc-' + str(print_screen.counter).zfill(2) + '.png') print_screen.counter = 0 def prepare_screenshots(): """ Helper function to prepare screenshots """ try: os.mkdir('screenshots') except OSError as exception: if exception.errno != errno.EEXIST: raise filelist = glob.glob(os.path.join('screenshots', "ftc*.png")) for file in filelist: os.remove(file) def main(): """ Module to submit FTC Do Not Call complaints. """ ################################################# call_name = get_option(sys.argv, "--call_name") call_number = get_option(sys.argv, "--call_number") call_datetime = get_option(sys.argv, "--call_datetime") if call_name is None: sys.exit("call_name is not available") if call_number is None: sys.exit("call_number is not available") if call_datetime is None: sys.exit("call_datetime is not available") parsed = parser.parse(call_datetime) call_date = parsed.strftime("%m/%d/%Y") call_hour = parsed.strftime("%I:00 %p") call_minute = parsed.strftime("%M") # print("(ftc) call_name: " + str(call_name)) # print("(ftc) call_number: " + str(call_number)) # print("(ftc) call_date: " + str(call_date)) # print("(ftc) call_hour: " + str(call_hour)) # print("(ftc) call_minute: " + str(call_minute)) # Prepare directory for next set of screenshots prepare_screenshots() ################################################# print("(ftc) Starting driver") if version.parse(selenium.__version__) >= version.parse("3.0"): opts = Options() opts.binary_location = get_chrome() opts.add_argument('--headless') opts.add_argument('--no-sandbox') opts.add_argument('--disable-dev-shm-usage') opts.add_argument('--disable-gpu') # The assholes changed it again... try: driver = webdriver.Chrome(options=opts) except: driver = webdriver.Chrome(chrome_options=opts) driver.maximize_window() else: profile = webdriver.ChromeProfile() profile.headless = True profile.binary_location = get_chrome() driver = webdriver.Chrome(profile) driver.maximize_window() # agent = driver.execute_script('return navigator.userAgent') # print(agent) ################################################# ### Page 1 # driver.get("https://complaints.donotcall.gov/complaint/complaintcheck.aspx") driver.get("https://www.donotcall.gov/report.html") # ids = driver.find_elements_by_xpath('//*[@id]') # for ii in ids: # print(ii.get_attribute('id')) time.sleep(randint(4, 10)) print_screen(driver, 0) print_screen(driver, 1) # print("Clicking Continue") button_continue = driver.find_element_by_id("MainContinueButton") button_continue.click() ################################################# ### Page 2 # ids = driver.find_elements_by_xpath('//*[@id]') # for ii in ids: # print(ii.get_attribute('id')) # print("Random sleep") time.sleep(randint(4, 10)) print_screen(driver, 0) print_screen(driver, 1) text_our_phone = driver.find_element_by_id("PhoneTextBox") text_our_phone.send_keys("4104395915") text_calendar = driver.find_element_by_id("DateOfCallTextBox") text_calendar.send_keys(call_date) text_calendar.send_keys(Keys.ESCAPE) dropdown_hour = driver.find_element_by_id("TimeOfCallDropDownList") dropdown_hour.send_keys(call_hour) dropdown_minute = driver.find_element_by_id("ddlMinutes") dropdown_minute.send_keys(call_minute) print_screen(driver, 2) radio_robocall = driver.find_element_by_id("PrerecordMessageYESRadioButton") radio_robocall.click() radio_phonecall = driver.find_element_by_id("PhoneCallRadioButton") radio_phonecall.click() dropdown_subject = driver.find_element_by_id("ddlSubjectMatter") dropdown_subject.send_keys("Unknown") time.sleep(randint(4, 10)) print_screen(driver, 3) # print("Clicking Continue") button_continue = driver.find_element_by_id("StepOneContinueButton") button_continue.click() ################################################# ### Page 3 # ids = driver.find_elements_by_xpath('//*[@id]') # for ii in ids: # print(ii.get_attribute('id')) time.sleep(randint(4, 10)) print_screen(driver, 0) print_screen(driver, 1) text_caller_phone = driver.find_element_by_name("CallerPhoneNumberTextBox") text_caller_phone.send_keys(call_number) text_call_name = driver.find_element_by_name("CallerNameTextBox") text_call_name.send_keys(call_name) radio_business = driver.find_element_by_id("HaveBusinessNoRadioButton") radio_business.click() radio_stop_calls = driver.find_element_by_id("StopCallingYesRadioButton") radio_stop_calls.click() text_first_name = driver.find_element_by_id("FirstNameTextBox") text_first_name.send_keys("Iris") text_last_name = driver.find_element_by_id("LastNameTextBox") text_last_name.send_keys("Walton") print_screen(driver, 1) text_address = driver.find_element_by_id("StreetAddressTextBox") text_address.send_keys("231 Beachwood Road") text_city = driver.find_element_by_id("CityTextBox") text_city.send_keys("Pasadena") print_screen(driver, 2) dropdown_state = driver.find_element_by_id("StateDropDownList") dropdown_state.send_keys("MD") text_zip = driver.find_element_by_id("ZipCodeTextBox") text_zip.send_keys("21122") text_comment = driver.find_element_by_id("CommentTextBox") text_comment.send_keys("Another DNC violation. Reported to Verizon " + \ "Unlawful Call Center using *57 Call Trace.") print_screen(driver, 2) print_screen(driver, 3) time.sleep(randint(4, 10)) # print("Clicking Continue") button_continue = driver.find_element_by_id("StepTwoSubmitButton") button_continue.click() ################################################# ### Page 4 time.sleep(randint(4, 10)) print_screen(driver, 0) print_screen(driver, 1) print("(ftc) Stopping driver") driver.quit() if __name__ == "__main__": main()