From ab7878393f4044a85a33e08b8e4e944e4983188d Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Sun, 17 May 2015 02:07:49 +0200 Subject: [PATCH] Kolekce helperu pro import --- dakosdump/helpers.py | 45 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/dakosdump/helpers.py b/dakosdump/helpers.py index 45e83612..05002cbf 100644 --- a/dakosdump/helpers.py +++ b/dakosdump/helpers.py @@ -1,6 +1,49 @@ -from seminar import ovvpfile import os +import datetime +import sqlite3 + +from django.utils.html import escape + +from seminar import ovvpfile +from seminar.models import Problem +from seminar.utils import roman, from_roman + + +# MM_ZADANIA.TYP +typtable={'1': Problem.TYP_ULOHA, '2':Problem.TYP_TEMA, '3':Problem.TYP_SERIAL} + +# MM_DOZ.ZARADENIE, MM_AZAD.ZAMERANIE +def dectag(x): + return ["MFIOTKPZD"[bi] for bi in range(0, 9) if (int(x) & (1 << bi))] + +# Datum z formatu "DD.MM.YY" +def transdate(s): + if '.' not in s: return None + d,m,r = map(int, s.split('.')) + return datetime.date(r + 2000 if r < 30 else r + 1900, m, d) + +class SQLiteRow(object): + def __unicode__(self): + return self.__dict__.__unicode__() + def __str__(self): + return self.__dict__.__str__() + def __repr__(self): + return self.__dict__.__str__() + +# sqlite3 helper +def sqget(db, sql, limit=None): + c = db.execute(sql) + rows = c.fetchmany(limit) if limit else c.fetchall() + res = [] + for row in rows: + o = SQLiteRow() + for coli in range(len(c.description)): + col = c.description[coli] + o.__setattr__(col[0], row[coli]) + res.append(o) + return res +## ovvpfile - based import helpers (old) def read_all_tables(basedir): tables = {}