Esempio n. 1
0
 def test_add_method_should_append_notification_to_list_and_return_uuid(
         self, uuid4):
     result = Notifications.add('warning', 'No title', 'No text')
     self.assertEqual(result, 'in-test')
     expected_list = self.notifications[:]
     expected_list.append({
         'uuid': 'in-test',
         'type': 'warning',
         'title': 'No title',
         'text': 'No text'
     })
     self.assertEqual(Notifications.list(), expected_list)
def run(store, conn, cursor):
    url = 'http://www.energo-pro.ge/category/electricity-suspensions/'

    # Reset stored values if needed / restore blinking after restart
    if is_notification_shown():
        store.delete(BLINKING_STORE_KEY)
        if gateway_led.is_blocked():
            gateway_led.unblock()
    else:
        Thread(target=blink, args=(store, )).start()
        store.set(BLINKING_STORE_KEY, 1)

    while True:
        try:
            page = pq(url)
        except:  # it will be a connection error or something like that anyway
            sleep(10)
            continue
        if AREA in str(page).lower():
            for el in page('.susp-table .bwm-post.post').items():
                region, location, customers, date, time_from, time_to = [
                    el('div').eq(i).text() for i in range(6)
                ]

                if AREA in region.lower() or AREA in location.lower():
                    if not add_to_parsed(store, el.text()):
                        continue
                    text = '<b>Location</b>: {}, {}<br/><b>When</b>: {}, from {} to {}<br/>'.format(
                        region, location, date, time_from, time_to)
                    if not is_notification_exists(text):
                        Notifications.add('error', NOTIFICATION_TITLE, text)
                        gateway_speaker.play(10008, 5)

                    if not store.get(BLINKING_STORE_KEY):
                        Thread(target=blink, args=(store, )).start()
                        store.set(BLINKING_STORE_KEY, 1)

        sleep()