Archive for the ‘Programmierung’ Category.

Trello-Boards exportieren mit py-trello

Hier etwas Beispiel-Code, um Trello-Boards zu exportieren. Unten im Code nur nach stdout, Code für LaTeX und HTML/MD werde ich im Github Repository https://github.com/UweZiegenhagen/python-trello-output ergänzen.

from trello import TrelloClient # pip install py-trello
 
client = TrelloClient(
    api_key='<secret_api_key>',
    token='<secret_token>'
)
 
def list_all_boards(client):
    """
        get list of all boards to determine the ID
        for further functions
    """
    all_boards = client.list_boards()
    for counter, board in enumerate(all_boards):
        print(counter, board.name)
 
## uncomment if needed
# list_all_boards(client)
 
def print_cards_from_board(board_id, client):
    """
        Access board with ID board_id in the client instance
        and print all non-archived lists with their non-archived cards 
    """
    all_boards = client.list_boards()
    my_board = all_boards[board_id] # 15 = my someday projects
    all_lists_on_board = my_board.list_lists()
 
    for list in all_lists_on_board:
        if not list.closed:
            for card in list.list_cards():
                if not card.closed:
                    print(list.name, ':' , card.name)
 
print_cards_from_board(15, client)

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

TeX-Dokumentstrukturen visualisieren mit Graphviz und Python

Hier ein Code-Schnipsel, um die Inputs und Includes von LaTeX-Dokumenten zu visualisieren. Ist noch ein wenig rudimentär und hardcoded, in den nächsten Tagen werde ich den Code mal in ein Github-Repo packen und dann ein wenig aufräumen. Aktuell wird eine Datei Master.tex erwartet, eine Graph.dot Datei wird als Output geschrieben. Das Skript geht rekursiv durch die TeX-Dateien durch und sucht nach \input, \include, \includegraphics und \lstinputlisting Befehlen.

# -*- coding: utf-8 -*-
import re
 
nodes = []
 
# which commands indicate following
commandsToFollow = ('input', 'include')
 
def find_ext_references(somefile):
    with open(somefile) as file:
        filecontent = file.readlines()
        for i in filecontent:
            search_results = re.findall(r"(\\)(includegraphics|include|lstinputlisting|input)(\[?.*\]?{)(.+?)(})", i)
            for j in search_results:
                print(j)
                nodes.append((somefile, j[3], j[1]))
                if j[1].endswith(commandsToFollow):
                    find_ext_references(j[3]+'.tex') # assume that no extension is used for input/include
 
find_ext_references('Master.tex')
 
print(nodes)
 
if len(nodes)>0:
    with open('graph.dot','w') as output:
            output.write('digraph IncludesInputs {\n')
            output.write('node [shape=box];\n\n')
            for k in nodes:
                if k[2].endswith(commandsToFollow):
                    output.write('"'+k[0] + '"->"' + k[1] + '.tex" [color="green"];\n')
                elif k[2].endswith('graphics'):
                    output.write('"'+k[0] + '"->"' + k[1] + '" [color="blue"];\n')         
                elif k[2].endswith('listing'):
                    output.write('"'+k[0] + '"->"' + k[1] + '" [color="red"];\n')                             
 
            output.write('}')

Übersetzt man die Graph.dot dann mit der dot.exe aus Graphviz, so erhält man für ein kleines Beispiel den folgenden Graphen. (Beispielaufruf: dot -Tpng Graph.dot)

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Git / Github Cheat Sheet

Da ich sie immer wieder vergesse, hier die (für mich) wichtigsten git Befehle.

Befehl Erläuterung
git config –global user.name „Max Mustermann“ Setze Usernamen
git config –global user.email „Max@Mustermann.de“ Setze User E-Mail-Adresse
git clone „githublink“ clone ein Repo von Github
git status Status des Repositories
git add „Datei“ Füge Datei zur Staging-Umgebung hinzu, git add . für alle Dateien im aktuellen Verzeichnis
git reset HEAD „Datei“ unstage Datei
git commit -m „Kommentar“ commit in das lokale Repository
git push origin master pushe Änderungen zurück nach github
git mv „datei1“ „datei2“ benennt Datei um
git rm „datei1“ löscht Datei
git init „Projektname“ legt lokal ein neues Repository an
git ls-files zeigt alle Dateien im Repo rekursiv

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Nordwind-DB mit Python abfragen (Python, pandas, MySQL)

Hier ein einfaches Beispiel, wie man die Daten aus der Nordwind-Datenbank in einen pandas Dataframe bekommt. Der originale Code stammt von https://pythontic.com/pandas/serialization/mysql und wurde auf meine Datenbank angepasst.

# -*- coding: utf-8 -*-
 
from sqlalchemy import create_engine
import pymysql
import pandas as pd
 
sqlEngine       = create_engine('mysql+pymysql://nwread:northwind@192.168.0.60/northwind', pool_recycle=3600)
dbConnection    = sqlEngine.connect()
frame           = pd.read_sql("select * from products", dbConnection);
 
pd.set_option('display.expand_frame_repr', False)
print(frame)
 
frame.to_excel('r:/abc.xlsx')
 
dbConnection.close()

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Getting jitsi into retirement homes

Together with friends from Dingfabrik Koeln (Thanks for the idea, Marian!) I am currently developing an solution for retirement homes to allow simple access to jitsi video sessions.

