<commit_before>
import sys
import requests

import imaging
import analysis

import serial
import time

ser = serial.Serial(sys.argv[2], 9600)

session_name = sys.argv[1]
print('Sending photo to session: -'+session_name+'-')
global session_status_request_error_counter = 0

def looping():
    sessionstatusrequest_successful = False
    while sessionstatusrequest_successful == False:
        try:
            req = requests.get('http://digitalfoodone.appspot.com/controllersessionstatus', params={'session_name':session_name})
            print(str(req.status_code))
            data = req.json()
            print(data['state'])

            def imagestuff():
                resp = imaging.capture(session_name,'capturing')
                print('Received http status code: '+str(resp.status_code))
                data = resp.json()
                print('Status: '+data['status'])
                analysis_resp = analysis.red_spot(session_name)
                print('Received http status code: '+str(analysis_resp.status_code))
                analysis_data = analysis_resp.json()
                print('Analysis status: '+analysis_data['status'])


            if data['state'] == 'rewind':
                ser.write(chr(1))
                ser.write(chr(1))
                ser.write(chr(1))
                ser.write(chr(1))
                ser.write(chr(1))
                ser.write(chr(1))
                imagestuff()
            if data['state'] == 'play_one':
                ser.write(chr(70))
                imagestuff()
            if data['state'] == 'play_two':
                print('waiting')
            sessionstatusrequest_successful = True
        except requests.exceptions.Timeout:
            print("session status request: request timeout")
        except requests.exceptions.TooManyRedirects:
            print('session status request: too many redirects')
        except requests.exceptions.RequestException as e:
            print('session status request: request exception:')
            print e
        print('apparently not successful - trying again in 10 sec')
        global session_status_request_error_counter += 1
        print('number of status request errors: '+session_status_request_error_counter)
        time.sleep(10)


while True:
    looping()
    time.sleep(8)
<commit_msg>added exception handling to all requests<commit_after>
import sys
import requests

import imaging
import analysis

import serial
import time

ser = serial.Serial(sys.argv[2], 9600)

session_name = sys.argv[1]
print('Sending photo to session: -'+session_name+'-')
session_status_request_error_counter = 0

def looping():
    global session_status_request_error_counter
    sessionstatusrequest_successful = False
    while sessionstatusrequest_successful == False:
        try:
            req = requests.get('http://digitalfoodone.appspot.com/controllersessionstatus', params={'session_name':session_name})
            print(str(req.status_code))
            data = req.json()
            print(data['state'])

            def imagestuff():
                resp = imaging.capture(session_name,'capturing')
                print('Received http status code: '+str(resp.status_code))
                data = resp.json()
                print('Status: '+data['status'])
                analysis_resp = analysis.red_spot(session_name)
                print('Received http status code: '+str(analysis_resp.status_code))
                analysis_data = analysis_resp.json()
                print('Analysis status: '+analysis_data['status'])


            if data['state'] == 'rewind':
                ser.write(chr(1))
                ser.write(chr(1))
                ser.write(chr(1))
                ser.write(chr(1))
                ser.write(chr(1))
                ser.write(chr(1))
                imagestuff()
            if data['state'] == 'play_one':
                ser.write(chr(70))
                imagestuff()
            if data['state'] == 'play_two':
                print('waiting')
            sessionstatusrequest_successful = True
        except requests.exceptions.Timeout:
            print("session status request: request timeout")
        except requests.exceptions.TooManyRedirects:
            print('session status request: too many redirects')
        except requests.exceptions.RequestException as e:
            print('session status request: request exception:')
            print e
        print('apparently not successful - trying again in 10 sec')
        global session_status_request_error_counter += 1
        print('number of status request errors: '+session_status_request_error_counter)
        time.sleep(10)


while True:
    looping()
    time.sleep(8)

{'fraction_non_alphanumeric': 0.10474978795589483, 'fraction_numerical': 0.008905852417302799, 'mean_word_length': 2.2463867859600826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2322772', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1202, 'n_words': 276}