from json import loads from bs4 import BeautifulSoup import mechanize api_key = "8def4868-509c-4f34-8667-f28684483810%3AS7obmNY1SsOfHLhP%2Fft6Z%2Fwc46x8B2W3BaHpa5aK2vJwy8VSTHvaPVuUpSLimHkn%2BLqSjT6NERzxqdvQ%2BpQfYA%3D%3D" growth_coupon_url = "https://api.import.io/store/data/a5ef05a9-784e-410c-9f84-51e1e8ff413c/_query?input/webpage/url=http%3A%2F%2Fgrowthcoupon.com%2Fcoupon-category%2F100-discount%2F&_user=8def4868-509c-4f34-8667-f28684483810&_apikey=" + api_key br = mechanize.Browser() br.set_handle_robots(False) br.addheaders = [("User-agent","Mozilla/5.0 (X11; U; Linux i686; en-US; rv:188.8.131.52) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13")] sign_in = br.open("https://www.udemy.com/join/login-popup/") br.select_form(nr=3) br["email"] = "email@example.com" br["password"] = "password" logged_in = br.submit() growth_coupon = br.open(growth_coupon_url) json_obj = loads(growth_coupon.read()) for course_link in json_obj["results"]: try: course_page = br.open(str(course_link["couponcode_link"])) soup = BeautifulSoup(course_page) for link in soup.find_all("a"): req_link = link.get('href') if 'https://www.udemy.com/payment/checkout' in str(req_link): print req_link br.open(str(req_link)) print "success" break except (mechanize.HTTPError,mechanize.URLError) as e: print e.code
This has been my favorite automation throughout the semester. The program checks growthcoupon.com for 100% off coupon codes for paid courses offered at Udemy and enrolls me to those courses. I have uploaded the program to pythonanywhere.com which allows me to have the script run daily(for free accounts) without me having to worry about it. At this time I have over 800 courses at my Udemy account, each courses on an average costs 75$.
import time from selenium import webdriver from selenium.webdriver.common.keys import Keys browser = webdriver.Firefox() browser2 = webdriver.Firefox() browser.get("http://cleverbot.com") browser2.get("http://cleverbot.com") time.sleep(15) input_for_bot = browser.find_element_by_name("stimulus") input_for_bot2 = browser2.find_element_by_name("stimulus") output_from_bot = "" output_from_bot2 = "Hey, friend, what's up" for i in range(0, 200): input_for_bot.send_keys(output_from_bot2) input_for_bot.send_keys(Keys.RETURN) output_from_bot = "" time.sleep(5) for elem in browser.find_elements_by_xpath('.//span[@class="bot"]'): output_from_bot = elem.text input_for_bot2.send_keys(output_from_bot) input_for_bot2.send_keys(Keys.RETURN) output_from_bot2 = "" time.sleep(5) for elem in browser2.find_elements_by_xpath('.//span[@class="bot"]'): output_from_bot2 = elem.text
This semester, I had to take Cognitive Science course. I enjoyed it. I had this assignment where I had to submit a page of conversation with cleverbot (www.cleverbot.com). I submitted the assignment and later decided to bridge a conversation between two cleverbots. I used selenium module in python to have this done. It was great and kind of felt like an achievement.
import pyautogui import time pyautogui.click(450,450);pyautogui.typewrite('graphicsnotes');pyautogui.press('enter') time.sleep(2) for i in range(107): pyautogui.press('right');pyautogui.press('enter') pyautogui.hotkey('ctrl','r');pyautogui.hotkey('ctrl','s') time.sleep(2) pyautogui.press('esc') time.sleep(2)
Being lazy to copy notes at class, I had to rely on photos of the notes sent by my friend. I discovered that the photos were all in landscape and were 107 pictures. I had come across pyautogui in A.I Sweigart’s course at Udemy and quickly wrote some 5-7 lines of code to open the picture and rotate the image and save it while I had my dinner. By the way I had no clue I had been enrolled in A.I Sweigart’s course until I opened my account to check which courses I had. All thanks to pythonanywhere.com which runs my program to enroll to Udemy courses on a daily basis.
from selenium import webdriver from selenium.webdriver.common.keys import Keys browser= webdriver.Firefox() browser.get("https://dropbox.com/register") list_of_inputs = browser.find_elements_by_xpath("//div/input[starts-with(@id, 'pyxl')]") list_of_inputs.send_keys("first name") list_of_inputs.send_keys("last name") list_of_inputs.send_keys("email") list_of_inputs.send_keys("password") list_of_inputs.click() password.send_keys(Keys.RETURN)
I had been involved with some people from IIT for some app ideas. We needed cloud space and agreed to use Dropbox. I had been given a bunch of emails with common password. I wrote a program in python to do the signups and later wrote a program to make apps at dropbox and get the API keys and secret keys to access the files in there. Unfortunately the project never continued for some reasons.
Overall, I had a good year but most of the time was spent at college and internship (doing mobile apps using Apache Cordova). For the new year, I will talk to my manager about switching to some python projects. My new year resolution would be to “write more codes and continue blogging about it.” Well that’s all I can think for now.
I would want some suggestions for my new year resolution. Do comment below. Once again A Happy New Year .