<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
# 2014 <NAME>

import os
import web
import json
import RPi.GPIO as GPIO
import time
from threading import Thread
from time import gmtime, strftime

# Set up LED on GPIO pin 22
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(22, GPIO.OUT)
GPIO.output(22,False)

# Blink the LED 10 times
def Blink():
  for i in range(0,20):
    GPIO.output(22,True)
    time.sleep(0.125)
    GPIO.output(22,False)
    time.sleep(0.125)

# Blink the LED 5 times – slowly.
def BlinkSlow():
  for i in range(0,5):
    GPIO.output(22,True)
    time.sleep(1)
    GPIO.output(22,False)
    time.sleep(1)

# Blink to indicate the server is listening
Thread(target=BlinkSlow).start()

# Catch the webhook
urls = ('/.*', 'hooks')
app = web.application(urls, globals())

class hooks:
  def POST(self):
    ip = web.ctx['ip']
    timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    serverlog = open('/home/pi/gonglord/server.log','a')

    # Write to the logfile
    serverlog.write('[' + ip + '] ' + timestamp + '\n')
    serverlog.close()

    # Make some noises
    print
    print 'drop da bass'
    print
    Thread(target=Blink).start()
    os.system("python /home/pi/gonglord/gong.py 1")

    return '200 OK'

if __name__ == '__main__':
  try:
    app.run()

  except KeyboardInterrupt:
    print
    print "Exiting..."
    print
    GPIO.cleanup()
    pigpio.stop()
    app.stop()<commit_msg>Writing to the log on start up and shut down<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
# 2014 <NAME>

import os
import web
import json
import RPi.GPIO as GPIO
import time
from threading import Thread
from time import gmtime, strftime

# Set up LED on GPIO pin 22
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(22, GPIO.OUT)
GPIO.output(22,False)

# Blink the LED 10 times
def Blink():
  for i in range(0,20):
    GPIO.output(22,True)
    time.sleep(0.125)
    GPIO.output(22,False)
    time.sleep(0.125)

# Blink the LED 5 times – slowly.
def BlinkSlow():
  for i in range(0,5):
    GPIO.output(22,True)
    time.sleep(1)
    GPIO.output(22,False)
    time.sleep(1)

# Blink to indicate the server is listening
Thread(target=BlinkSlow).start()

# Catch the webhook
urls = ('/.*', 'hooks')
app = web.application(urls, globals())

class hooks:
  def POST(self):
    ip = web.ctx['ip']
    timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    serverlog = open('/home/pi/gonglord/server.log','a')

    # Write to the logfile
    serverlog.write('[' + ip + '] ' + timestamp + '\n')
    serverlog.close()

    # Make some noises
    print
    print 'drop da bass'
    print
    Thread(target=Blink).start()
    os.system("python /home/pi/gonglord/gong.py 1")

    return '200 OK'

if __name__ == '__main__':
  try:
    timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    serverlog = open('/home/pi/gonglord/server.log','a')
    serverlog.write('Server starting: ' + timestamp + '\n')
    serverlog.close()
    app.run()

  except KeyboardInterrupt:
    timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    serverlog = open('/home/pi/gonglord/server.log','a')
    serverlog.write('Server stopping: ' + timestamp + '\n')
    serverlog.close()
    print
    print "Exiting..."
    print
    GPIO.cleanup()
    pigpio.stop()
    app.stop()
{'fraction_non_alphanumeric': 0.15956482320942883, 'fraction_numerical': 0.0247809005741916, 'mean_word_length': 3.1792929292929295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4364467', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1199, 'n_words': 304}