Skip to content

Instantly share code, notes, and snippets.

@Ivoah
Created February 29, 2016 01:44
Show Gist options
  • Save Ivoah/076d65a87d5424bccbd6 to your computer and use it in GitHub Desktop.
Save Ivoah/076d65a87d5424bccbd6 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from requests import get
from bs4 import BeautifulSoup
import time
import Foundation
import objc
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):
notification = NSUserNotification.alloc().init()
notification.setTitle_(title)
notification.setSubtitle_(subtitle)
notification.setInformativeText_(info_text)
notification.setUserInfo_(userInfo)
if sound:
notification.setSoundName_("NSUserNotificationDefaultSoundName")
notification.setDeliveryDate_(Foundation.NSDate.dateWithTimeInterval_sinceDate_(delay, Foundation.NSDate.date()))
NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
oval = 0
while True:
val = int(BeautifulSoup(get('https://www.kickstarter.com/projects/214379695/micropython-on-the-esp8266-beautifully-easy-iot').text, 'html.parser').find_all('data')[2]['data-value'])
if val != oval:
notify('MicroPython donation!', 'Now at: {} pounds'.format(val), 'Somebody donated {} pounds'.format(val - oval), sound = True)
oval = val
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment