Skip to content

Instantly share code, notes, and snippets.

@Ronaldomata34
Last active January 5, 2018 18:01
Show Gist options
  • Save Ronaldomata34/99dd77978deded2edfd789cc7b3d15b8 to your computer and use it in GitHub Desktop.
Save Ronaldomata34/99dd77978deded2edfd789cc7b3d15b8 to your computer and use it in GitHub Desktop.
import time
from datetime import datetime, time
from getpass import getpass
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
def facebook_bot(email, pwd, description, post_url):
driver = webdriver.PhantomJS(service_args=['--ssl-protocol=any'])
print("accessing to Facebook / Login ...")
driver.get("https://mbasic.facebook.com/")
username_box = driver.find_element_by_name("email")
username_box.send_keys(email)
password_box = driver.find_element_by_name("pass")
password_box.send_keys(pwd)
login_btn = driver.find_element_by_name("login")
login_btn.submit()
button_cancel_save_account = driver.find_element_by_xpath('/html/body/div[1]/div/div/div/table/tbody/tr/td/div/div[3]/a')
if button_cancel_save_account:
button_cancel_save_account.click()
else:
pass
try:
driver.find_element_by_name("xc_message")
print("Logged in")
except NoSuchElementException as e:
print("Fail to login")
# GoAlabamaFootball/posts/2010903932526356
print("accessing the post address...")
driver.get(post_url)
buttons = driver.find_elements_by_tag_name("a")
for button in buttons:
if button.text == "Edit":
button.click()
break
else:
pass
input_edit = driver.find_element_by_name("p_text")
input_edit.clear()
print("writting new description...")
input_edit.send_keys(description)
save_button = driver.find_element_by_class_name("bn").click()
print("post updated")
if __name__ == '__main__':
email = input("Enter your Facebook Email: \n")
pwd = getpass("Enter your Facebook Password: \n")
post_id = input("Enter Post ID: \n")
description = input("Enter New Description: \n")
date_execution = input("DD/MM/YY : ")
hour = input("HH:MM (e.g.) : \n")
managed_page = input("Managed Page : \n")
post_url = "https://mbasic.facebook.com/{}/posts/{}".format(managed_page, post_id)
date_of_execution = "{} {}".format(date_execution, hour)
aux = datetime.strptime(date_of_execution, "%d/%m/%y %H:%M").strftime("%Y-%m-%d %H:%M")
print("current date: {}".format(datetime.now().strftime("%Y-%m-%d %H:%M")))
print("execution date: {}".format(aux))
while(True):
today = datetime.now().strftime("%Y-%m-%d %H:%M")
if today == aux:
facebook_bot(email, pwd, description, post_url)
print("the post {} was updated successfully".format(post_id))
print("You can to see it here: {}".format(post_url))
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment