new version, sqlite, MIT, new db from MI

This commit is contained in:
NetMan 2025-12-16 22:30:11 +01:00
parent bcf25e69f0
commit a7b5f94fe2
8 changed files with 3727 additions and 7196 deletions

134
LICENSE
View file

@ -1,121 +1,21 @@
Creative Commons Legal Code MIT License
CC0 1.0 Universal Copyright (c) 2025 NetMan
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE Permission is hereby granted, free of charge, to any person obtaining a copy
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN of this software and associated documentation files (the "Software"), to deal
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS in the Software without restriction, including without limitation the rights
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS copies of the Software, and to permit persons to whom the Software is
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM furnished to do so, subject to the following conditions:
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The laws of most jurisdictions throughout the world automatically confer THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
exclusive Copyright and Related Rights (defined below) upon the creator IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
and subsequent owner(s) (each and all, an "owner") of an original work of FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
authorship and/or a database (each, a "Work"). AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Certain owners wish to permanently relinquish those rights to a Work for OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
the purpose of contributing to a commons of creative, cultural and SOFTWARE.
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.

101
README.md
View file

@ -1,84 +1,87 @@
# db-prawo-jazdy # db-prawo-jazdy
### Slightly modified version of [prawo-jazdy-resources](https://git.mandarynki.eu/maciej/prawo-jazdy-resources) by [maciej](https://git.mandarynki.eu/maciej), to suit the needs of [nuxt-prawo-jazdy](https://git.mandarynki.eu/netman/nuxt-prawo-jazdy) ### Based on [prawo-jazdy-resources](https://git.mandarynki.eu/maciej/prawo-jazdy-resources) by [maciej](https://git.mandarynki.eu/maciej), to better suit the needs of [nuxt-prawo-jazdy](https://git.mandarynki.eu/netman/nuxt-prawo-jazdy)
### Files summary ### Files summary
`main.py` is an _extremely_ badly-written script that reads files (`pytania.csv` and `punkty.csv`) shared by the Ministry of Infrastructure and imports them into a postgresql database `main.py` is a script that reads the file `pytania_z_punktacja_11_2025.csv` (it may change, depending on the age of the file and its outdatedness, but also sometimes the lack of [point value](placeholder_for_blog_post) ==> (blog post about such shenanigans in the future)) and imports it/them into a SQLite database file
- `db/pytania.csv` is the `katalog_pytania_egzminacyjne_kandydat__14112024.xlsx` file from [here](https://www.gov.pl/web/infrastruktura/prawo-jazdy) - `database.db` SQLite file filled with data from the file above
- `db/punkty.csv` isn't published by the Ministry, so you have to send a public information request to acquire it - we have received an XLSX - `pytania_z_punktacja_11_2025.csv` is the `pytania_egzaminacyjne_na_kierowcę_2025.xlsx` file converted to CSV (string delimiter `;`) from the website of the Polish Ministry of Infrastructure [here](https://www.gov.pl/attachment/a6fac2fd-8e2d-415b-8e65-49f903f8e433) - now the new file displayed at the main [driver's license page]() doesn't contain the point value as opposed to the one provided above, [in that case a writing to the Ministry is needed, asking for the public information of that value for each question](placeholder_for_blog_post) ==> (blog post about such shenanigans in the future)
both of them are converted to CSV
# Requirements # Requirements
- postgres server
- python3 - python3
- packages from requirements.txt (`pip install -r requirements.txt`) - tqdm
- files above (either already CSV'd from this repo or converted by yourself from official, most probably fresher sources)
## Running
Just run `python main.py` IN THE SAME DIRECTORY AS THE SCRIPT IS LOCATED IN.
- If needed, modify the CSV file name inside the script AND SET THE ROWS ACCORDINGLY.
- Also check if your CSV file has a header on its first row, the file provided in this repository does have one, hence the `next(reader)` command which skips the first row. If your script doesn't have such header, comment these lines out.
- If your CSV does not contain point values, contact the Ministry and get pairs of question IDs and their point values in CSV, then comment the lines below `## COMMENT OUT BELOW...` and above `## COMMENT OUT ABOVE`, and uncomment the lines below `## UNCOMMENT BELOW` and above `## UNCOMMENT ABOVE`
- Set rows accordingly.
- Also check if your point value CSV file has a header on its first row, the file provided in this repository does have one, hence the `next(reader)` command which skips the first row. If your script doesn't have such header, comment these lines out.
### Database structure ### Database structure
```sql ```sql
CREATE TABLE IF NOT EXISTS tasks ( CREATE TABLE IF NOT EXISTS tasks (
id integer NOT NULL, id INTEGER,
correct_answer character(5), correct_answer TEXT,
media_url text, media_url TEXT,
weight smallint weight INTEGER
); );
CREATE TABLE IF NOT EXISTS questions ( CREATE TABLE IF NOT EXISTS questions (
task_id integer, task_id INTEGER,
lang character(2), lang TEXT,
text text text TEXT
); );
CREATE TABLE IF NOT EXISTS tasks_advanced ( CREATE TABLE IF NOT EXISTS tasks_advanced (
id integer NOT NULL, id INTEGER,
correct_answer character(1), correct_answer TEXT,
media_url text, media_url TEXT,
weight smallint weight INTEGER
); );
CREATE TABLE IF NOT EXISTS questions_advanced ( CREATE TABLE IF NOT EXISTS questions_advanced (
task_id integer, task_id INTEGER,
lang character(2), lang TEXT,
text text, text TEXT,
answer_a text, answer_a TEXT,
answer_b text, answer_b TEXT,
answer_c text answer_c TEXT
); );
CREATE TABLE IF NOT EXISTS categories ( CREATE TABLE IF NOT EXISTS categories (
name text, name TEXT,
task_id integer task_id INTEGER
); );
``` ```
## Criteria ## Criteria
Categories are as such: Categories:
- A
- B
- C
- D
- T
- AM - AM
- A1 - A1
- A2 - A2
- A
- B1 - B1
- B
- C1 - C1
- C
- D1 - D1
- D
- T
- PT - PT
Languages as such: Languages as such:
- PL - PL
- EN - EN
- UA
- DE - DE
- UA
# Basic tasks query # Basic tasks query
@ -88,7 +91,12 @@ According to the Ministry of Infrastructure, in an exam there are (basic):
- 6 questions for 2 points - 6 questions for 2 points
- 10 questions for 3 points - 10 questions for 3 points
so NO_OF_QUESTIONS and WEIGHT_OF_QUESTIONS should be set accordingly to the requirements above (and of course set category & lang to your liking) Set below values accordingly to the requirements above or to your liking:
- NO_OF_QUESTIONS
- WEIGHT_OF_QUESTIONS
- LANG
- CATEGORY
```sql ```sql
SELECT SELECT
@ -101,8 +109,8 @@ FROM tasks
LEFT JOIN questions ON tasks.id = questions.task_id LEFT JOIN questions ON tasks.id = questions.task_id
LEFT JOIN categories ON tasks.id = categories.task_id LEFT JOIN categories ON tasks.id = categories.task_id
WHERE WHERE
categories.name = 'B' AND categories.name = CATEGORY AND
questions.lang = 'PL' AND questions.lang = LANG AND
tasks.weight = WEIGHT_OF_QUESTIONS tasks.weight = WEIGHT_OF_QUESTIONS
ORDER BY random() ORDER BY random()
LIMIT (NO_OF_QUESTIONS); LIMIT (NO_OF_QUESTIONS);
@ -116,7 +124,12 @@ According to the Ministry of Infrastructure, in an exam there are (advanced):
- 4 questions for 2 points - 4 questions for 2 points
- 6 questions for 3 points - 6 questions for 3 points
so NO_OF_QUESTIONS and WEIGHT_OF_QUESTIONS should be set accordingly to the requirements above (and of course set category & lang to your liking) Set below values accordingly to the requirements above or to your liking:
- NO_OF_QUESTIONS
- WEIGHT_OF_QUESTIONS
- LANG
- CATEGORY
```sql ```sql
SELECT SELECT
@ -132,8 +145,8 @@ FROM tasks_advanced
LEFT JOIN questions_advanced ON tasks_advanced.id = questions_advanced.task_id LEFT JOIN questions_advanced ON tasks_advanced.id = questions_advanced.task_id
LEFT JOIN categories ON tasks_advanced.id = categories.task_id LEFT JOIN categories ON tasks_advanced.id = categories.task_id
WHERE WHERE
categories.name = 'B' AND categories.name = CATEGORY AND
questions_advanced.lang = 'PL' AND questions_advanced.lang = LANG AND
tasks_advanced.weight = WEIGHT_OF_QUESTIONS tasks_advanced.weight = WEIGHT_OF_QUESTIONS
ORDER BY random() ORDER BY random()
LIMIT (NO_OF_QUESTIONS); LIMIT (NO_OF_QUESTIONS);

BIN
database.db Normal file

Binary file not shown.

139
main.py
View file

@ -1,113 +1,120 @@
import csv, psycopg2, pwinput import csv
from tqdm import tqdm from tqdm import tqdm
import sqlite3
host = input('host: ') conn = sqlite3.connect('./database.db')
user = input('user: ')
password = pwinput.pwinput(prompt='password: ')
dbname = input('dbname: ')
port = int(input('port: '))
conn = psycopg2.connect(host=host, user=user, password=password, dbname=dbname, port=port)
cur = conn.cursor() cur = conn.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS tasks (id integer NOT NULL, correct_answer character(5), media_url text, weight smallint);') cur.execute('CREATE TABLE IF NOT EXISTS tasks (id INTEGER, correct_answer TEXT, media_url TEXT, weight INTEGER);')
cur.execute('CREATE TABLE IF NOT EXISTS questions (task_id integer, lang character(2), text text);') cur.execute('CREATE TABLE IF NOT EXISTS questions (task_id INTEGER, lang TEXT, text TEXT);')
cur.execute('CREATE TABLE IF NOT EXISTS tasks_advanced (id integer NOT NULL, correct_answer character(1), media_url text, weight smallint);') cur.execute('CREATE TABLE IF NOT EXISTS tasks_advanced (id INTEGER, correct_answer TEXT, media_url TEXT, weight INTEGER);')
cur.execute('CREATE TABLE IF NOT EXISTS questions_advanced (task_id integer, lang character(2), text text, answer_a text, answer_b text, answer_c text);') cur.execute('CREATE TABLE IF NOT EXISTS questions_advanced (task_id INTEGER, lang TEXT, text TEXT, answer_a TEXT, answer_b TEXT, answer_c TEXT);')
cur.execute('CREATE TABLE IF NOT EXISTS categories (name text, task_id integer);') cur.execute('CREATE TABLE IF NOT EXISTS categories (name TEXT, task_id INTEGER);')
cur.execute('TRUNCATE TABLE tasks;') cur.execute('DELETE FROM tasks;')
cur.execute('TRUNCATE TABLE questions;') cur.execute('DELETE FROM questions;')
cur.execute('TRUNCATE TABLE categories;') cur.execute('DELETE FROM categories;')
cur.execute('TRUNCATE TABLE tasks_advanced;') cur.execute('DELETE FROM tasks_advanced;')
cur.execute('TRUNCATE TABLE questions_advanced;') cur.execute('DELETE FROM questions_advanced;')
with open('pytania.csv') as file: with open('./pytania_z_punktacja_11_2025.csv') as file:
reader = csv.reader(file, delimiter=';') reader = csv.reader(file, delimiter=';')
next(reader)
for row in tqdm(reader): for row in tqdm(reader):
numer = row[0] numer = row[1]
pytanie_pl = row[1] pytanie_pl = row[2]
odp_a_pl = row[2] odp_a_pl = row[3]
odp_b_pl = row[3] odp_b_pl = row[4]
odp_c_pl = row[4] odp_c_pl = row[5]
poprawna_odp = row[5] poprawna_odp = row[6]
media = row[6] media = row[7]
kategorie = row[7] pkt = row[9]
pjm_pytanie = row[8] kategorie = row[10]
pjm_odp_a = row[9] # pjm_pytanie = row[11]
pjm_odp_b = row[10] # pjm_odp_a = row[12]
pjm_odp_c = row[11] # pjm_odp_b = row[13]
pytanie_en = row[12] # pjm_odp_c = row[14]
odp_a_en = row[13] pytanie_en = row[15]
odp_b_en = row[14] odp_a_en = row[16]
odp_c_en = row[15] odp_b_en = row[17]
pytanie_de = row[16] odp_c_en = row[18]
odp_a_de = row[17] pytanie_de = row[19]
odp_b_de = row[18] odp_a_de = row[20]
odp_c_de = row[19] odp_b_de = row[21]
pytanie_ua = row[20] odp_c_de = row[22]
odp_a_ua = row[21] pytanie_ua = row[23]
odp_b_ua = row[22] odp_a_ua = row[24]
odp_c_ua = row[23] odp_b_ua = row[25]
odp_c_ua = row[26]
categories = kategorie.split(',') categories = kategorie.split(',')
task_id = int(numer) task_id = int(numer)
if numer and pytanie_pl and poprawna_odp and kategorie and not odp_a_pl and not odp_b_pl and not odp_c_pl: if numer and pytanie_pl and poprawna_odp and kategorie and not odp_a_pl and not odp_b_pl and not odp_c_pl:
if poprawna_odp == 'Tak': if poprawna_odp == 'T':
correct_answer = 'true' correct_answer = "true"
elif poprawna_odp == 'Nie': elif poprawna_odp == 'N':
correct_answer = 'false' correct_answer = "false"
else: else:
raise Exception('Error, an answer to a basic question does not equal "Tak" or "Nie", check the pytania.csv file for anomaly in poprawna_odp section') raise Exception(f'Wystąpił problem, odpowiedź dla pytania {numer} jest niejasna. Poprawna odpowiedź to {poprawna_odp}...')
cur.execute('INSERT INTO tasks (id, correct_answer, media_url) VALUES (%s, %s, %s)', cur.execute('INSERT INTO tasks (id, correct_answer, media_url) VALUES (?, ?, ?)',
(task_id, correct_answer, media)) (task_id, correct_answer, media))
cur.execute('INSERT INTO questions(task_id, lang, text) VALUES (%s, %s, %s)', cur.execute('INSERT INTO questions(task_id, lang, text) VALUES (?, ?, ?)',
(task_id, 'PL', pytanie_pl)) (task_id, 'PL', pytanie_pl))
if pytanie_en: if pytanie_en:
cur.execute('INSERT INTO questions(task_id, lang, text) VALUES (%s, %s, %s)', cur.execute('INSERT INTO questions(task_id, lang, text) VALUES (?, ?, ?)',
(task_id, 'EN', pytanie_en)) (task_id, 'EN', pytanie_en))
if pytanie_de: if pytanie_de:
cur.execute('INSERT INTO questions(task_id, lang, text) VALUES (%s, %s, %s)', cur.execute('INSERT INTO questions(task_id, lang, text) VALUES (?, ?, ?)',
(task_id, 'DE', pytanie_de)) (task_id, 'DE', pytanie_de))
if pytanie_ua: if pytanie_ua:
cur.execute('INSERT INTO questions(task_id, lang, text) VALUES (%s, %s, %s)', cur.execute('INSERT INTO questions(task_id, lang, text) VALUES (?, ?, ?)',
(task_id, 'UA', pytanie_ua)) (task_id, 'UA', pytanie_ua))
if numer and pytanie_pl and poprawna_odp and kategorie and odp_a_pl and odp_b_pl and odp_c_pl: if numer and pytanie_pl and poprawna_odp and kategorie and odp_a_pl and odp_b_pl and odp_c_pl:
cur.execute('INSERT INTO tasks_advanced(id, correct_answer, media_url) VALUES (%s, %s, %s)', cur.execute('INSERT INTO tasks_advanced(id, correct_answer, media_url) VALUES (?, ?, ?)',
(task_id, poprawna_odp, media)) (task_id, poprawna_odp, media))
cur.execute('INSERT INTO questions_advanced(task_id, lang, text, answer_a, answer_b, answer_c) VALUES (%s, %s, %s, %s, %s, %s)', cur.execute('INSERT INTO questions_advanced(task_id, lang, text, answer_a, answer_b, answer_c) VALUES (?, ?, ?, ?, ?, ?)',
(task_id, 'PL', pytanie_pl, odp_a_pl, odp_b_pl, odp_c_pl)) (task_id, 'PL', pytanie_pl, odp_a_pl, odp_b_pl, odp_c_pl))
if odp_a_en and odp_b_en and odp_c_en: if odp_a_en and odp_b_en and odp_c_en:
cur.execute('INSERT INTO questions_advanced(task_id, lang, text, answer_a, answer_b, answer_c) VALUES (%s, %s, %s, %s, %s, %s)', cur.execute('INSERT INTO questions_advanced(task_id, lang, text, answer_a, answer_b, answer_c) VALUES (?, ?, ?, ?, ?, ?)',
(task_id, 'EN', pytanie_en, odp_a_en, odp_b_en, odp_c_en)) (task_id, 'EN', pytanie_en, odp_a_en, odp_b_en, odp_c_en))
if odp_a_de and odp_b_de and odp_c_de: if odp_a_de and odp_b_de and odp_c_de:
cur.execute('INSERT INTO questions_advanced(task_id, lang, text, answer_a, answer_b, answer_c) VALUES (%s, %s, %s, %s, %s, %s)', cur.execute('INSERT INTO questions_advanced(task_id, lang, text, answer_a, answer_b, answer_c) VALUES (?, ?, ?, ?, ?, ?)',
(task_id, 'DE', pytanie_de, odp_a_de, odp_b_de, odp_c_de)) (task_id, 'DE', pytanie_de, odp_a_de, odp_b_de, odp_c_de))
if odp_a_ua and odp_b_ua and odp_c_ua: if odp_a_ua and odp_b_ua and odp_c_ua:
cur.execute('INSERT INTO questions_advanced(task_id, lang, text, answer_a, answer_b, answer_c) VALUES (%s, %s, %s, %s, %s, %s)', cur.execute('INSERT INTO questions_advanced(task_id, lang, text, answer_a, answer_b, answer_c) VALUES (?, ?, ?, ?, ?, ?)',
(task_id, 'UA', pytanie_ua, odp_a_ua, odp_b_ua, odp_c_ua)) (task_id, 'UA', pytanie_ua, odp_a_ua, odp_b_ua, odp_c_ua))
for category in categories: for category in categories:
cur.execute('INSERT INTO categories(name, task_id) VALUES (%s, %s)', cur.execute('INSERT INTO categories(name, task_id) VALUES (?, ?)',
(category, task_id)) (category, task_id))
## COMMENT OUT BELOW IF POINT VALUES ARE NOT IN YOUR CSV
if numer and pytanie_pl and poprawna_odp and kategorie:
cur.execute('UPDATE tasks SET weight=? WHERE id=?', (pkt, numer))
cur.execute('UPDATE tasks_advanced SET weight=? WHERE id=?', (pkt, numer))
## COMMENT OUT ABOVE IF POINT VALUES ARE NOT IN YOUR CSV
with open('punkty.csv') as file:
reader = csv.reader(file, delimiter=';') ## UNCOMMENT BELOW IF POINT VALUES ARE IN ANOTHER CSV
for row in tqdm(reader): # with open('punkty.csv') as file:
numer = int(row[0]) # reader = csv.reader(file, delimiter=';')
punkty = int(row[1]) # next(reader)
cur.execute('UPDATE tasks SET weight=%s WHERE id=%s', (punkty, numer)) # for row in tqdm(reader):
cur.execute('UPDATE tasks_advanced SET weight=%s WHERE id=%s', (punkty, numer)) # numer = int(row[0])
# punkty = int(row[1])
# cur.execute('UPDATE tasks SET weight=? WHERE id=?', (punkty, numer))
# cur.execute('UPDATE tasks_advanced SET weight=? WHERE id=?', (punkty, numer))
## UNCOMMENT BELOW IF POINT VALUES ARE IN ANOTHER CSV
cur.execute('SELECT COUNT(id) FROM tasks') cur.execute('SELECT COUNT(id) FROM tasks')

3392
punkty.csv

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1 @@
tqdm tqdm
psycopg2-binary
pwinput
csv