Skip to content

Instantly share code, notes, and snippets.

View sebastianknopf's full-sized avatar

Sebastian Knopf sebastianknopf

View GitHub Profile
@sebastianknopf
sebastianknopf / set-cover-gtfs.py
Created May 5, 2025 11:57
Python implementation for a set-cover-problem: Which are the minimum stations to meet every trip of a GTFS dataset at least once?
import csv
import os
import re
import sys
from collections import defaultdict
from datetime import datetime
def reduce_ifopt(ifopt_id: str) -> str:
pattern = r"^[a-z]{2}:\d{5}:[\w\d]+(:[\w\d]+){0,2}$"
@sebastianknopf
sebastianknopf / datalog.py
Last active April 3, 2025 11:02
datalog.py
import json
import os
from datetime import datetime
from lxml.etree import fromstring
from lxml.etree import tostring
class Datalog:
@classmethod
@sebastianknopf
sebastianknopf / csv2ddb.py
Last active October 13, 2024 19:30
python helper script for memory efficient importing huge CSV files into a DuckDB database
import click
import csv
import duckdb
import polars
@click.command
@click.option('--file', '-f', help='Input CSV file')
@click.option('--db', '-d', help='DuckDB filename')
@click.option('--table', '-t', help='Destination table name to import the CSV file')
@click.option('--create-statement', '-c', default=None, help='Create statement filename for destination table')
@sebastianknopf
sebastianknopf / asc.py
Last active September 12, 2024 09:36
Python helper class to process *.asc files used in IVU.pool data for timetable exchange
import csv
import re
import os
from isa.ascdef import name2def
########################################################################################################################
# Helper class for reading and modifying *.asc files.
########################################################################################################################
@sebastianknopf
sebastianknopf / x10.py
Created August 1, 2024 08:41
Python helper class to process *.x10 files according to VDV-451
import csv
import re
########################################################################################################################
# Helper class for reading and modifying *.x10 files.
########################################################################################################################
def read_x10_file(filename):
x10_file = X10File()
x10_file.read(filename)
@sebastianknopf
sebastianknopf / offlinemaps.py
Created January 12, 2023 18:28
python script to fetch ZXY tiles from map servers
import os
import requests
import math
import zipfile
from optparse import OptionParser
# map server constants
MAP_SERVER_ADDRESS = '[YourMapServer]'
MAP_SERVER_USERNAME = ''
@sebastianknopf
sebastianknopf / objectunifier.py
Created May 11, 2022 21:03
unifies objects to a comparable (hash) string regardless of their spelling - use case: checking persons and addresses against a blacklist without storing personal data permanently in database
import hashlib
import re
import unittest
from abc import abstractmethod
class ObjectUnifier:
_token_list = []
@sebastianknopf
sebastianknopf / CommandLineParser.java
Last active May 25, 2020 10:53
a basic parser for command line arguments in java
import java.util.ArrayList;
import java.util.List;
/**
* Command line argument parser class for parsing command lines like
* program.jar -i input.txt -o output.txt --verbose.
*/
public class CommandLineParser {
/**
@sebastianknopf
sebastianknopf / timetable.php
Created February 5, 2019 14:47
simple script for creating visual time tables based on data in gtfs format
<?php
// database credentials
define('DB_HOST', '');
define('DB_USER', '');
define('DB_PASW', '');
define('DB_DATA', '');
define('DB_PREF', '');
// several constants