Skip to content

Instantly share code, notes, and snippets.

@vinay13
Created August 8, 2016 05:56
Show Gist options
  • Save vinay13/2dcad9fbd32b10786bca25d8a1e1c31a to your computer and use it in GitHub Desktop.
Save vinay13/2dcad9fbd32b10786bca25d8a1e1c31a to your computer and use it in GitHub Desktop.
import os
import requests
import bs4
from apscheduler.schedulers.blocking import BlockingScheduler
def CheckWin():
url = 'http://www.nbcolympics.com/medals'
response = requests.get(url)
html = response.content
#[sudo] gem install terminal-notifier for osx
def notify(title, subtitle, message):
t = '-title {!r}'.format(title)
s = '-subtitle {!r}'.format(subtitle)
m = '-message {!r}'.format(message)
os.system('terminal-notifier {}'.format(' '.join([m, t, s])))
country = []
soup = bs4.BeautifulSoup(html,'html.parser')
table = soup.find('table')
#for row in table.findAll('tr'):
for cell in table.findAll('a'):
find_india=cell.text.strip()
#find_india=cell.text.replace(' ', '')
#find_india
#find_india.replace("u'\n\n'",'')
country.append(str(find_india))
#print country
if 'India' in country:
return notify(title = 'India Win',
subtitle = 'in rio olympic',
message = 'Yeah!!, We won .. hurrayyy')
#print "we won!!"
else:
return notify(title = 'No Win Yet',
subtitle = 'in rio olympic',
message = 'best of luck india')
scheduler = BlockingScheduler()
scheduler.add_job(CheckWin, 'interval', hours=15)
scheduler.start()
"""
html =
<html>
<body>
<table>
<tr>
<td>45</td>
</tr>
</table>
</body>
</html>
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment