<commit_before>#!/usr/bin/env python
import RPi.GPIO as GPIO
import datetime
import requests
import settings
import time


class Pin(object):
    URL = "http://passoa.online.ntnu.no/notiwire/" + settings.NAME + '/'

    def post(self, data):
            data['api_key'] = settings.API_KEY
            r = requests.post(self.URL + self.relative_url, data=data)
            if settings.DEBUG:
                print 'POST:', self.URL + self.relative_url


class Coffee(Pin):
    pots = 0

    relative_url = 'coffee'

    def __init__(self, notipi, PIN):
        self.notipi = notipi
        self.PIN = PIN

        self.last = time.time()
        GPIO.setup(self.PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        # Running in it's own thread
        GPIO.add_event_detect(self.PIN, GPIO.RISING, callback=self.update, bouncetime=5000)

    def update(self, signal):
        self.pots += 1
        self.notipi.blink(2)
        # Date formatted like '06. October 2014 13:13:19'
        coffee_date = datetime.datetime.now().strftime('%d. %B %Y %H:%M:%S')
        self.post({'pots': self.pots, 'datetime': coffee_date})
        time.sleep(1)
        self.notipi.blink(2)
        if settings.DEBUG:
            print 'New coffee pot:', coffee_date


class Light(Pin):
    relative_url = 'light'

    def __init__(self, notipi, PIN):
        self.notipi = notipi
        self.PIN = PIN

        GPIO.setup(self.PIN, GPIO.IN)<commit_msg>Reset coffee counter after midnight (oops)<commit_after>#!/usr/bin/env python
import RPi.GPIO as GPIO
import datetime
import requests
import settings
import time


class Pin(object):
    URL = "http://passoa.online.ntnu.no/notiwire/" + settings.NAME + '/'

    def post(self, data):
            data['api_key'] = settings.API_KEY
            r = requests.post(self.URL + self.relative_url, data=data)
            if settings.DEBUG:
                print 'POST:', self.URL + self.relative_url


class Coffee(Pin):
    pots = 0

    relative_url = 'coffee'

    def __init__(self, notipi, PIN):
        self.notipi = notipi
        self.PIN = PIN

        self.day = datetime.date.today()
        GPIO.setup(self.PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        # Running in it's own thread
        GPIO.add_event_detect(self.PIN, GPIO.RISING, callback=self.update, bouncetime=5000)

    def update(self, signal):
        today = datetime.date.today()
        if today > self.day:
            self.pots = 0
            self.day = today
        self.pots += 1
        self.notipi.blink(2)
        # Date formatted like '06. October 2014 13:13:19'
        coffee_date = datetime.datetime.now().strftime('%d. %B %Y %H:%M:%S')
        self.post({'pots': self.pots, 'datetime': coffee_date})
        time.sleep(1)
        self.notipi.blink(2)
        if settings.DEBUG:
            print 'New coffee pot:', coffee_date


class Light(Pin):
    relative_url = 'light'

    def __init__(self, notipi, PIN):
        self.notipi = notipi
        self.PIN = PIN

        GPIO.setup(self.PIN, GPIO.IN)
{'fraction_non_alphanumeric': 0.12649402390438247, 'fraction_numerical': 0.014276228419654714, 'mean_word_length': 2.3146314631463145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '990847', 'n_tokens_mistral': 1060, 'n_tokens_neox': 988, 'n_words': 227}