Last active
March 8, 2016 15:13
-
-
Save steven2358/c063da3e6fc884047219 to your computer and use it in GitHub Desktop.
Check if Kaggle has launched a competition today
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
# Check if Kaggle has launched a competition today. | |
# | |
# Ported to Python 2 from https://github.com/BraunPhilipp/snippets/blob/master/kaggle.py | |
from urllib2 import urlopen | |
from bs4 import BeautifulSoup | |
import time | |
import random | |
import string | |
import datetime | |
page = urlopen("https://www.kaggle.com/competitions", timeout=5) | |
soup = BeautifulSoup(page, "html.parser") | |
competitions = soup.find('div', id='competitions-recent') | |
competitions = competitions.find_all('li') | |
new_competitions = [] | |
for competition in competitions: | |
try: | |
url = 'https://www.kaggle.com'+str(competition.find('a', class_='comp-link')['href']) | |
page = urlopen(url, timeout=5) | |
soup = BeautifulSoup(page, "html.parser") | |
start = ' '.join(soup.find("div", id='comp-header-stats-start').text.split()) | |
start = datetime.datetime.strptime(start, "%a %d %b %Y") | |
now = datetime.datetime.now() | |
if ( start.date() == now.date() ): | |
title = soup.find('h1').find('a').text | |
content = soup.find('div', class_='comp-content-inside') | |
new_competitions.append(url) | |
except: | |
pass | |
if (len(new_competitions) == 0): | |
print("NO NEW COMPETITIONS FOUND!") | |
else: | |
print("\n".join(new_competitions)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment