Beispiel #1
0
 def __init__(self, serialized=None):
     self.data_high_gain = np.array((0, 2), dtype=np.complex)
     self.data_low_gain = np.array((0, 2), dtype=np.complex)
     self.gain = np.array((0, 2), dtype=np.complex)
     self.clock_base = None
     self.filter_cutoff = None
     self.filter_order = None
     self.drive_voltage = None
     Message.__init__(self, serialized)
Beispiel #2
0
	def build_msg(self, msg_id):
		"""
		return a msg obj of msg_id
		"""
		if msg_id == constant.MESSAGE_TYPE.MSG_STRING.value:
			return Message.MessageString()
		if msg_id == constant.MESSAGE_TYPE.MSG_INT.value:
			return Message.MessageInt()
		if msg_id == constant.MESSAGE_TYPE.MSG_DOUBLE.value:
			return Message.MessageDouble()
Beispiel #3
0
def classify_api():
    try:
        ret = verify_request_parameters()
        if ret.code != '200': return ret.to_json()
        args = flask.request.args
        start = datetime.now()
        ret.res = do_image_recognition()
        end = datetime.now()
        duration = end - start
        logger.info('Total time cost: {}s'.format(duration.total_seconds()))
    except Exception as err:
        logger.error(str(err))
        ret = Message('500', str(err))
    return ret.to_json()
def sender(messenger, message, receivers_carriers):
    # SMS get Spam filtered for any mention of IKEA, Notification or Store
    sms = Message(subject="Update Text/Test", email=email, password=password) if email and password else None

    for receiver, carrier in receivers_carriers:
        if carrier in {'gmail'} and messenger:
            messenger.send(to_recv=receiver, carrier=carrier, message=message)
        elif sms:
            sms.send(to_recv=receiver, carrier=carrier, message=message)
        
    # For Desktop notifications   
    if notification_flag:
        message = message.split('\n')
        for msg in message:
            notification.notify(title='IKEA Stores Notification!', message=msg, app_icon='./bell.ico', timeout=30)
Beispiel #5
0
 def test_jsonify(self):
     msg = Message(id="1",
                   chat_id="123",
                   chat_type=ChatType.GROUP,
                   author=User(id="123",
                               username="******",
                               display_name="yelsh",
                               is_bot=False),
                   sent=datetime.datetime(2011, 11, 4, 0, 0),
                   text="test")
     s = encode_json(msg)
     # noinspection PyTypeChecker
     unloaded = json.load(StringIO(s))
     expected_as_dict = {
         '__type__': 'Message',
         'id': '1',
         'chat_id': '123',
         'chat_type': 1,
         'author': {
             '__type__': 'User',
             'id': '123',
             'username': '******',
             'display_name': 'yelsh',
             'is_bot': False
         },
         'sent': '2011-11-04T00:00:00',
         'text': 'test'
     }
     self.assertEqual(unloaded, expected_as_dict)
Beispiel #6
0
def sender(messenger, message, receivers_carriers):
    # SMSs get Spam filtered for any mention of IKEA, Notification or Store with tmobile carries for some reason.
    sms = Message(subject="Update Text/Test", email=email, password=password)

    for receiver, carrier in receivers_carriers:
        if carrier in {'gmail'}:
            messenger.send(to_recv=receiver, carrier=carrier, message=message)
            continue
        sms.send(to_recv=receiver, carrier=carrier, message=message)

    # For Desktop notifications
    if notification_flag:
        notification.notify(title='IKEA Stores Notification!',
                            message=message,
                            app_icon='./bell.ico',
                            timeout=30)
Beispiel #7
0
def verify_request_parameters():
    ret = Message('200', 'OK')
    # basic parameters verification
    args = flask.request.args
    req_types = args.get('types')
    req_language = args.get('language')
    req_url = args.get('url')
    req_roi = args.get('roi')
    req_max_lbs = args.get('max_labels')
    req_threshold = args.get('threshold')
    # image verification
    if not req_url:
        imagefile = flask.request.files['imagefile']
        if not imagefile:
            ret.code = '420'
            ret.msg = 'The requested resource does not support one or more of the given parameters.'
            return ret
    return ret
Beispiel #8
0
def broadcast(message, prefix=""):
    """
    Simply sends message to every client
    :param message:
    :param prefix:
    :return:
    """
    mess = Message(message, prefix)
    sended_messages.append(mess)
    for sock in clients:
        sock.send(bytes(prefix + ": ", "utf8") + message)
Beispiel #9
0
    def __init__(self):
        self.crc = Crc()

        self.can1 = CanInterface(1)
        #self.can2 = CanInterface(2)

        # allocate message buffer
        self.messages_max = 25
        self.messages_size_max = 128
        self.messages = []
        for i in range(self.messages_max):
            self.messages.append(Message(self.crc, self.messages_size_max))
        self.message_count = 0
