<s> try : <EOL> import config <EOL> except ImportError : <EOL> print ( "<STR_LIT>" ) ; exit ( ) ; <EOL> debug_communication = <NUM_LIT:0> <EOL> try : <EOL> from Tkinter import * <EOL> except ImportError : <EOL> from tkinter import * <EOL> import json <EOL> import time <EOL> import urllib3 <EOL> def send_to_hcp ( ) : <EOL> global debug_communication <EOL> global http <EOL> global url <EOL> global headers <EOL> global s1 <EOL> timestamp = int ( time . time ( ) ) <EOL> body = '<STR_LIT>' + str ( config . message_type_id_From_device ) + '<STR_LIT>' + str ( s1 . get ( ) ) + '<STR_LIT>' + str ( timestamp ) + '<STR_LIT>' <EOL> r = http . urlopen ( '<STR_LIT:POST>' , url , body = body , headers = headers ) <EOL> if ( debug_communication == <NUM_LIT:1> ) : <EOL> print ( "<STR_LIT>" + str ( r . status ) ) <EOL> print ( r . data ) <EOL> def poll_from_hcp ( ) : <EOL> global debug_communication <EOL> global http <EOL> global url <EOL> global headers <EOL> global t1 <EOL> global f4_cb1 <EOL> r = http . urlopen ( '<STR_LIT:GET>' , url , headers = headers ) <EOL> if ( debug_communication == <NUM_LIT:1> ) : <EOL> print ( "<STR_LIT>" + str ( r . status ) ) <EOL> print ( r . data ) <EOL> json_string = '<STR_LIT>' + ( r . data ) . decode ( "<STR_LIT:utf-8>" ) + '<STR_LIT:}>' <EOL> try : <EOL> json_string_parsed = json . loads ( json_string ) <EOL> try : <EOL> messages_reversed = reversed ( json_string_parsed [ "<STR_LIT>" ] ) <EOL> for single_message in messages_reversed : <EOL> payload = single_message [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> opcode = payload [ "<STR_LIT>" ] <EOL> operand = payload [ "<STR_LIT>" ] <EOL> if ( opcode == "<STR_LIT>" ) : <EOL> t1 . config ( state = NORMAL ) <EOL> t1 . delete ( <NUM_LIT:1.0> , END ) <EOL> t1 . insert ( END , operand ) <EOL> t1 . config ( state = DISABLED ) <EOL> if ( opcode == "<STR_LIT>" ) : <EOL> f4_cb1 . config ( state = NORMAL ) <EOL> if ( operand == "<STR_LIT:0>" ) : <EOL> f4_cb1 . deselect ( ) <EOL> if ( operand == "<STR_LIT:1>" ) : <EOL> f4_cb1 . select ( ) <EOL> f4_cb1 . config ( state = DISABLED ) <EOL> except TypeError : <EOL> print ( "<STR_LIT>" + ( r . data ) . decode ( "<STR_LIT:utf-8>" ) + "<STR_LIT>" ) <EOL> except ValueError : <EOL> print ( "<STR_LIT>" + ( r . data ) . decode ( "<STR_LIT:utf-8>" ) + "<STR_LIT>" ) <EOL> def handle_slider ( event ) : <EOL> global do_send <EOL> global s1 <EOL> global cb1 <EOL> value = s1 . get ( ) <EOL> if ( value == <NUM_LIT:100> ) : <EOL> do_send = <NUM_LIT:1> <EOL> cb1 . config ( state = NORMAL ) <EOL> cb1 . select ( ) <EOL> cb1 . config ( state = DISABLED ) <EOL> if ( value == <NUM_LIT:0> ) : <EOL> do_send = <NUM_LIT:0> <EOL> cb1 . config ( state = NORMAL ) <EOL> cb1 . deselect ( ) <EOL> cb1 . config ( state = DISABLED ) <EOL> def handle_exit_button ( ) : <EOL> exit ( ) <EOL> def my_send_timer ( ) : <EOL> global root <EOL> global do_send <EOL> if ( do_send == <NUM_LIT:1> ) : <EOL> send_to_hcp ( ) <EOL> root . after ( <NUM_LIT:1000> , my_send_timer ) <EOL> def my_poll_timer ( ) : <EOL> global root <EOL> poll_from_hcp ( ) <EOL> root . after ( <NUM_LIT:1000> , my_poll_timer ) <EOL> def build_and_start_ui_with_timers ( ) : <EOL> global root <EOL> global s1 <EOL> global cb1 <EOL> global f4_cb1 <EOL> global t1 <EOL> root = Tk ( ) <EOL> root . resizable ( FALSE , FALSE ) <EOL> root . title ( "<STR_LIT>" ) <EOL> root . geometry ( '<STR_LIT>' ) <EOL> l1 = Label ( root , text = "<STR_LIT>" , font = "<STR_LIT>" ) <EOL> l1 . pack ( ) <EOL> l2 = Label ( root , text = "<STR_LIT>" ) <EOL> l2 . pack ( ) <EOL> s1 = Scale ( root , from_ = <NUM_LIT:0> , to = <NUM_LIT:100> , orient = HORIZONTAL , command = handle_slider ) <EOL> s1 . configure ( length = <NUM_LIT> ) <EOL> s1 . pack ( ) <EOL> cb1 = Checkbutton ( root , text = "<STR_LIT>" , state = DISABLED ) <EOL> cb1 . pack ( ) <EOL> f1 = Frame ( root , height = <NUM_LIT:3> , width = <NUM_LIT> ) <EOL> f1 . pack ( ) <EOL> f2 = Frame ( root , height = <NUM_LIT:1> , width = <NUM_LIT> , bg = "<STR_LIT>" ) <EOL> f2 . pack ( ) <EOL> f3 = Frame ( root , height = <NUM_LIT:3> , width = <NUM_LIT> ) <EOL> f3 . pack ( ) <EOL> l3 = Label ( root , text = "<STR_LIT>" , font = "<STR_LIT>" ) <EOL> l3 . pack ( ) <EOL> f4 = Frame ( root , width = <NUM_LIT> ) <EOL> f4 . pack ( ) <EOL> f4 . l1 = Label ( f4 , text = "<STR_LIT>" ) <EOL> f4 . l1 . pack ( side = LEFT ) <EOL> f4_cb1 = Checkbutton ( f4 , state = DISABLED ) <EOL> f4_cb1 . pack ( side = LEFT ) <EOL> l4 = Label ( root , text = "<STR_LIT>" ) <EOL> l4 . pack ( ) <EOL> t1 = Text ( root , height = <NUM_LIT:10> , width = <NUM_LIT> , borderwidth = <NUM_LIT:2> , relief = SUNKEN , state = DISABLED ) <EOL> t1 . pack ( ) <EOL> t1 . config ( state = NORMAL ) <EOL> t1 . insert ( END , "<STR_LIT>" ) <EOL> t1 . config ( state = DISABLED ) <EOL> b1 = Button ( root , text = "<STR_LIT>" , command = handle_exit_button ) <EOL> b1 . pack ( ) <EOL> my_send_timer ( ) <EOL> my_poll_timer ( ) <EOL> root . mainloop ( ) <EOL> try : <EOL> urllib3 . disable_warnings ( ) <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> if ( config . proxy_url == '<STR_LIT>' ) : <EOL> http = urllib3 . PoolManager ( ) <EOL> else : <EOL> http = urllib3 . proxy_from_url ( config . proxy_url ) <EOL> url = '<STR_LIT>' + config . hcp_account_id + config . hcp_landscape_host + '<STR_LIT>' + str ( config . device_id ) <EOL> headers = urllib3 . util . make_headers ( user_agent = None ) <EOL> headers [ '<STR_LIT>' ] = '<STR_LIT>' + config . oauth_credentials_for_device <EOL> headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> do_send = <NUM_LIT:0> <EOL> build_and_start_ui_with_timers ( ) </s>
