Skip to content

Instantly share code, notes, and snippets.

@steven2358
Last active March 8, 2016 15:13
Show Gist options
  • Save steven2358/c063da3e6fc884047219 to your computer and use it in GitHub Desktop.
Save steven2358/c063da3e6fc884047219 to your computer and use it in GitHub Desktop.
Check if Kaggle has launched a competition today
# 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