Esempio n. 1
0
    def __init__(self):
        #procControllerAddr = '165.227.24.226'  # I am client to HostController
        #procControllerPort = '5557'
        hostControllerPort = '5556' # I server to device

        print("Host Controller Starting\n")

        self.context = zmq.Context()   # get context
        self.loop = IOLoop.instance()

#       self.clientSetup = ClientSetup(context)  # instantiate the ClientSetup object
        self.serverSetup = ServerSetup(self.context) # instantiate the ServerSetup object


        # set up separate server and client sockets
        self.serverSocket = self.serverSetup.createServerSocket() # get a server socket
        self.serverSetup.serverBind(hostControllerPort, self.serverSocket) # bind to an address

#       self.clientSocket = self.clientSetup.createClientSocket() # get a client socket

# NOTE: setIdentity() MUST BE CALLED BEFORE clientConnect or the identity will
# not take effect
#       self.clientSetup.setIdentity(MasterId().getDevId()) # get the device id
#       self.clientSetup.clientConnect(hostControllerAddr, hostControllerPort, self.clientSocket) # connect to server using clientSocket
        self.serverSocket = ZMQStream(self.serverSocket)
        self.serverSocket.on_recv(self.onServerRecv)
        self.messages = Messages() # instantiate a Messages object

        self.inDict = {}
        self.outDict = {}
Esempio n. 2
0
    def __init__(self):
        deviceControllerAddr = 'localhost'

        deviceControllerPort = '5555'
        clientPort = ''

        print("Device Starting\n")

        self.context = zmq.Context()   # get context

        self.loop = IOLoop.instance()

        self.clientSetup = ClientSetup(self.context)  # instantiate the ClientSetup object
#serverSetup = ServerSetup(context) # instantiate the ServerSetup object

# set up separate server and client sockets

        self.clientSocket = self.clientSetup.createClientSocket() # get a client socket



        # NOTE: setIdentity() MUST BE CALLED BEFORE clientConnect or the identity will
        # not take effect
        self.clientSetup.setIdentity(MasterId().getDevId(), self.clientSocket) # get the device id

        self.clientSetup.clientConnect(deviceControllerAddr, deviceControllerPort, self.clientSocket) # connect to server using clientSocket

        self.clientSocket = ZMQStream(self.clientSocket)
        self.clientSocket.on_recv(self.onClientRecv)
        self.messages = Messages() # instantiate a Messages object
Esempio n. 3
0
    def __init__(self, mode, ip, port):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.msg = Messages()
        self.missing_packages = []
        self.keywords = ['setPyPy', 'pycross()']
        self.Pycross = []

        self.MainFile = None

        if mode:
            self.socket.connect((ip, port))
            self.send = self.__client_send
            self.recv = self.__client_recv

        else:
            self.socket.bind((ip, port))
            self.socket.listen(2)
            self.send = self.__server_send
            self.recv = self.__server_recv
            self.clinet = self.socket.accept()[0]

        self.msgToFunc = {
            "SF": self.sendFunc,
            "RF": self.readFunc,
            "RMF": self.readMainFile,
            "RP": self.readPackages,
            "SMF": self.sendMainFile,
            "SP": self.sendPackages,
            "RO": self.readOutput,
            "RE": self.readError,
            "end": None
        }
Esempio n. 4
0
def get_message(sid):
    messages = Messages()
    
    msg = messages.getMessage(app.config['TWILIO_ACCOUNT_SID'], 
        app.config['TWILIO_AUTH_TOKEN'], 
        sid)
    return json.dumps({"sid": msg.sid, "body": msg.body, "date_sent": msg.date_sent, "from": msg.from_})
Esempio n. 5
0
def vs_locus(input):
    msg = Messages()
    #msg.info("Welcome to vs_locus (version {})".format(vs.__version__))
    msg.info("Welcome to vs_locus!")
    cluster_summary = ClusterSummary()
    cluster_summary.load_table(input)
    cluster_summary.add_centroids()
    cluster_summary.add_hits()
    pass
Esempio n. 6
0
def get_message_sid_list():
    messages = Messages()
    messages=messages.list(app.config['TWILIO_ACCOUNT_SID'], app.config['TWILIO_AUTH_TOKEN'])
    message_sid_list = []
    for message in messages:
        if message.direction == 'inbound':
            message_sid_list.append(message.sid)
    
    return json.dumps(message_sid_list)
Esempio n. 7
0
def get_messages():
    messages = Messages()
    messages=messages.list(app.config['TWILIO_ACCOUNT_SID'], app.config['TWILIO_AUTH_TOKEN'])
    ret_message = []
    for msg in messages:
        if msg.direction == 'inbound':
            ret_message.append({"sid": msg.sid, "body": msg.body, "date_sent": str(msg.date_sent), "from": msg.from_})
    
    return json.dumps(ret_message)
