Last active
December 11, 2015 20:09
-
-
Save tcg/4653530 to your computer and use it in GitHub Desktop.
Something Sweet to Comfort some folks that are tired of checking the box. Bloated requirements, but it works. Want to skip Requests and use something more native? DO IT! Updated! Now: More bloat! But less rude, and works FASTER! YAY!
This file contains 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 requests # `pip install requests`; DO IT! | |
import time | |
import sys | |
class ComfortSweet: | |
TIME_THRESHOLD = 30 # seconds | |
LAST_ATTEMPT = 0 | |
def main(self): | |
now = time.time() | |
if now > self.LAST_ATTEMPT + self.TIME_THRESHOLD: | |
self.LAST_ATTEMPT = time.time() | |
expected_form_data = { | |
'username': 'hotelguest', # Checkbox | |
'password': 'wireless', # Hidden | |
'original_url': 'http://www.gstatic.com/generate_204', # Hidden | |
'login': 'Accept', # Named Submit button | |
} | |
result = requests.get("http://www.google.com/", allow_redirects=False) | |
if result.status_code != 200: | |
r = s.post('http://wireless.colubris.com:1080/goform/HtmlLoginRequest', data=expected_form_data) | |
print "\nPosted the goods. Welcome back to the internet." | |
# Be nice. | |
sys.stdout.write(".") | |
time.sleep(5) | |
sys.stdout.flush() | |
if __name__ == '__main__': | |
CS = ComfortSweet() | |
while True: | |
try: | |
CS.main() | |
except KeyboardInterrupt: | |
sys.exit() | |
except Exception as e: | |
print e.__class__.__name__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment