├── .env ├── config.py ├── requirements.txt ├── wishes.py ├── .gitignore ├── README.md └── app.py /.env: -------------------------------------------------------------------------------- 1 | source Scripts/activate 2 | . bin/activate 3 | 4 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | # Enter your credential here 2 | 3 | EMAIL = "" 4 | PASSWORD = "" 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.3 2 | packaging==16.8 3 | pyparsing==2.2.0 4 | selenium==3.3.0 5 | six==1.10.0 6 | -------------------------------------------------------------------------------- /wishes.py: -------------------------------------------------------------------------------- 1 | BIRTHDAY_WISHES = [ 2 | "Happy birthday!", 3 | "Happy birthday! :)", 4 | "Happy birthday! Wish you all the best!", 5 | "Happy birthday! Have a great one :D" 6 | ] 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /Include 2 | /Lib 3 | /Scripts 4 | /tcl 5 | /selenium 6 | 7 | /bin 8 | /include 9 | /lib 10 | 11 | __pycache__/ 12 | 13 | pip-selfcheck.json 14 | *.pyc 15 | chromedriver* 16 | config.* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Facebook Auto Post Birthday Message 2 | 3 | This hack can probably save 2 to 3 hours of your life. 4 | 5 | ## Setting Up 6 | 7 | 1. Download [Python 3.xx](https://www.python.org/downloads/) (*3.6 is recommended*) 8 | 2. Clone this repo by typing `git clone https://github.com/MaxKusnadi/fb-auto-birthday-post.git` on your command line 9 | 3. Enter `cd fb-auto-birthday-post` 10 | 4. Enter `pip install -r requirements.txt` 11 | 5. Download `chromedriver` from [here](https://sites.google.com/a/chromium.org/chromedriver/downloads). Unzip and put inside the `fb-auto-birthday-post` folder. **This is an important step, otherwise the program will not work** 12 | 6. Enter `python app.py` if *Setup Successful* appears on your command line, it means everything is fine 13 | 14 | ## Entering your credential 15 | 16 | There are 2 ways of entering your credential: 17 | 18 | 1. Open `config.py` using your favourite text editor and fill in your credentials there. This is recommended for automatic login. 19 | 2. Key in your credentials when your screen ask you to. 20 | 21 | ## Customizing your birthday wishes 22 | 23 | 1. Open `wishes.py` 24 | 2. Add your custom messages to the list 25 | 26 | ## Running this script on startup 27 | 28 | Linux user, check [this](http://askubuntu.com/questions/814/how-to-run-scripts-on-start-up) out. 29 | 30 | Windows user, you can go [here](https://www.howtogeek.com/138159/how-to-enable-programs-and-custom-scripts-to-run-at-boot/). 31 | 32 | ## GitBash Problem 33 | 34 | 35 | People who use windows git bash may get a problem in which password prompt does not appear after the email prompt. The solution can be found [here](http://stackoverflow.com/questions/32597209/python-not-working-in-the-command-line-of-git-bash) or else, just update `config.py` file 36 | 37 | --- 38 | 39 | Created by [me](https://maxkusnadi.github.io) 40 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import time 3 | 4 | from selenium import webdriver 5 | from selenium.webdriver.common.keys import Keys 6 | from config import EMAIL, PASSWORD 7 | from wishes import BIRTHDAY_WISHES 8 | 9 | 10 | logging.basicConfig(level=logging.INFO, 11 | format=' %(asctime)s - %(levelname)s - %(message)s') 12 | 13 | 14 | class FB_Auto_Birthday(object): 15 | 16 | def __init__(self): 17 | self.driver = None 18 | self.email = None 19 | self.password = None 20 | self.login = False 21 | 22 | def send_birthday_wishes(self): 23 | divs = self.get_birthday_list() 24 | birthday_div = divs.find_element_by_xpath("..") 25 | 26 | def is_today_birthday(): 27 | return "Today's Birthdays" in birthday_div.text 28 | 29 | def execute_no_birthday(): 30 | logging.info("There is no birthday today") 31 | self.driver.close() 32 | 33 | def execute_birthday(): 34 | text_areas = birthday_div.find_elements_by_tag_name("textArea") 35 | 36 | if len(text_areas) == 0: 37 | logging.info("You have wished everyone already :)") 38 | self.driver.close() 39 | 40 | import random 41 | import time 42 | 43 | for text in text_areas: 44 | text.send_keys(random.choice(BIRTHDAY_WISHES)) 45 | time.sleep(2) 46 | text.send_keys(Keys.RETURN) 47 | time.sleep(10) 48 | 49 | if is_today_birthday(): 50 | execute_birthday() 51 | else: 52 | execute_no_birthday() 53 | 54 | def get_birthday_list(self): 55 | return self.driver.find_element_by_id("birthdays_today_card") 56 | 57 | def getting_login_details(self): 58 | def ask_email(): 59 | email = input("What's your FB email? >> ") if len( 60 | EMAIL) == 0 else EMAIL 61 | self.email = email 62 | 63 | def ask_password(): 64 | import getpass 65 | password = getpass.getpass("What's your FB password? >> ") if len( 66 | PASSWORD) == 0 else PASSWORD 67 | self.password = password 68 | 69 | ask_email() 70 | ask_password() 71 | 72 | def firing_up_driver(self): 73 | def initialize_driver(): 74 | try: # Linux 75 | logging.info("Initializing chrome") 76 | self.driver = webdriver.Chrome('./chromedriver') 77 | except: 78 | logging.error("Can't initialize chrome") 79 | else: 80 | logging.info("Setup successful") 81 | 82 | def driver_open_url(): 83 | self.driver.get("http://facebook.com/events/birthdays") 84 | 85 | initialize_driver() 86 | driver_open_url() 87 | 88 | def sending_login_details(self): 89 | def send_email(): 90 | em = self.driver.find_element_by_name("email") 91 | em.clear() 92 | em.send_keys(self.email) 93 | 94 | def send_password(): 95 | pwd = self.driver.find_element_by_name("pass") 96 | pwd.clear() 97 | pwd.send_keys(self.password) 98 | pwd.send_keys(Keys.RETURN) 99 | 100 | send_email() 101 | send_password() 102 | 103 | def sign_in(self): 104 | def login_attempt(): 105 | self.getting_login_details() 106 | self.firing_up_driver() 107 | logging.info("Logging in...") 108 | self.sending_login_details() 109 | 110 | while self.login is False: 111 | login_attempt() 112 | 113 | try: 114 | self.get_birthday_list() 115 | except: 116 | # self.driver.close() 117 | logging.error("Wrong email or password?") 118 | global EMAIL 119 | global PASSWORD 120 | EMAIL = "" 121 | PASSWORD = "" 122 | else: 123 | self.login = True 124 | logging.info("Login Successful!") 125 | 126 | def main(self): 127 | self.sign_in() 128 | self.send_birthday_wishes() 129 | 130 | 131 | def main(): 132 | app = FB_Auto_Birthday() 133 | app.main() 134 | 135 | if __name__ == '__main__': 136 | main() 137 | --------------------------------------------------------------------------------