Skip to content

PyWebIO vs. Flask

Python3
  • Seit einigen Monaten, entwickle ich zum Lernen mit Flask. Davor habe ich schon mal PyWebIO eingesetzt. Beides sind Webframeworks. Was sind so meine Gedanken dazu.

    Code Beispiel PyWebIO

    @use_scope('backup')
        def backup():
            clear_scope()
            BackupList.load_json()
    
            # we build header and tdata for table
            tab_init = []
    
            # Print data from backups
            for count, value in enumerate(backups):
                # print("Control", count, backups[value].name)
    
                if count == 0:
                    tab_init.append(['No.', 'Backup name of the restic data backup', 'Actions'])
    
                if backups[value].init == "1":
                    button_list = {"label": 'Init', "value": 'Init', "color": 'primary', "disabled": True}
                    tab_init.append([count + 1,
                                     backups[count].name,
                                     put_buttons([
                                          button_list],
                                         onclick=partial(actions, count + 1))
                                     ])
                else:
                    button_list = {'label': 'Init', 'value': 'Init', 'color': 'primary', "disabled": False}
                    tab_init.append([count + 1,
                                     backups[count].name,
                                     put_buttons([
                                          button_list],
                                         onclick=partial(actions, count + 1))
                                     ])
    

    PyWebIO - Pro

    Contra

    • Nur für kleine Projekte geeignet
    • Kleine Community

    Code Beispiel Flask

    @home.route('/dashboard', methods=['GET'])
    @login_required
    def dashboard():
        refreshed = False
        refreshed = 'refreshed' in request.args
        # print("Refreshed", refreshed)
    
        data2 = all_data.get_all_stocks()
    
        data = sorted(data2.values(), key=lambda x: x['name_stock'], reverse=False)
    
        sums = []
        total_sum = all_data.get_total_sum('total_sum')
        sums.append(float(total_sum) if total_sum is not None else 0.0)
        old_total_sum = all_data.get_total_sum('old_total_sum')
        sums.append(float(old_total_sum) if total_sum is not None else 0.0)
        # print("SUMS", sums)
    
        return render_template('dashboard.html',
                               refreshed=refreshed,
                               data=data,
                               sums=sums,
                               active_menu='dashboard',
                               test_mode=config.TEST_MODE)
    

    Flask - Pro

    • Auch für große Projekte geeignet
    • Gute Dokumentation
    • Große aktive Community

    Contra

    • Leider muss man sich auch viel mit HTML, CSS & Javascript beschäftigen

    Fazit

    An PyWebIO hat mir sehr gut gefallen, das man so ziemlich alles mit Python Code machen kann, bis man an die Grenzen stößt. Mit Flask kann man wesentlich komplexere Webanwendungen bauen, dank Blueprints kann man das auch ordentlich strukturieren. Was mich sofort an Flask genervt hat ist, das man nun wieder HTML, CSS & Javascript drauf haben sollte. Aber, das ist halt auch der große Vorteil gegenüber PyWebIO, man ist wesentlich flexibler.

    Ich habe mir vorgenommen, mein vorhandenes Projekt ResticUI auf Flask umzubauen. Mal schauen, wie sich das so entwickelt. Mein aktuelles privates Flask Projekt (portfolio) ist mittlerweile gut ausgereift ist aber leider zu sehr auf meine privaten Anforderungen zugeschnitten, so dass ich es nicht public stellen kann. Evtl. baue ich das später mal entsprechend um.

    Happy Coding!

  • Mist, jetzt habe ich auch noch Streamlit gefunden. Jetzt geht mir langsam die Zeit aus...

  • Pycharm - Interpreter Settings

    Python3 python pycharm
    1
    2
    0 Stimmen
    1 Beiträge
    161 Aufrufe
    Niemand hat geantwortet
  • Redis Stack?

    Redis redis linux
    1
    1
    0 Stimmen
    1 Beiträge
    169 Aufrufe
    Niemand hat geantwortet
  • NodeBB - v3.7.0

    NodeBB nodebb linux
    1
    0 Stimmen
    1 Beiträge
    130 Aufrufe
    Niemand hat geantwortet
  • Nextcloud - extrem lange Ladezeiten

    Nextcloud nextcloud code linux
    1
    1
    0 Stimmen
    1 Beiträge
    178 Aufrufe
    Niemand hat geantwortet
  • Ansible - ein kurzer Test

    Linux ansible linux
    1
    0 Stimmen
    1 Beiträge
    173 Aufrufe
    Niemand hat geantwortet
  • Portainer - NodeBB Container erstellen

    Linux nodebb portainer linux redis
    1
    5
    0 Stimmen
    1 Beiträge
    342 Aufrufe
    Niemand hat geantwortet
  • NanoPi R2S - Firewall mit VLan und DHCP-Server

    Verschoben NanoPi R2S nanopir2s linux
    2
    2
    0 Stimmen
    2 Beiträge
    831 Aufrufe
    FrankMF
    Nachdem ich die Tage feststellen musste, das irgendwas mit dem Gerät nicht stimmte, bekam keine DNS Auflösung über die Konsole, habe ich das heute mal eben neuinstalliert. Armbian ist ja immer was spezielles Hat sich bis heute nix dran geändert..... Ok, dann heute mal eben ein neues Image erstellt. Download Gewählt habe ich das Armbian Buster. Image auf die SD-Karte, eingeloggt. Alles wie oben erstellt und abgespeichert. Neustart, geht wieder alles. root@192.168.3.15's password: _ _ _ ____ ____ ____ | \ | | __ _ _ __ ___ _ __ (_) | _ \|___ \/ ___| | \| |/ _` | '_ \ / _ \| '_ \| | | |_) | __) \___ \ | |\ | (_| | | | | (_) | |_) | | | _ < / __/ ___) | |_| \_|\__,_|_| |_|\___/| .__/|_| |_| \_\_____|____/ |_| Welcome to Debian GNU/Linux 10 (buster) with Linux 5.9.11-rockchip64 System load: 2% Up time: 11 min Memory usage: 10% of 978M IP: 192.168.3.15 192.168.1.1 192.168.2.1 CPU temp: 61°C Usage of /: 5% of 29G Last login: Sun Dec 6 12:28:10 2020 from 192.168.3.213 Kernelversion root@nanopi-r2s:~# uname -a Linux nanopi-r2s 5.9.11-rockchip64 #20.11.1 SMP PREEMPT Fri Nov 27 21:59:08 CET 2020 aarch64 GNU/Linux ip a oot@nanopi-r2s:~# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether b2:b5:10:38:9e:76 brd ff:ff:ff:ff:ff:ff inet 192.168.3.15/24 brd 192.168.3.255 scope global dynamic eth0 valid_lft 6360sec preferred_lft 6360sec inet6 2a02:908:xxxxxx/64 scope global dynamic mngtmpaddr valid_lft 7196sec preferred_lft 596sec inet6 fe80::b0b5:10ff:fe38:9e76/64 scope link valid_lft forever preferred_lft forever 3: lan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether b2:b5:10:38:9e:96 brd ff:ff:ff:ff:ff:ff 4: lan0.100@lan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether b2:b5:10:38:9e:96 brd ff:ff:ff:ff:ff:ff inet 192.168.1.1/24 brd 192.168.1.255 scope global lan0.100 valid_lft forever preferred_lft forever inet6 fe80::b0b5:10ff:fe38:9e96/64 scope link valid_lft forever preferred_lft forever 5: lan0.200@lan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether b2:b5:10:38:9e:96 brd ff:ff:ff:ff:ff:ff inet 192.168.2.1/24 brd 192.168.2.255 scope global lan0.200 valid_lft forever preferred_lft forever inet6 fe80::b0b5:10ff:fe38:9e96/64 scope link valid_lft forever preferred_lft forever Vom Notebook aus funktioniert auch alles. So weit bin ich zufrieden. Jetzt mal langsam anfangen, der Kiste IPv6 beizubringen. Oje, nicht gerade mein Lieblingsthema... Bis der NanoPi R4S hier ankommt und ein vernünftiges Image hat, vergeht ja noch was Zeit...
  • Restic - forget --keep-last 3 --prune

    Restic linux restic
    2
    0 Stimmen
    2 Beiträge
    663 Aufrufe
    FrankMF
    Ich habe mich damit noch ein wenig beschäftigt, die letzten drei zu behalten, ist nicht so optimal. Da es viele Optionen bei dem Befehl gibt, hier ein Ausschnitt Flags: -l, --keep-last n keep the last n snapshots -H, --keep-hourly n keep the last n hourly snapshots -d, --keep-daily n keep the last n daily snapshots -w, --keep-weekly n keep the last n weekly snapshots -m, --keep-monthly n keep the last n monthly snapshots -y, --keep-yearly n keep the last n yearly snapshots habe ich das ein wenig so angepasst, das ich denke es passt für mich. restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ forget --keep-last 3 --keep-monthly 3 --prune Damit behalte ich auch die jeweils eines pro Monat. Und die letzten drei. Das sieht dann so aus. root@debian:~# ./backup2.sh repository 2f3f6147 opened successfully, password is correct Files: 38 new, 100 changed, 13268 unmodified Dirs: 0 new, 1 changed, 0 unmodified Added to the repo: 10.166 GiB processed 13406 files, 50.324 GiB in 3:24 snapshot 849f614c saved repository 2f3f6147 opened successfully, password is correct Applying Policy: keep the last 3 snapshots, 3 monthly snapshots snapshots for (host [debian], paths [/home/frank]): keep 5 snapshots: ID Time Host Tags Reasons Paths ------------------------------------------------------------------------------------ a7251cfd 2019-11-28 17:00:01 debian monthly snapshot /home/frank 283d4027 2019-12-31 17:00:01 debian monthly snapshot /home/frank ae2b96ec 2020-01-01 21:47:46 debian last snapshot /home/frank 079e00a6 2020-01-02 17:00:01 debian last snapshot /home/frank 849f614c 2020-01-03 21:08:45 debian last snapshot /home/frank monthly snapshot ------------------------------------------------------------------------------------ 5 snapshots remove 26 snapshots: ID Time Host Tags Paths ------------------------------------------------------------------ 896f16c2 2019-11-07 22:23:40 debian /home/frank b21bcf6d 2019-11-11 17:00:01 debian /home/frank f89248fb 2019-11-12 17:00:01 debian /home/frank 123ab546 2019-11-13 17:00:01 debian /home/frank b82d87d0 2019-11-18 17:00:01 debian /home/frank 040b0ab7 2019-11-19 17:00:01 debian /home/frank 7221d8ef 2019-11-20 17:00:01 debian /home/frank 84132a25 2019-11-21 17:00:01 debian /home/frank b558a52c 2019-11-25 17:00:01 debian /home/frank e5cc0c3e 2019-12-02 17:00:01 debian /home/frank 22423fa5 2019-12-03 17:00:01 debian /home/frank 39df1ab9 2019-12-04 17:00:01 debian /home/frank 98843457 2019-12-05 17:00:01 debian /home/frank b0cdd4b6 2019-12-09 17:00:01 debian /home/frank 828414f9 2019-12-10 17:00:01 debian /home/frank e34a27c3 2019-12-11 17:00:01 debian /home/frank 6e488c3b 2019-12-12 17:00:01 debian /home/frank 17898403 2019-12-16 17:00:01 debian /home/frank 1973305a 2019-12-17 17:00:01 debian /home/frank 9553bedd 2019-12-18 17:00:01 debian /home/frank fedf749d 2019-12-19 17:00:01 debian /home/frank 8e7cb876 2019-12-23 17:00:01 debian /home/frank 0bd0d102 2019-12-25 17:00:01 debian /home/frank 13d348b0 2019-12-26 17:00:01 debian /home/frank c7d960aa 2019-12-30 17:00:01 debian /home/frank f6ea9118 2020-01-01 17:00:01 debian /home/frank ------------------------------------------------------------------ 26 snapshots 26 snapshots have been removed, running prune counting files in repo building new index for repo [0:35] 100.00% 7806 / 7806 packs repository contains 7806 packs (46537 blobs) with 41.110 GiB processed 46537 blobs: 0 duplicate blobs, 0 B duplicate load all snapshots find data that is still in use for 5 snapshots [0:01] 100.00% 5 / 5 snapshots found 32654 of 46537 data blobs still in use, removing 13883 blobs will remove 0 invalid files will delete 715 packs and rewrite 752 packs, this frees 5.027 GiB [2:28] 100.00% 752 / 752 packs rewritten counting files in repo [0:01] 100.00% 6571 / 6571 packs finding old index files saved new indexes as [d137b425 f7caee99 a6e9711a] remove 35 old index files [1:13] 100.00% 1467 / 1467 packs deleted done using temporary cache in /tmp/restic-check-cache-916655151 repository 2f3f6147 opened successfully, password is correct created new cache in /tmp/restic-check-cache-916655151 create exclusive lock for repository load indexes check all packs check snapshots, trees and blobs read all data [7:47] 100.00% 6571 / 6571 items duration: 7:47 no errors were found root@debian:~# Am Ende seht ihr noch, wie Restic alle Files testet. Mein Script sieht jetzt so aus. #!/bin/bash # Script um mit Restic Daten automatisiert zu sichern! # Dient zum Sichern der Homepartition auf dem ROCKPro64 NAS! # Was soll gesichert werden? backup_pfad=/home/frank # Programm Start restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ backup $backup_pfad --exclude-file=excludes.txt restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ forget --keep-last 3 --keep-monthly 3 --prune # Testen restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ check --read-data Das dann schön mit einem Cronjob laufen lassen und die Datensicherung ist erledigt