We know that many old people currently cannot receive visitors due to Corona. So our idea is to give them access to a simple Linux-based notebook and allow them to easily create a jitsi video session. Based on a predefined list of servers (that is to be updated from remote) and a text file with names, that can be edited by a nurse with a text editor, we simply create a url that can be shared among relatives.

The application was made using Python and tkinter, all code was pretty much copied from SO and other sources, I just had to put it together. (Thank you giants, that I could „stand on your shoulders“)

Using a Linux laptop with installed Python (and additional python3-tk package), Chrome/Chromium and git we have the tool run on startup. On the first start a text file with names is created, that can be edited easily.

If you find it useful, see the code in my github: https://github.com/UweZiegenhagen/pyJitsiopen.

Future updates shall include:

  • Automated updates
  • Logging for error tracking
  • Using local server lists that are not overwritten during updates

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Zugriff aus dem lokalen Netz auf die Nordwind-DB

Um aus dem lokalen Netz Zugriff auf die Nordwind-DB zu erhalten, muss man folgendes tun:

  • die Datei 50-server.cnf in /etc/mysql/mariadb.conf.d bearbeiten. Hier statt 127.0.0.1 die IP-Adresse des Servers eingeben. An dieses Interface wird MariaDB gebunden.
  • einen neuen Nutzer anlegen:

    CREATE USER 'nwread' IDENTIFIED BY 'northwind';

  • Zugriff aus dem Netz für diesen User erteilen:

    GRANT USAGE ON *.* TO 'nwread'@'%' IDENTIFIED BY 'northwind';

    Kann sein, dass dieses Statement schon ausreichend ist, das werde ich noch überprüfen. Ich habe aber zusätzlich noch ausgeführt:

  • Zugriff auf die Datenbank geben:

    GRANT ALL privileges ON `northwind`.* TO 'nwread'@'%';

Nach dem Neustarts des MariaDB-Servers klappt der Zugriff, beispielsweise über HeidiSQL, das ich sehr empfehlen kann.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Die Nordwind-Datenbank für MySQL nutzen

Mit der Nordwind (Northwind) Datenbank gibt es eine ursprünglich für MS Access entwickelte Datenbank, an der sich viele SQL-Konstrukte üben lassen. Die Datenbank gibt es auch für MySQL, unter anderem unter https://github.com/dalers/mywind.

Hier nun die notwendigen Schritte für das Einspielen in eine MySQL/MariaDB-Datenbank:

  • git clone https://github.com/dalers/mywind.git
  • cd mywind
  • sudo mariadb < northwind.sql
  • sudo mariadb < northwind-data.sql

Mittels SQL kann man jetzt prüfen, ob die Daten vollständig geladen wurden:

  • sudo mariadb
  • use northwind
  • select count(*) from products;

bringt eine Zeilenzahl von 45 Zeilen.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

MariaDB installieren unter Linux

Für Apache Guacamole brauchte ich einen MySQL/MariaDB Server auf meinem Linux-Server, hier die Schritte zur Installation:

  1. sudo apt update
  2. sudo apt upgrade
  3. sudo apt install mariadb-server
  4. sudo mariadb

Standardmäßig kommt man als root sofort in die Datenbank, ohne ein Passwort einzugeben. Ich bin zwar den Hinweisen von https://kofler.info/root-login-problem-mit-mariadb/ gefolgt, um für den root-User ebenfalls ein Passwort festzulegen.

Aktuell wird aber jedes Passwort akzeptiert, wenn ich root bin, jedoch das festgelegte Passwort nicht akzeptiert, wenn ich als normaler User mysql -u root -p ausführe.

Sinnvolle mysql/mariadb-Befehle

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Parsing Lexware Qif files with Python (and pandas)

Python has a few packages to parse Quicken files, among them:

However both packages generated errors when I used them with the file from Lexware Financial Manager 2019. Also as a programming exercise I decided to write my own parser, available under https://github.com/UweZiegenhagen/PyQIF-Parser.

As of today the code parses Quicken files and generates an Excel file with the accounts, classifications, categories and transactions it finds in the file. It supports (German) online accounts, investment accounts are not (yet) supported. I do not use my portfolio with Quicken so I probably will not implement this, feel free ask for it (with example files) or send pull requests.

Some code example is provided:

from PyQifParser import PyQifParser
 
P = PyQifParser(r'C:\Users\Uwe\Nextcloud\QIF-Parser\Quicken_h.QIF')
P.parse()
P.to_excel('r:/export.xlsx')

I plan to extend the code with repect to a) visualisation, b) sanity checks and c) statistical analyses

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Hashes von Dateien erstellen mit Powershell

Verzeichnisse lassen sich recht einfach mit Powershell abgleichen, wenn man die Hashes aller enthaltenen Dateien vergleicht. Standardmäßig nutzt Powershell SHA256, dies lässt sich jedoch recht leicht ändern.

dir c:\ | get-filehash |  export-csv -notypeinformation -delimiter  ";" -path r:\files.csv 
 
PSDefaultParameterValues.add("Get-FileHash:Algorithm","MD5")

Die erzeugten Daten lassen sich dann leicht in Excel weiterverabeiten.

"Algorithm";"Hash";"Path"
"SHA256";"C883B5D2E16D22B09B176CA0786128F8064D47EDF26186B95845AA3678868496";"C:\msdia80.dll"

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website