Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to export all final Markdown translations #12

Open
fushar opened this issue Oct 19, 2022 · 2 comments
Open

Add functionality to export all final Markdown translations #12

fushar opened this issue Oct 19, 2022 · 2 comments

Comments

@fushar
Copy link
Member

fushar commented Oct 19, 2022

After a contest day ends, we want to be able to export the final Markdown translations. One reason is to allow the team leaders to reuse the Notice translation in Day 2. Another reason is for general task archiving purpose.

It is not easy to do this from the UI. As a workaround, @sijie123 came up with a quick script for IOI 2022. The script is posted here as-is for posterity / reference for next years if this functionality is not built yet 😄

two parts: one sql to get the latest version per team per task and dump to csv, and one python3 to take the dumped csv and write into individual files

psql
\c translationdatabase

COPY ( 
    WITH data AS (
        SELECT trans_version.*,trans_task.name,trans_country.code2,trans_user.language_id
        FROM trans_version
        INNER JOIN trans_translation
            ON trans_version.translation_id = trans_translation.id
        INNER JOIN trans_task 
            ON trans_translation.task_id = trans_task.id
        INNER JOIN trans_user
            ON trans_translation.user_id = trans_user.user_ptr_id
        INNER JOIN trans_country 
            ON trans_user.country_id = trans_country.code
    )
    SELECT a.*
    FROM data a
    INNER JOIN (
        SELECT MAX(id) as maxid
        FROM trans_version
        GROUP BY translation_id
    ) AS b ON a.id=b.maxid
) TO '/tmp/test.csv' WITH DELIMITER ',' CSV HEADER;
mkdir -p /tmp/sj
cd /tmp/sj

vim quick.py

import csv
with open('/tmp/test.csv', 'r') as f:
  spamreader = csv.DictReader(f, delimiter=',')
  for row in spamreader:
    with open(f"/tmp/sj/{row['name']}_{row['country_id']}.md", "w") as x:
        x.write(row['text'])

python3 quick.py
@fushar
Copy link
Member Author

fushar commented Oct 19, 2022

An attempt to implement this: ioi-2022#67, feel free for anyone to build on this.

@gollux
Copy link
Member

gollux commented Aug 28, 2024

The "refresh" branch adds support for ./manage.py export.

I will close this issue when the branch is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants