示例#1
0
    def interpritMessage(self, client, userdata, message):
        """Interprets MQTT message and handles creating/joining of threads"""
        try:
            msg = json.loads(message.payload)['message']
        except ValueError:
            print('MISSING DELIMITER IN JSON')
            return

        if 'args' in message.payload:
            try:
                args = json.loads(message.payload)['args']
            except ValueError:
                print('MISSING DELIMITER IN JSON')
        else:
            args = ''

        print('Message received: \"{}\" from topic {}'.format(
            msg, message.topic))

        if self.thread.isAlive():
            print('JOINING THREAD')
            self.thread.should_stop = True
            self.thread.join()

        if 'clock' in msg:
            clock_attrs = ClockAttributes(args)

            self.thread = ClockThread(
                3, clock_attrs.unit, clock_attrs.zip_code, clock_attrs.region,
                clock_attrs.temp_color, clock_attrs.day_color,
                clock_attrs.date_color, clock_attrs.hour_color,
                clock_attrs.minute_color)

            self.thread.should_stop = False
            self.thread.start()
        if 'image' in msg:
            cvs = Module.image_canvas_from_url(args)

            if cvs.has_data():
                self.send_message(True, 'successfully downloaded image')
            else:
                self.send_message(False, 'failed to download image')

            self.thread = CanvasThread(cvs)
            self.thread.start()

        if 'gif' in msg:
            args = './gifs/' + args + '.gif'

            anim = Module.gif_anim(args)

            if len(anim) > 1:
                self.send_message(True, 'successfully compiled gif')
            else:
                self.send_message(False, 'failed to compile gif')

            self.thread = AnimationThread(anim)
            self.thread.should_stop = False
            self.thread.start()
示例#2
0
 def undo(self, mod: modules.Module):
     props = mod.get_exposed_props()
     if self.before and self.before.keys() == props.keys() \
             and props() == self.after:
         mod.set_exposed_props(self.before)
         return mod
     else:
         print("tried to undo, but the target props are", self.before,
               "while the current are", props)
         return None
示例#3
0
 def do(self, mod: modules.Module, pos: base.Vec2d) -> modules.Module:
     self.pos = pos
     self.before = mod_props = mod.get_exposed_props()
     for name, change in self.changes.items():
         if name in mod_props and self.type_test(change):
             mod_props[name] = change
         else:
             return mod
     self.after = mod_props
     mod.set_exposed_props(mod_props)
     return mod
示例#4
0
def open_modules():
    """ Function that will load all modules """
    dirs = os.listdir(path + "modules/")
    modules = {}
    for dir in dirs:
        modules[dir] = Module(dir, path)
    return modules
示例#5
0
def test_gif(gif_path):
    anim = Module.gif_anim(gif_path)

    matrix = EzMatrix()

    while True:
        matrix.run_anim(anim)
示例#6
0
def test_img(image_path):
    cvs = Module.image_canvas_from_path(image_path)

    matrix = EzMatrix()

    while True:
        matrix.draw_canvas(cvs)
示例#7
0
    def run(self):
        temp_cvs = Module.temperature_canvas(self.unit, self.zip_code,
                                             self.temp_color)

        tme = int(time.time())

        while not self.should_stop:
            if int(time.time()) - tme == self.ref_rate:
                temp_cvs = Module.temperature_canvas(self.unit, self.zip_code,
                                                     self.temp_color)
                tme = int(time.time())

            time_cvs = Canvas(25, 19).add_subcanvas(
                Module.time_canvas(self.region, self.day_color,
                                   self.date_color, self.hour_color,
                                   self.hour_color, self.minute_color),
                Point(0, 6))

            time_cvs.add_subcanvas(temp_cvs, Point(9, 0))

            matrix.draw_canvas(Canvas().add_subcanvas(time_cvs, Point(3, 6)))
示例#8
0
def draw_dashboard(ref_rate=3):  # includes clock and temperature
    """ ref_rate is the interval (in minutes) between weather API calls """
    temp_cvs = Module.temperature_canvas('f', '94103', Color.green())

    ref_rate = ref_rate * 60

    tme = int(time.time())

    matrix = EzMatrix()

    while True:
        if int(time.time()) - tme == ref_rate:
            temp_cvs = Module.temperature_canvas('f', '94103', Color.green())
            tme = int(time.time())

        time_cvs = Canvas(25,
                          19).add_subcanvas(Module.time_canvas('US/Pacific'),
                                            Point(0, 6))

        time_cvs.add_subcanvas(temp_cvs, Point(9, 0))

        matrix.draw_canvas(Canvas().add_subcanvas(time_cvs, Point(3, 6)))
示例#9
0
 def lipo(self, platform, *frameworks):
     merged = super(FrameworkModule, self).lipo(platform, *frameworks)
     framework_module = FrameworkModule(Module(
         merged.name,
         merged.library_path,
         glob('{}/Headers/*.h'.format(merged.framework_path)),
         self.module.umbrella_header,
         self.module.submodules  
     ))
     framework_module.framework_path = 'Frameworks/{}/{}.framework'.format(
             platform.name, self.name)
     framework_module.is_created = True
     framework_module.abs_path = os.path.abspath(merged.framework_path)
     return framework_module
示例#10
0
def dice(d, file):
    """Output a Tracery module simulating a given dice roll using NdS notation."""
    n, s = d.split('d')
    n = int(n)
    s = int(s)
    possibility_space = itertools.product([i+1 for i in range(s)], repeat=n)
    possibility_space = [sum(x) for x in possibility_space]

    virtual_name = 'dice({0})'.format(d)

    return Module(
        name=virtual_name,
        file_path='!dice({0})'.format(d),
        productions={
            virtual_name: ['{0}'.format(x) for x in possibility_space]
        },
        external=True,
        variables=set(),
        links=set()
    )
示例#11
0
文件: choose.py 项目: moriartyb/ppbot
 def __init__(self, *args, **kwargs):
     """Constructor"""
     Module.__init__(self, kwargs=kwargs)
示例#12
0
 def __init__(self, parser):
     Module.__init__(self, parser, self.name)
     self.hook_on = clang.cindex.CursorKind.CALL_EXPR
示例#13
0
 def __init__(self, parser):
     Module.__init__(self, parser, self.name)
     self.hook_on = clang.cindex.CursorKind.CALL_EXPR
示例#14
0
    if manufacturer is None:
        return [
            i['inverter'] for i in json.loads(open(SPATH + '/si.json').read())
        ]
    else:
        a = []
        for i in json.loads(open(SPATH + '/si.json').read()):
            if i['inverter'].find(manufacturer) != -1:
                a.append(i['inverter'])
        return a


if __name__ == "__main__":
    from modules import Module, Array

    PANEL = Module('Mage Solar : Powertec Plus 245-6 PL *')
    INVERTER = Inverter("Enphase Energy: M215-60-SIE-S2x 240V",
                        Array(PANEL, [{
                            'series': 1
                        }]))
    print INVERTER.array
    print ""
    print INVERTER.dump()
    # si = sb6000us(s)

    print INVERTER.p_ac(950)
    print INVERTER.i_ac(960, 240)

    INVERTER = Inverter("SMA America: SB7000US-11 277V",
                        Array(PANEL, [{
                            'series': 11,
示例#15
0
def postag(sentence):
    return Module.extract_agents(sentence)
示例#16
0
def clock():  # does not include temperature
    matrix = EzMatrix()

    while True:
        matrix.draw_canvas(Canvas().add_subcanvas(
            Module.time_canvas('US/Pacific'), Point(3, 9)))
示例#17
0
文件: choose.py 项目: fourk/ppbot
 def __init__(self, *args, **kwargs):
     """Constructor"""
     Module.__init__(self, kwargs=kwargs)
示例#18
0
 def p_newMod(p):
     'modName : MODULE NAME'
     nonlocal curentMod
     curentMod = Module(p[2])