diff --git a/qr_script/qr_file.csv b/qr_script/qr_file.csv new file mode 100644 index 0000000..603a8b0 --- /dev/null +++ b/qr_script/qr_file.csv @@ -0,0 +1,7 @@ +qr,nazov +123123141412313000,qr1 +324503450345839,qr2 +234252342424,qr3 +23425252342424,qr4 +111111111,qr5 +0,qr6 diff --git a/qr_script/qr_file.ods b/qr_script/qr_file.ods new file mode 100644 index 0000000..8bf0460 Binary files /dev/null and b/qr_script/qr_file.ods differ diff --git a/qr_script/qr_generator.py b/qr_script/qr_generator.py new file mode 100644 index 0000000..afc8730 --- /dev/null +++ b/qr_script/qr_generator.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +""" +QR Code Generator + +Reads a CSV/TSV file where: + - First row is a header (skipped). + - First column contains the data/text to encode into a QR code. + - Second column contains the base name for the output PNG file. + +Uses the `qrencode` command-line tool to generate QR codes. +""" + +import argparse +import csv +import os +import subprocess +import sys + + +def main(): + parser = argparse.ArgumentParser( + description="Generate QR codes from a data file using qrencode." + ) + parser.add_argument( + "input_file", + help="Path to the input file (CSV or TSV). The first row is treated as a header and skipped.", + ) + parser.add_argument( + "-d", + "--delimiter", + default=None, + help="Column delimiter (default: auto-detect — comma for .csv, tab otherwise).", + ) + parser.add_argument( + "-o", + "--output-dir", + default=".", + help="Directory to write PNG files into (default: current directory).", + ) + parser.add_argument( + "--qrencode", + default="qrencode", + help="Path to the qrencode binary (default: qrencode).", + ) + parser.add_argument( + "--size", + type=int, + default=10, + help="Module size in pixels (qrencode -s, default: 10).", + ) + + args = parser.parse_args() + + # --- auto-detect delimiter --- + if args.delimiter is None: + if args.input_file.lower().endswith(".csv"): + args.delimiter = "," + else: + args.delimiter = "\t" + + # --- check qrencode --- + try: + subprocess.run( + [args.qrencode, "--version"], + capture_output=True, + check=True, + ) + except (FileNotFoundError, subprocess.CalledProcessError): + print( + f"Error: '{args.qrencode}' not found or not working. Install qrencode (e.g. apt install qrencode).", + file=sys.stderr, + ) + sys.exit(1) + + os.makedirs(args.output_dir, exist_ok=True) + + # --- read file and generate QR codes --- + with open(args.input_file, "r", encoding="utf-8") as fh: + reader = csv.reader(fh, delimiter=args.delimiter) + header = next(reader) # skip header row + print(f"Skipped header: {header}") + + count = 0 + for row_num, row in enumerate(reader, start=2): # row 2 = first data row + if not row or len(row) < 2: + print(f"Row {row_num}: skipping (needs at least 2 columns)", file=sys.stderr) + continue + + data = row[0].strip() + name = row[1].strip() + + if not data or not name: + print(f"Row {row_num}: skipping (empty column)", file=sys.stderr) + continue + + output_path = os.path.join(args.output_dir, f"{name}.png") + + cmd = [ + args.qrencode, + "-s", str(args.size), + "-o", output_path, + data, + ] + + print(f"Row {row_num}: encoding '{data}' -> {output_path}") + subprocess.run(cmd, check=True) + count += 1 + + print(f"\nDone. Generated {count} QR code(s) in '{args.output_dir}'.") + + +if __name__ == "__main__": + main() diff --git a/qr_script/qr_output/qr1.png b/qr_script/qr_output/qr1.png new file mode 100644 index 0000000..093dd74 Binary files /dev/null and b/qr_script/qr_output/qr1.png differ diff --git a/qr_script/qr_output/qr2.png b/qr_script/qr_output/qr2.png new file mode 100644 index 0000000..6809756 Binary files /dev/null and b/qr_script/qr_output/qr2.png differ diff --git a/qr_script/qr_output/qr3.png b/qr_script/qr_output/qr3.png new file mode 100644 index 0000000..fb786d1 Binary files /dev/null and b/qr_script/qr_output/qr3.png differ diff --git a/qr_script/qr_output/qr4.png b/qr_script/qr_output/qr4.png new file mode 100644 index 0000000..d76bfbf Binary files /dev/null and b/qr_script/qr_output/qr4.png differ diff --git a/qr_script/qr_output/qr5.png b/qr_script/qr_output/qr5.png new file mode 100644 index 0000000..14ee40d Binary files /dev/null and b/qr_script/qr_output/qr5.png differ diff --git a/qr_script/qr_output/qr6.png b/qr_script/qr_output/qr6.png new file mode 100644 index 0000000..46dc146 Binary files /dev/null and b/qr_script/qr_output/qr6.png differ