Пример #1
0
    def create(self):
        css = ''
        for css_file in self.css_files:
            css += f'<link rel="stylesheet" type="text/css" href="{css_file}">\n'
        js = ''
        for js_file in self.script_files:
            js += f'<script src="{js_file}"> </script>\n'

        ok, self.html = fio.read( self.template )
        if ok:
            self.html = self.html.replace('{{%now%}}', str( datetime.datetime.now() ))
            self.html = self.html.replace('{{%title%}}', self.title)
            self.html = self.html.replace('{{%charset%}}', self.charset)
            self.html = self.html.replace('{{%author%}}', self.author)
            self.html = self.html.replace('{{%viewport%}}', self.viewport)
            self.html = self.html.replace('{{%css_files%}}', css)
            self.html = self.html.replace('{{%css_code%}}', self.css_code)
            self.html = self.html.replace('{{%header%}}', self.header)
            self.html = self.html.replace('{{%main%}}', self.main)
            self.html = self.html.replace('{{%footer%}}', self.footer)
            self.html = self.html.replace('{{%script_files%}}', js)
            self.html = self.html.replace('{{%script_code%}}', self.script_code)
            self.html = self.html.replace('{{%path_to_root%}}', self.path_to_root)

        return ok
Пример #2
0
def download_and_read_file(url, file):
    ok, t = False, ''
    if has_internet():
        ok = fio.download(url, file)
        if ok:
            ok, t = fio.read(file)
    else:
        console.log('No internet connection...', True)

    return ok, t
Пример #3
0
def ask_for_entities( txt, space=False):
    l, info = [], False
    ok, t = fio.read(utils.mk_path(config.dir_app, config.knmi_dayvalues_info_txt))
    inf = f'INFO:\n{t}' if ok else f'Info file {config.knmi_dayvalues_info_txt} not found...'

    txt += '\n' + vt.dayvalues_entities( sep=',' )
    txt += 'To add one weather entity, type in the enitity name. e.g. TX\n'
    txt += 'To add one more stations, give entity name separated by a comma. e.g TX, TG, TN\n'

    while True:
        t  = txt
        t += inf if config.help_info or info else "Type 'i' for more info..."

        if len(l) > 0:
            t += "\nPress 'n' to move to the next !"

        answ = ask_for_txt( t, default=False, space=space )

        if not answ or utils.is_empthy(answ):
            console.log('Please type in something ...', True)
            continue # Again
        else:
            answ = clear( answ )
            if answ == 'i':
                info = True
            elif utils.is_quit(answ):
                return config.answer_quit[0] # Return first el for quit
            elif answ == 'n' and len(l) > 0:
                return l
            elif answ.find(',') != -1:
                lt = answ.split(',')
                for e in lt:
                    if e:
                        e = clear(e) # Clean input
                        ok, ent = daydata.is_ent( e )
                        if ok:
                            l.append(e)
            else:
                ok, ent = daydata.is_ent( answ )
                if ok:
                    l.append(ent)
                else:
                    console.log(f"Unknown option {ent} given. Fill in one or more entities separated by an ',' ", True)

            if len(l) > 0:
                cnt, kol, t = 1, 10, 'All weather entities who are added are: '
                for ent in l:
                    t += ent + ', '
                    if cnt % kol == 0:
                        t += '\n'
                t = t[0:-2] # Remove space and comma
                console.log( t, True )

    return l
Пример #4
0
def process_weather_knmi_global():
    '''Function downloads and print a global weather forecast from the website from the knmi'''
    console.header('START DOWNLOAD KNMI GLOBAL FORECAST...', True)

    ok, t = False, ''
    if utils.has_internet():
        sd = utils.loc_date_now().strftime('%Y%m%d')
        url = cfg.knmi_forecast_global_url
        file = utils.mk_path(cfg.dir_forecasts_txt,
                             f'basisverwachting-{sd}.txt')
        ok = fio.download(url, file)
        if ok:
            ok, t = fio.read(file)
            if ok:
                t = '\n' + vt.clean_up(t)
                console.log(t, True)
            else:
                console.log('Not ok. Something went wrong along the way.',
                            True)
    else:
        console.log('No internet connection...', True)

    console.footer('END DOWNLOAD KNMI GLOBAL FORECAST...', True)
    cask.ask_back_to_main_menu()
Пример #5
0
def process_weather_knmi_guidance():
    '''Function downloads and prints a global a more in depth forecast from the website from the knmi'''
    console.header('START DOWNLOAD KNMI GUIDANCE...', True)

    ok, t = False, ''
    if utils.has_internet():
        sd = utils.loc_date_now().strftime('%Y%m%d')
        url = cfg.knmi_forecast_guidance_url
        name = f'guidance_meerdaagse-{sd}.txt'
        file = utils.mk_path(cfg.dir_forecasts_txt, name)
        ok = fio.download(url, file)
        if ok:
            ok, t = fio.read(file)
            if ok:
                t = '\n' + vt.clean_up(t)
                console.log(t, True)
            else:
                console.log('Not ok. Something went wrong along the way.',
                            True)
    else:
        console.log('No internet connection...', True)

    console.footer('END DOWNLOAD KNMI GUIDANCE...', True)
    cask.ask_back_to_main_menu()
Пример #6
0
def process_weather_knmi_model():
    '''Function downloads and prints a discussion about the weather models from the website from the knmi'''
    console.header('START DOWNLOAD KNMI DISCUSSION WEATHER MODELS...', True)

    ok, t = False, ''
    if utils.has_internet():
        sd = utils.loc_date_now().strftime('%Y%m%d')
        url = cfg.knmi_forecast_model_url
        name = f'guidance_model-{sd}.txt'
        file = utils.mk_path(cfg.dir_forecasts_txt, name)
        ok = fio.download(url, file)
        if ok:
            ok, t = fio.read(file)
            if ok:
                t = '\n' + vt.clean_up(t)
                console.log(t, True)
            else:
                console.log('Not ok. Something went wrong along the way.',
                            True)
    else:
        console.log('No internet connection...', True)

    console.footer('END DOWNLOAD KNMI DISCUSSION WEATHER MODELS...', True)
    cask.ask_back_to_main_menu()