Beispiel #10
0
    def __init__(self, robo):
        self.robo = robo
        self.buf = RingBuffer(2048)
        self.crc = Crc()
        self.proc = Processor()

        # load template messages
        self.messages_size_max = 128 
        self.messages = []
        self.message_count = 0

        with open('command_list.csv','r') as file:
            header = 0
            row = 0 # translates into message nbr
            for line in file:
                if header == 0:
                    header = 1 # ignore
                else:
                    line = line.rstrip('\n').rstrip('\r')
                    self.messages.append(Message(self.crc, self.messages_size_max))
                    self.messages[row].mode = 1 # overwrite crc
                            
                    col = 0 
                    for val in line.split(','):
                        if col == 1:
                            self.messages[row].boot = int(val)
                        elif col == 2:
                            self.messages[row].freq = int(val)
                        elif col > 2 and val != '0':
                            self.messages[row].put(int(val, 16))
                        col += 1
                    row += 1
            self.message_count = row

        # allocate byte arrays for frame buffer
        self.data = []
        for i in range(9):
            self.data.append(bytearray(i))

        # allocate frames with references to the byte arrays
        self.frame = []
        for i in range(9):
            self.frame.append([0x201, 0, 0, memoryview(self.data[i])])

        self.add(self.messages[11]) #LED ON
Beispiel #11
0
    async def process(self, websocket, path):
        # initial connection
        msg_string = await websocket.recv()
        new_msg_string, game_id = self.process_message(msg_string, websocket)
        await websocket.send(new_msg_string)

        # wait for both player to be connected
        while not self.ready[game_id]:
            await asyncio.sleep(1)

        # initial game state
        player_name = self.get_player_name_by_websocket(websocket, game_id)
        game_state = self.ganager.get_game_state(game_id, player_name)

        new_msg = Message('state', game_state, game_id)

        new_msg_string = new_msg.to_json()
        await websocket.send(new_msg_string)

        # communication
        self.first_round[game_id] = True
        while not self.ganager.is_game_over(game_id):
            msg_string = await websocket.recv()
            new_msgs_strings, game_id = self.process_message(
                msg_string, websocket)

            for i, websock in enumerate(self.websockets[game_id]):
                await websock.send(new_msgs_strings[i])

                if not self.first_round[game_id]:
                    if not self.ganager.is_game_over(game_id):
                        player_name = None
                        wrong_player = self.get_player_name_by_websocket(
                            websocket, game_id)
                        if self.players[game_id][0] == wrong_player:
                            player_name = self.players[game_id][1]
                        elif self.players[game_id][1] == wrong_player:
                            player_name = self.players[game_id][0]

                        if i == 0:
                            self.ganager.material_update(game_id, player_name)

                        game_state = self.ganager.get_game_state(
                            game_id, player_name)
                        new_msg = Message('material_update', game_state,
                                          game_id)
                        new_msg_string = new_msg.to_json()
                        await websock.send(new_msg_string)

            self.first_round[game_id] = False
Beispiel #12
0
 def run(self):
     for i in range(amount):
         sentence = fake.sentence(nb_words=5, variable_nb_words=True, ext_word_list=None)
         receiver = users[randint(0, amount - 1)]
         print(f"Message {sentence} was sent to {receiver}");
         Message.create_message(self.user_id, sentence, receiver)
from msg import Message
from collections import defaultdict
import requests
import time

# DO NOT COMMIT FILES WITH CREDENTIALS
email = 'EMAIL'
password = '******'
numbers_carriers = [('0000000000 or 000-000-0000', 'carrier')]

var = "PLZ WORK"
test = Message(subject="Update Text/Test", email=email, password=password)
msg = "Wubba Lubba Dub Dub\n"
for _ in range(5):
    msg += f'Wubba Lubba Dub Dub {var}\n'

ikea_stores = defaultdict(bool)
r = requests.get('https://ikea-status.dong.st/latest.json')
for store in r.json():
    if store['last_open'] and store['last_open'] > store['last_closed']:
        ikea_stores[(store['country'], store['state'], store['name'])] = True

msg += f'First notification from script about IKEA store availability ran at {time.strftime("%d-%b-%Y %H:%M:%S", time.localtime())} Local Time.\n'
for country, state, name in ikea_stores.keys():
    msg += f'{country}, {state}, {name} - OPEN\n'

for number, carrier in numbers_carriers:
    test.send(to_recv=number, carrier=carrier, message=msg)

print('OK')
Beispiel #14
0
    if notification_flag:
        notification.notify(title='IKEA Stores Notification!',
                            message=message,
                            app_icon='./bell.ico',
                            timeout=30)


# DO NOT COMMIT FILES WITH CREDENTIALS. Modify variables below as necessary.
email = 'EMAIL'
password = '******'
notification_flag = True
receivers_carriers = [('000-000-0000', 'carrier'), ('0000000000', 'carrier'),
                      ('email-ID', 'carrier')]

stores_open = Message(subject="IKEA STORES OPEN!",
                      email=email,
                      password=password)
stores_closed = Message(subject="IKEA STORES CLOSED!",
                        email=email,
                        password=password)

ikea_stores = defaultdict(bool)
r = requests.get('https://ikea-status.dong.st/latest.json')
for store in r.json():
    if store['last_open'] and store['last_open'] > store['last_closed']:
        ikea_stores[(store['country'], store['state'], store['name'])] = True

stores_open_msg = f'First notification from script about IKEA Stores availability ran at {time.strftime("%d-%b-%Y %H:%M:%S", time.localtime())} Local Time.\n'
for country, state, name in ikea_stores.keys():
    stores_open_msg += f'{country}, {state}, {name}: OPEN\n'
Beispiel #15
0
 def __init__(self, serialized=None):
     self.motor_position = float()
     Message.__init__(self, serialized)
Beispiel #16
0
    def process_message(self, msg_string, websocket):
        msg = Message()
        msg.from_json(msg_string)

        if msg.get_msg_name() == 'create_game':
            game_id = self.ganager.create_new_game(player=msg.content)
            self.websockets[game_id] = [websocket]
            self.players[game_id] = [msg.content]
            self.ready[game_id] = False
            new_msg = Message('game_id', game_id, game_id)
            return new_msg.to_json(), game_id

        if msg.get_msg_name() == 'join_game':
            self.ganager.join_game(game_id=msg.game_id,
                                   player_name=msg.content)
            self.websockets[msg.game_id].append(websocket)
            self.players[msg.game_id].append(msg.content)
            self.ready[msg.game_id] = True
            new_msg = Message('game_id', msg.game_id, msg.game_id)
            return new_msg.to_json(), msg.game_id

        if msg.get_msg_name() == 'action':
            player_name = self.get_player_name_by_websocket(
                websocket, msg.game_id)
            end = self.ganager.play_card(game_id=msg.game_id,
                                         player_name=player_name,
                                         card_idx=msg.content)
            messages = []
            if not end:
                for _, player_name in enumerate(self.players[msg.game_id]):
                    game_state = self.ganager.get_game_state(
                        msg.game_id, player_name)
                    new_msg = Message('state', game_state, msg.game_id)
                    new_msg_str = new_msg.to_json()
                    messages.append(new_msg_str)
            else:
                for _, player_name in enumerate(self.players[msg.game_id]):
                    game_state = self.ganager.get_game_state(
                        msg.game_id, player_name)
                    game_state['game_status'] = end
                    new_msg = Message('end', game_state, msg.game_id)
                    new_msg_str = new_msg.to_json()
                    messages.append(new_msg_str)

            return messages, msg.game_id

        if msg.get_msg_name() == 'throw_away':
            player_name = self.get_player_name_by_websocket(
                websocket, msg.game_id)
            self.ganager.throw_away_card(game_id=msg.game_id,
                                         player_name=player_name,
                                         card_idx=msg.content)
            messages = []
            for _, player_name in enumerate(self.players[msg.game_id]):
                game_state = self.ganager.get_game_state(
                    msg.game_id, player_name)
                new_msg = Message('state', game_state, msg.game_id)
                new_msg_str = new_msg.to_json()
                messages.append(new_msg_str)
            return messages, msg.game_id
            sms.send(to_recv=receiver, carrier=carrier, message=message)
        
    # For Desktop notifications   
    if notification_flag:
        message = message.split('\n')
        for msg in message:
            notification.notify(title='IKEA Stores Notification!', message=msg, app_icon='./bell.ico', timeout=30)

# DO NOT COMMIT FILES WITH CREDENTIALS. Modify variables below as necessary.
email = 'EMAIL'
password = '******'
notification_flag = True
# receivers_carriers = [('000-000-0000', 'carrier'), ('0000000000', 'carrier'), ('email-ID', 'carrier')]
receivers_carriers = []

stores_open = Message(subject="IKEA STORES OPEN!", email=email, password=password) if email and password else None
stores_closed = Message(subject="IKEA STORES CLOSED!", email=email, password=password) if email and password else None

ikea_stores = defaultdict(bool)
r = requests.get('https://api.ikea-status.dong.st/prod/locations')
for store in r.json()['locations']:
    if store['status'] == 'open':
        ikea_stores[(store['countryCode'], store['subdivisionCode'], store['locationName'])] = True

stores_open_msg = f'First notification from script about IKEA Stores availability ran at {time.strftime("%d-%b-%Y %H:%M:%S", time.localtime())} Local Time.\n'
for countryCode, subdivisionCode, locationName in ikea_stores.keys():
    stores_open_msg += f'{countryCode}, {subdivisionCode}, {locationName}: OPEN\n'

sender(stores_open, stores_open_msg, receivers_carriers)

while True: