Python

OpenBSD - ansible-pylibssh

wanna build ansible-pylibssh on OpenBSD 7.3 ? Build failed ? $ pip install ansible-pylibssh Defaulting to user installation because normal site-packages is not writeable Collecting ansible-pylibssh Using cached ansible-pylibssh-1.1.0.tar.gz (106 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... done Building wheels for collected packages: ansible-pylibssh Building wheel for ansible-pylibssh (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for ansible-pylibssh (pyproject.

Multiprocessing

Parallel Processing i recently read an article about parallel processing. i remembered my domain checker service which checks a lot of domains for their availablitly, and this script runs sequentiel and needs around 30 seconds. initially i worked on a caching mechanism to speed up results. but if a service is not used that often (nobody is useing my domain checker…), there is not much you can gain with caching.

Python - Redirector

Redirector App wrote a little redirector app and tought i will explain and share it here. it’s a bit like a url shortener, but you can define the “shortcut” of the URL. how does it work it basically consists of a Text File wir Redirection URL’s. redi.txt stoege,https://www.stoege.net blog,https://blog.stoege.net test,https://www.test.com Call it so, when you open a Browser and Request the URL: https://your.domain.de/blog, you get redirected to https://blog.stoege.net main.app from flask import Flask, redirect, request import datetime import os import random # Vars redirect_file="redi.

Python - Little Wordcloud

Do you like Word Clouds ? I do …! following a litte Script which Parse a Website and build a appropriate Word Cloud Script mkdir ~/mywordcloud; cd ~/mywordcloud cat <<'EOF' > main.py import fire import matplotlib.pyplot as plt import pandas as pd import re import requests from bs4 import BeautifulSoup from wordcloud import STOPWORDS, WordCloud def gen_cloud_tag(url: str = "https://blog.stoege.net"): # add https if not url.startswith("https://"): url = "https://" + url # get Webpage response = requests.

Flask JWT - Sample

Flask & JWT getting your hands dirty with Flask and JWT Source https://dev.to/grahammorby/jwt-auth-in-flask-python-18i4 with some modifications by myself … Environment Test under macOS & OpenBSD, Poetry installed and working Script build virtual env export app="app100" export FLASK_APP="${app}/app" poetry new ${app} cd ${app} set python 3.10 poetry env use $(which python3.10) gsed -i "s/python = \"^3.*$/python = \"^3.10\"/" pyproject.toml poetry lock add packages wget -4 -O requirements.txt https://raw.githubusercontent.com/GrahamMorbyDev/jwt-flask/master/requirements.txt echo "marshmallow-sqlalchemy" >> requirements.

Django on Gooogle Cloud

I’ll give a try running an Application on Google Cloud. Not with great sucess :( Source https://codelabs.developers.google.com/codelabs/cloud-run-django?hl=en#0 https://codelabs.developers.google.com/codelabs/cloud-run-hello-python3#1 Get Cloud List, Active Account gcloud auth list gcloud config set account 'username@gmail.com' List Projects gcloud config list project [core] project = cloud-run-372113 Your active configuration is: [cloudshell-6045] username@cloudshell:~ (cloud-run-372113)$ Set Project ID gcloud config set project cloud-run-372113 username@cloudshell:~ (cloud-run-372113)$ gcloud config set project cloud-run-372113 Updated property [core/project]. Enable API gcloud services enable \ artifactregistry.

Alpine - Pandas on Docker Image

How to install Pandas on Alpine Linux Run Alpine Container docker run -it alpine add packages apk update apk add python3 py3-pip gcc python3-dev g++ add / build pandas time pip install pandas real 26m 13.14s user 30m 46.40s sys 3m 27.51s Happy Pandas ! Any Comments ? sha256: afb99c7e3ed003bee48b65795a153c4fe7835fe3dae0759b70ab2bfb5adc4fd5

Fastapi

FastAPI - Dependencies and Custom Headers Source https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-in-path-operation-decorators/ Code from fastapi import Depends, FastAPI, Header, HTTPException app = FastAPI() async def verify_token(x_token: str = Header()): if x_token != "fake-super-secret-token": raise HTTPException(status_code=400, detail="X-Token header invalid") async def verify_key(x_key: str = Header()): if x_key != "fake-super-secret-key": raise HTTPException(status_code=400, detail="X-Key header invalid") return x_key @app.get("/items/", dependencies=[Depends(verify_token), Depends(verify_key)]) async def read_items(): return [{"item": "Foo"}, {"item": "Bar"}] Test’s Failed no Custom Header curl -s http://localhost/api/items/ |jq { "detail": [ { "loc": [ "header", "x-token" ], "msg": "field required", "type": "value_error.

Little Mail Validator in Python

wrote a little Mail Adresse Validator in Python. use it, modify it, like it … best practice for python is to use a virtual env like Poetry (or virtualenv) and add the “email-validator” module like this: poetry add email-validator Code few lines of code … #!/usr/bin/env python3 from email_validator import validate_email, EmailNotValidError ok=[] nok=[] emails = [ "my+address@mydomain.tld", "hans@dampf.ch", "gott@welt.net", "adsf@asdf.com", "asf.asdf", "franz!mueller@abc.com", "asdf@asdf.adf" ] print ("\nMy Little Mail Validator\n") for email in emails: try: # Validate.

Python

Python Snippets RealPython Best Practices: https://realpython.com/tutorials/best-practices/ Convert CSV to JSON cat LARGEFILE.csv |python3 -c 'import csv, json, sys; print(json.dumps([dict(r) for r in csv.DictReader(sys.stdin)]))' > LARGEFILE.json ### Show System Path python3.10 -c "import sys; print('\n'.join(sys.path))" Zfill Padding Zero >>> for i in range(1,10): ... str(i).zfill(4) '0001' '0002' '0003' ... Different Padding #!/usr/bin/env python3 for i in range(1,99): print( str(i).zfill(4) +" "+ str(i).rjust(4, '-') +" "+ str(i).ljust(4, '-') +" "+ str(i).center(4, '-') ) 0001 ---1 1--- -1-- 0002 ---2 2--- -2-- 0003 ---3 3--- -3-- .