Esempio n. 8
0
    def initialize(self):
        self.msg = Messages(self)
        self.patterns = []
        self.pattern = None
        self.currentDatFile = None

        self.initConfig()
        self.initializeUtilities()

        self.gui = Gui()
        self.gui.initializeMainWindow(self)
        self.updatePatternCanvasLastSize()
        self.patternListBox.bind('<<ListboxSelect>>', self.patternSelected)
        self.after_idle(self.canvasConfigured)
        self.deviceEntry.entryText.set(self.getConfig().device)
        self.datFileEntry.entryText.set(self.getConfig().datFile)

        self.initEmulator()
        self.after_idle(self.reloadPatternFile)
Esempio n. 9
0
    def start(self, event):

        self.send_presence()
        self.get_roster()
        self.send_message(mto=self.recipient, mbody="connect", mtype='chat')

        from Rss import Feeds
        from time import sleep
        from Messages import Messages
        i = 0
        while True:
            i = i + 1
            sleep(15)
            feed = Feeds().feedaki()
            #self.msg = "publish:face3 "+feed
            self.msg = "publish:face3 I am on my " + str(i) + "  cycle!"
            self.send_message(
                mto=self.recipient,
                #mbody=self.msg,
                mbody=Messages().choose_message(),
                mtype='chat')
        # Using wait=True ensures that the send queue will be
        # emptied before ending the session.
        self.disconnect(wait=True)
Esempio n. 10
0
def dump():
    messages = Messages()
    return render_template('dump.html', 
    messages=messages.list(app.config['TWILIO_ACCOUNT_SID'], 
    app.config['TWILIO_AUTH_TOKEN']))
Esempio n. 11
0
#import time
import random
import math
from NewSnake import NewSnake
from CheckDirections import CheckDirections
from Messages import Messages

pygame.init()
white = (255, 255, 255)
red = (255, 0, 0)
green = (0, 155, 0)

check = CheckDirections()
mySnake = NewSnake()

message = Messages()

display_width = 1056
display_height = 600
gameDisplay = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('Snake')

background = pygame.image.load("Snake-Game-py/src/Background.png")
snakSheet = pygame.image.load("Snake-Game-py/src/snakeImage.png")

AppleSprite = snakSheet.subsurface(pygame.Rect((0, 3 * 64, 64, 64)))

gameDisplay.blit(background, (0, 0))

clock = pygame.time.Clock()
Esempio n. 12
0
def main():
    '''
    main entry point into the script
    '''

    # store the start time
    # used for duration stats later
    start_time = datetime.now()

    global environment_options
    global messages
    environment_options = EnvironmentOptions()
    environment_options.get_options()
    messages = Messages().prefixes

    if environment_options.debug:
        print(f'{environment_options}\n')

    print(f'{messages.info} Evaluation script started at {pretty_time()}.')

    print(f'{messages.info} Checking environment.')
    # check the environment, first
    environment_options.check_environment(messages)
    print(f'{messages.ok} Environment OK.')

    # verify the specified blueprint directory exists
    if os.path.exists(environment_options.directory):
        print(f'{messages.info} Blueprint directory found.  Continuing.')
    else:
        print(f'{messages.error} Blueprint directory not found.  Exiting.')
        sys.exit()

    # verify the specified criteria file exists
    if os.path.exists(f'{environment_options.criteria}'):
        print(f'{messages.info} Evaluation criteria file found.  Continuing.')
        # validate the specified criteria as valid JSON
        try:
            with open(f'{environment_options.criteria}', 'r') as criteria_file:
                json.loads(criteria_file.read())
                print(f'{messages.info} Criteria file ' +
                      f'{environment_options.criteria} successfully parsed ' +
                      'as JSON.  Continuing.')
                criteria_file.close()
        except json.decoder.JSONDecodeError as e:
            print(
                f'{messages.error} The {environment_options.criteria} JSON ' +
                'file could not be parsed.  Is it valid JSON?')
            if environment_options.debug:
                print(f'{messages.error} Exception details: {e}')

    else:
        print(f'{messages.error} Evaluation criteria file not found.  ' +
              'Exiting.')
        sys.exit()

    # keep track of how many blueprints have been processed
    processed_ok = 0
    '''
    check to see if the user has indicated they want to parse all blueprints
    in the specified blueprint directory
    '''
    if environment_options.blueprint.lower() == 'all':
        print(f'{messages.info} All blueprints in ' +
              f'{environment_options.directory} ' + 'will be processed.')
        bp_list = glob.iglob(f'{environment_options.directory}/*.json')
        for bp in bp_list:
            process_json(bp)
            processed_ok += 1
    else:
        print(f'{messages.info} Only {environment_options.blueprint} in ' +
              f'{environment_options.directory} will be processed.')
        process_json(f'{environment_options.directory}/' +
                     f'{environment_options.blueprint}')
        processed_ok += 1

    # store the finish time
    finish_time = datetime.now()

    # calculate how long the script took to run
    duration = finish_time - start_time

    # clean up
    print(f'{messages.line}')
    print(f'{messages.info} Cleaning up.')
    print(f'{messages.info} Processed {processed_ok} blueprints.')
    print(f'{messages.info} Evaluation completed in ' +
          f'{humanize.precisedelta(duration, minimum_unit="seconds")}.')
    print(f'{messages.info} Evaluation script finished at {pretty_time()}.\n')
