コード例 #1
0
def update_cache():
    # Check if RTC has been synced over NTP
    if not rtc.isSet():
        _show_progress("Connecting to WiFi...", False)
        wifi.connect()
        if not wifi.wait():
            _show_progress("Failed to connect to WiFi.", True)
            return False

        while wifi.status() and (time.time() < 1482192000):
            wifi.ntp()

    last_update = _get_last_updated()
    if last_update > 0 and time.time() < last_update + (600):
        return True

    if not wifi.status():
        _show_progress("Connecting to WiFi...", False)
        wifi.connect()
        if not wifi.wait():
            _show_progress("Failed to connect to WiFi.", True)
            return False

    print('Updating woezel cache..')
    #os.remove(cache_path + '/categories.json')
    
    _show_progress("Downloading package list...")
    packages = get_pkg_list()
    categories = set(item['category'] for item in packages)

    with open(cache_path + '/categories.json', 'w') as categories_file:
        categories_file.write(json.dumps([{'name': _slug_to_name(cat), 'slug': cat} for cat in categories]))

    _show_progress("Saving lists...")
    for cat in categories:
        gc.collect()
        with open(cache_path + '/' + cat + '.json', 'w') as category_file:
            category_file.write(json.dumps([app for app in packages if app['category'] == cat]))

    gc.collect()
    _set_last_updated()

    _show_progress("Done!")
    gc.collect()
    return True
コード例 #2
0
		easydraw.disp_string_right_bottom(0, info)
		if len(gui_apps) > 0:
			drawPageIndicator(len(gui_apps), gui_app_current)
		if cfg_greyscale:
			display.flush(display.FLAG_LUT_GREYSCALE)
		else:
			display.flush(display.FLAG_LUT_NORMAL)
	return 1000

virtualtimers.new(0, drawTask, True)

# Free up space in RAM
gc.collect()

# Set the RTC if needed and WiFi is allowed
if not rtc.isSet() and cfg_wifi:
	wifi.connect() #Connecting to WiFi automatically sets the time using NTP (see wifiTask)

# Text scroller
display.windowCreate("scroller", 512, 32) #Workaround!!! windows get corrupted when size is not in units of 8
display.windowShow("scroller")
display.windowMove("scroller", 65, display.height()-22) # Move out of visible screen
display.drawFill("scroller", COLOR_BG)
display.drawText("scroller", 0, 0, cfg_nick_text, COLOR_FG, "permanentmarker22")

def scrollerThread():
	scrollerStartPos = 129
	scrollerEndPos = -display.getTextWidth(cfg_nick_text, "permanentmarker22") - 128
	scrollerPos = scrollerStartPos
	global stopThreads
	while not stopThreads:
コード例 #3
0
def update_cache():
    # Check if RTC has been synced over NTP
    if not rtc.isSet():
        _show_progress("Connecting to WiFi...", False)
        wifi.connect()
        if not wifi.wait():
            _show_progress("Failed to connect to WiFi.", True)
            return False

        while wifi.status() and (time.time() < 1482192000):
            wifi.ntp()

    last_update = _get_last_updated()
    if last_update > 0 and time.time() < last_update + (600):
        return True

    if not wifi.status():
        _show_progress("Connecting to WiFi...", False)
        wifi.connect()
        if not wifi.wait():
            _show_progress("Failed to connect to WiFi.", True)
            return False

    print('Updating woezel cache..')

    _show_progress("Downloading categories...")
    try:
        request = urequests.get("https://%s/eggs/categories/json" %
                                woezel_domain,
                                timeout=30)
        _show_progress("Saving categories...")

        with open(cache_path + '/categories.json', 'w') as categories_file:
            categories_file.write(request.text)

        _show_progress("Parsing categories...")
        categories = request.json()
        request.close()
        del request
        for index, category in enumerate(categories):
            gc.collect()
            cat_slug = category["slug"]
            _show_progress("Downloading '" + category["name"] +
                           "' (%d/%d)..." % (index, len(categories)))
            f = urequests.get("https://%s/basket/%s/category/%s/json" %
                              (woezel_domain, device_name, cat_slug),
                              timeout=30)

            with open(cache_path + '/' + cat_slug + '.json', 'w') as f_file:
                f_file.write(f.text)
            f.close()
            del f
            gc.collect()
        _set_last_updated()

        _show_progress("Done!")
        gc.collect()
        return True
    except BaseException as e:
        sys.print_exception(e)
        _show_progress("Failed!", True)
        gc.collect()
    return False
コード例 #4
0
                'Location': 'epoch'
            }],
            'date':
            '01 Jan',
            'doy':
            1
        }]
        print("Error parsing activities")


##### Main program ######

days = []

## Check if RTC is initialized
if not rtc.isSet():
    if not wifi.status():
        print("Updating time")
        uinterface.connect_wifi()
    wifi.ntp()
    wifi.disconnect()

## Cache updates
cache_path = '/cache/activities'
cache_file = '/activities.json'
url = "http://cz19.lanergy.eu/api/cz_app.php"

## Update cache
update_cache()

## Get current day of year