from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pickle
import time

#paramter list
#saved_cookie_file = ""
#filter_name = ""
#notification_email_id = ""
#folder_name = ""


#logging in using saved cookies
driver = webdriver.Firefox()
driver.get("https://mail.yahoo.com")
cookies = pickle.load(open("yahoo.pkl", "rb"))
for cookie in cookies:
     driver.add_cookie(cookie)
driver.refresh()

#adding filter

#access filter page
driver.get("https://mail.yahoo.com/d/settings/7")

time.sleep(5)

#add filter button
filter_add = driver.find_element_by_xpath("/html/body/div[1]/div/div[1]/div/div[2]/div/div/div/section/div/article/div/div[1]/div/div[2]/div[3]/button")
filter_add.send_keys(Keys.RETURN)

time.sleep(5)

#add filter name
#edit req : parameterize
filter_name = driver.find_element_by_xpath("/html/body/div[1]/div/div[1]/div/div[2]/div/div/div/section/div/article/div/div[2]/div/div/div[1]/div/div[1]/input")
filter_name.send_keys("temp1")

#select other form intputs
#edit req : add custom options, better comments here
filter_rule1 = driver.find_element_by_xpath("/html/body/div[1]/div/div[1]/div/div[2]/div/div/div/section/div/article/div/div[2]/div/div/div[2]/div/ul/li[1]/article/div[1]/div/div[1]/input")
filter_rule1.click()
filter_rule1_1 = driver.find_element_by_xpath("/html/body/div[1]/div/div[1]/div/div[2]/div/div/div/section/div/article/div/div[2]/div/div/div[2]/div/ul/li[1]/article/div[1]/div/div[2]/ul/li[1]/a")
filter_rule1_1.click()

#add notif email id
#edit req : parameterize
filter_rule2 = driver.find_element_by_xpath("/html/body/div[1]/div/div[1]/div/div[2]/div/div/div/section/div/article/div/div[2]/div/div/div[2]/div/ul/li[1]/article/div[2]/div/input")
filter_rule2.clear()
#filter_rule2.send_keys("saikrishnaragam.temp@gmail.com")
filter_rule2.send_keys("postmaster@investopedia.com")

#add folder name
#edit req : parameterize
filter_rule3 = driver.find_element_by_xpath("/html/body/div[1]/div/div[1]/div/div[2]/div/div/div/section/div/article/div/div[2]/div/div/div[3]/div[2]/div/div/input")
filter_rule3.send_keys("Notes")

#save filter
filter_save = driver.find_element_by_xpath("/html/body/div[1]/div/div[1]/div/div[2]/div/div/div/section/div/article/div/div[2]/div/div/div[4]/button[1]")
filter_save.click()

#reset driver
driver.delete_all_cookies()
driver.refresh()

time.sleep(3)

driver.close()