Esempio n. 13
0
    def __init__(self, nick, addr, port):

        self.width, self.height = 750, 500
        self.card_w, self.card_h = 43, 62

        # initialize pygame
        pygame.init()
        # 2
        # initialize the screen
        self.screen = pygame.display.set_mode((self.width, self.height))
        pygame.display.set_caption('Poker')
        # 3
        # initialize pygame clock
        self.clock = pygame.time.Clock()

        self.nick_color, self.money_color, self.text_color = (150, 150,
                                                              150), (255, 255,
                                                                     0), (50,
                                                                          50,
                                                                          50)
        self.bg_color = (220, 220, 220)

        self.is_turn = False
        self.is_playing = True
        self.is_waiting_to_start = True
        self.player_id = None
        self.is_out = False

        self.pot_val = None

        self.money = None
        self.big_blind = self.small_blind = None
        self.id_big_blind = self.id_small_blind = None

        self.card1 = self.card2 = None

        self.back_card = pygame.image.load(f'images/back.png')
        self.table_img = pygame.image.load('images/table.png')
        self.table_img_x, self.table_img_y = self.width // 2 - 700 // 2, 20

        # self.font = pygame.font.Font('freesansbold.ttf', 16)
        self.font = pygame.font.SysFont('Arial', 16, bold=True)
        self.text_font = pygame.font.SysFont('Arial', 12)
        self.nick = nick

        self.error_font = pygame.font.Font('freesansbold.ttf', 12)
        self.error_raise_msg = self.error_font.render('INVALID VALUE', True,
                                                      (255, 0, 0),
                                                      (255, 255, 255))
        self.error_time = 0

        # other players
        self.is_opp_out = defaultdict(
            bool)  # True when out of money, default to False
        self.opp_cards_img = {}
        self.is_opp_playing = {}
        self.id_turn = None
        self.opp_bet = {}
        self.players_nick = {}
        self.opp_ids = []
        self.opp_money = {}
        self.players_pos = [(self.width * 0.75 // 5, self.height * 3.1 // 5),
                            (self.width * 0.75 // 5, self.height * 1.7 // 5),
                            (self.width // 2, 75),
                            (self.width * 4.25 // 5, self.height * 1.7 // 5),
                            (self.width * 4.25 // 5, self.height * 3.1 // 5)]

        # cards on the table
        self.on_table = [None] * 5

        self.bet = 0
        self.bet_on_table = 0

        self.fold_b = Button('fold', (self.width - 270, self.height - 20),
                             self.screen)
        self.check_b = Button('check', (self.width - 180, self.height - 20),
                              self.screen)
        self.raise_b = Button('raise to', (self.width - 90, self.height - 20),
                              self.screen)
        self.raise_t = TextField((self.width - 90, self.height - 50),
                                 self.screen)

        # self.mess = Messages((0, self.height-115), self.screen)
        self.mess = Messages((5, 5), self.screen)
        self.actions_mess = Messages((5, self.height - 35),
                                     self.screen,
                                     size=(275, 25))

        self.Connect((addr, int(port)))
Esempio n. 14
0
# testMessages.py
from Messages import Messages
from Messages import devType

# create a brand new message from an orignating node
# pass my devType, cmd, and an empty return list.  This Message
# is a "hiya" message

aNewMessage = Messages().createMessageDict(devType(), '00', [])
print("A new message =", aNewMessage)

outBuf = Messages().createOutMessage(aNewMessage)
print("The buffer to be sent (json)=", outBuf)

# now pretend I got a buffer from zmq, I'll use outBuf in this case
# I want to create a message dictionary

inDict = Messages().bufferToDict(outBuf)
# print the new inDict

print("\n")
print("Now I'm the next guy, I got a buffer, I converted to a dict:", inDict)

# now I want to append my id to the end and create a buffer
# that I can send

newOutDict = Messages().appendMyIdToReturnList(inDict)
print("newOutDict with my id appended =", newOutDict)

newOutBuf = Messages().createOutMessage(newOutDict)
print("newOutBuf with my id appended", newOutBuf)
Esempio n. 15
0
def get_archive():
    messages = Messages()
    return render_template('archive.html', messages=messages.list(app.config['TWILIO_ACCOUNT_SID'], app.config['TWILIO_AUTH_TOKEN']))    
Esempio n. 16
0
def display_sweetboard():
    messages = Messages()
    return render_template('index.html', messages=messages.list(app.config['TWILIO_ACCOUNT_SID'], app.config['TWILIO_AUTH_TOKEN']))    
Esempio n. 17
0
from __future__ import print_function
'''
Cluster: A class to hold information and methods associated with a unique cluster
Sequence: A class to hold information and methods associated with each hit to a cluster
'''

import pandas as pd
from Messages import Messages

msg = Messages()

class ClusterSummary:
    def __init__(self):
        self.clusters = {}
    def load_table(self, filename):
        msg.info("Loading {}...".format(filename))
        try:
            header_names = ['type', 'cluster_number', 'length', 'percent', 'orientation', 'skip1', 'skip2', 'cigar', 'seq_label', 'centroid_label']
            self.tab = pd.read_table(filename, header = None, names = header_names)
            msg.success('Finished loading table from {}.'.format(filename))
            msg.info('Loaded {} lines.'.format( self.tab.shape[0]))
        except:
            msg.fail('Could not load {}'.format(filename))
            raise IOError
    def add_centroids(self):
        self.tab_centroids = self.tab[self.tab.type == 'C']
        self.loci = {}
        for row in self.tab_centroids.itertuples():
            self.loci[row.seq_label] = {}
            self.loci[row.seq_label]['size'] = row.length
            self.loci[row.seq_label]['id'] = row.cluster_number
Esempio n. 18
0
    def __init__(self):
        Gtk.Window.__init__(self, title="Magic Mirror")

        self.state_list = [
            "HOME", "WEATHER", "TIME", "QUOTE", "CALENDAR", "HELP", "INFO",
            "MIRROR"
        ]
        self.state = ""

        # Data classes which update from subscriber
        input_data = InputData()
        weather_data = WeatherData()
        quote_data = QuoteData()
        calendar_data = EventData()
        message_data = MessageData()
        home_data = HomeData()
        self.auth_data = AuthData()
        pin_data = PinData()

        # Screen objects that are cycled in the window
        self.home_screen = Home(weather_data, calendar_data, home_data,
                                self.auth_data)
        self.auth_screen = Auth(self.auth_data, pin_data)
        self.weather_screen = Weather(weather_data)
        self.time_screen = TimeDate()
        self.message_screen = Messages(message_data)
        self.quote_screen = Quote(quote_data)
        self.calendar_screen = Calendar(calendar_data)
        self.help_screen = Help()
        self.info_screen = Info()
        self.mirror_screen = Mirror()

        # Starts the MQTT subscriber
        self.data_thread = threading.Thread(target=subscriber.run,
                                            args=([
                                                input_data, weather_data,
                                                quote_data, calendar_data,
                                                home_data, self.auth_data,
                                                pin_data
                                            ], ))
        self.data_thread.daemon = True
        self.data_thread.start()

        # Updates the value on the screens in separate threads
        GObject.timeout_add(1000, self.auth_screen.update)
        GObject.timeout_add(1000, self.weather_screen.update_weather)
        GObject.timeout_add(1000, self.time_screen.update_clock)
        GObject.timeout_add(1000, self.quote_screen.update)
        GObject.timeout_add(1000, self.calendar_screen.update_events)
        GObject.timeout_add(1000, self.message_screen.update_screen)
        GObject.timeout_add(1000, self.home_screen.update_home)

        self.app_stack = Gtk.Stack()
        self.app_stack.set_transition_type(
            Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
        self.app_stack.set_transition_duration(500)

        self.app_stack.add_named(self.auth_screen, "Auth")
        self.app_stack.add_named(self.home_screen, "Home")
        self.app_stack.add_named(self.weather_screen, "Weather")
        self.app_stack.add_named(self.time_screen, "Time")
        self.app_stack.add_named(self.message_screen, "Message")
        self.app_stack.add_named(self.quote_screen, "Quote")
        self.app_stack.add_named(self.calendar_screen, "Calendar")
        self.app_stack.add_named(self.help_screen, "Help")
        self.app_stack.add_named(self.info_screen, "Info")
        self.app_stack.add_named(self.mirror_screen, "Mirror")

        # Meant to add the default screen
        self.add(self.app_stack)

        self.fullscreen()
        self.modify_bg(Gtk.StateType.NORMAL, Gdk.Color(255, 0, 255))
        self.set_icon(IMG.iconpix)