Last active
November 28, 2018 11:05
-
-
Save dipu-bd/555183e2362a82ef534c343ffdc56f94 to your computer and use it in GitHub Desktop.
Visit stackoverflow everyday to get the Fanatic badge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from os import path | |
from datetime import datetime | |
from splinter import Browser | |
email = "<EMAIL>" | |
password = "<PASSWORD>" | |
user_name = "<USER_NAME>" | |
dir_path = path.dirname(path.realpath(__file__)) | |
driver_path = path.join(dir_path, 'lib', 'chromedriver') | |
def run_task(): | |
browser = Browser( | |
'chrome', | |
headless=True, | |
incognito=True, | |
executable_path=driver_path | |
) | |
login = "https://stackoverflow.com/users/login" | |
logout = "https://stackoverflow.com/users/logout" | |
profile = "https://stackoverflow.com/users/1583052/" + user_name | |
print(datetime.now(), 'Visiting login...') | |
browser.visit(login) | |
browser.fill('email', email') | |
browser.fill('password', password) | |
time.sleep(1) | |
script = '$("#submit-button").click();' | |
browser.execute_script(script) | |
print(datetime.now(), 'Awaiting login...') | |
seconds = 0 | |
while seconds < 60 and len(browser.find_by_css('.my-profile')) == 0: | |
time.sleep(1) | |
seconds += 1 | |
time.sleep(1) | |
print(datetime.now(), 'Visiting profile...') | |
browser.visit(profile) | |
elem = browser.find_by_css( | |
'#top-cards .js-highlight-box-badges span.grid--cell.fs-caption') | |
if len(elem) > 0: | |
elem = elem.first | |
print(datetime.now(), elem.text) | |
else: | |
print(datetime.now(), '<!> Badge count not present.') | |
print(datetime.now(), 'Wait a little...') | |
time.sleep(20) | |
print(datetime.now(), 'Visiting logout...') | |
browser.visit(logout) | |
time.sleep(1) | |
script = '$("#logout-form #controls input")[0].click();' | |
browser.execute_script(script) | |
print(datetime.now(), 'Awaiting logout...') | |
seconds = 0 | |
while seconds < 60 and len(browser.find_by_css('.login-link')) == 0: | |
time.sleep(1) | |
seconds += 1 | |
time.sleep(1) | |
print(datetime.now(), 'Exit') | |
browser.quit() | |
if __name__ == '__main__': | |
print('$ python3 stackoverflow.py') | |
print('-----------------------------------') | |
run_task() | |
print('-----------------------------------') | |
print('') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup it as a cron in a server: