<commit_before>#! /usr/bin/python
# python app.py domain_name.com pi_id
# Outputs decimal numbers to 74HCT595 shift registers connected
# to 74LS274 BCD-to-7-Segment decoders.

import RPi.GPIO as GPIO
import urllib2
import json
import time
import os
import sys

args=sys.argv

# IO Port definitions (not pins!)
GPIO_SER = 17 # serial data (high bit first) - to 595 SER (14)
GPIO_SCLK = 27  # Serial clock (rising edge) - to 595 SRCLK (11)
GPIO_RCLK = 22  # Register latch (rising edge) - to 595 RCLK (12)

NUM_DIGITS = 3  # Number of 7-segment displays
NUM_BITS = 4    # Bits in each digit

def setup():
  GPIO.setmode(GPIO.BCM)

  GPIO.setup(GPIO_SER, GPIO.OUT)
  GPIO.setup(GPIO_SCLK, GPIO.OUT)
  GPIO.setup(GPIO_RCLK, GPIO.OUT)

  GPIO.output(GPIO_SER, GPIO.LOW)
  GPIO.output(GPIO_SCLK, GPIO.LOW)
  GPIO.output(GPIO_RCLK, GPIO.LOW)

def output_digit(num):
  mask = 2**(NUM_BITS - 1)

  # shift BCD data into register high bit first
  for i in range(NUM_BITS):
    # set bit (SER input)
    GPIO.output(GPIO_SER, int(num) & int(mask) != 0)
    # shift with high strobe (SCLK)
    GPIO.output(GPIO_SCLK, GPIO.HIGH)
    GPIO.output(GPIO_SCLK, GPIO.LOW)
    mask = mask >> 1

def output(num):
  """ Outputs an integer number onto BCD display.
      Leading digits will be ignored if fewer than needed 7-segment 
      displays are in place as data simply shifts through.  """

  mask = 10 ** (NUM_DIGITS - 1)
  for digit in range(NUM_DIGITS):
    output_digit((num / mask) % 10)  
    mask = mask / 10
  # latch data into outputs with high strobe (RCLK)
  GPIO.output(GPIO_RCLK, GPIO.HIGH)
  GPIO.output(GPIO_RCLK, GPIO.LOW)

def main():
  setup()

  while (True):
    # getting the value from the cloud
    url = "http://" + os.getenv("metricsinyourfaceurl", args[1]) + "/getvalue?id=" + args[2]
    response = urllib.request.urlopen(url)
    data = json.loads(response.read().decode('utf-8'))
    #displaying the value
    output(int(data["value"]))
    time.sleep(2)

  # resetting GPIO messes up display
  GPIO.cleanup()

main()<commit_msg>correction urllib2<commit_after>#! /usr/bin/python
# python app.py domain_name.com pi_id
# Outputs decimal numbers to 74HCT595 shift registers connected
# to 74LS274 BCD-to-7-Segment decoders.

import RPi.GPIO as GPIO
import urllib2
import json
import time
import os
import sys

args=sys.argv

# IO Port definitions (not pins!)
GPIO_SER = 17 # serial data (high bit first) - to 595 SER (14)
GPIO_SCLK = 27  # Serial clock (rising edge) - to 595 SRCLK (11)
GPIO_RCLK = 22  # Register latch (rising edge) - to 595 RCLK (12)

NUM_DIGITS = 3  # Number of 7-segment displays
NUM_BITS = 4    # Bits in each digit

def setup():
  GPIO.setmode(GPIO.BCM)

  GPIO.setup(GPIO_SER, GPIO.OUT)
  GPIO.setup(GPIO_SCLK, GPIO.OUT)
  GPIO.setup(GPIO_RCLK, GPIO.OUT)

  GPIO.output(GPIO_SER, GPIO.LOW)
  GPIO.output(GPIO_SCLK, GPIO.LOW)
  GPIO.output(GPIO_RCLK, GPIO.LOW)

def output_digit(num):
  mask = 2**(NUM_BITS - 1)

  # shift BCD data into register high bit first
  for i in range(NUM_BITS):
    # set bit (SER input)
    GPIO.output(GPIO_SER, int(num) & int(mask) != 0)
    # shift with high strobe (SCLK)
    GPIO.output(GPIO_SCLK, GPIO.HIGH)
    GPIO.output(GPIO_SCLK, GPIO.LOW)
    mask = mask >> 1

def output(num):
  """ Outputs an integer number onto BCD display.
      Leading digits will be ignored if fewer than needed 7-segment 
      displays are in place as data simply shifts through.  """

  mask = 10 ** (NUM_DIGITS - 1)
  for digit in range(NUM_DIGITS):
    output_digit((num / mask) % 10)  
    mask = mask / 10
  # latch data into outputs with high strobe (RCLK)
  GPIO.output(GPIO_RCLK, GPIO.HIGH)
  GPIO.output(GPIO_RCLK, GPIO.LOW)

def main():
  setup()

  while (True):
    # getting the value from the cloud
    url = "http://" + os.getenv("metricsinyourfaceurl", args[1]) + "/getvalue?id=" + args[2]
    response = urllib2.urlopen(url)
    data = json.loads(response.read().decode('utf-8'))
    #displaying the value
    output(int(data["value"]))
    time.sleep(2)

  # resetting GPIO messes up display
  GPIO.cleanup()

main()
{'fraction_non_alphanumeric': 0.11771904062652962, 'fraction_numerical': 0.02594224180127264, 'mean_word_length': 3.466666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2428702', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1444, 'n_words': 440}