@@ -0,0 +1,1572 @@
+#!/usr/bin/env python3%0A%0A%22%22%22Dump all maps with the snapshot in a directory strucre:%0A%0Atopics_id%0A    focal_set%0A        focus%0A            period%0A                start_date%0A                    map%0A%22%22%22%0A%0Aimport os%0Aimport sys%0A%0Aimport mediawords.db%0A%0Afrom mediawords.util.log import create_logger%0A%0Alog = create_logger(__name__)%0A%0Adef main():%0A    if len(sys.argv) %3C 2:%0A        raise Error(%22usage: dump_topic_maps.py %3Csnapshots_id%3E%22);%0A%0A    snapshots_id = sys.argv%5B1%5D%0A%0A    db = mediawords.db.connect_to_db()%0A%0A    snapshot = db.require_by_id('snapshots', snapshots_id)%0A%0A    timespan_maps = db.query(%0A        %22%22%22%0A        select %0A                t.*,%0A                tm.*,%0A                f.name focus_name, fs.name focal_set_name%0A            from timespans t%0A                join timespan_maps tm using ( timespans_id )%0A                left join foci f using ( foci_id )%0A                left join focal_sets fs using ( focal_sets_id )%0A            where t.snapshots_id = %25(a)s%0A        %22%22%22,%0A        %7B'a': snapshots_id%7D%0A    ).hashes()%0A%0A    for tm in timespan_maps:%0A        filename = %22%25s.%25s%22 %25 (tm%5B'options'%5D.get('color_by', 'default'), tm%5B'format'%5D)%0A        directory = '%25d/%25s/%25s/%25s/%25s' %25 ( %0A            snapshot%5B'topics_id'%5D,%0A            tm%5B'focal_set_name'%5D,%0A            tm%5B'focus_name'%5D,%0A            tm%5B'period'%5D,%0A            tm%5B'start_date'%5D%5B0:10%5D,%0A        )%0A%0A        os.makedirs(directory, exist_ok=True)%0A%0A        full_path = %22%25s/%25s%22 %25 (directory, filename)%0A%0A        log.warning(%22writing %25s...%22 %25 full_path)%0A%0A        f = open(full_path, 'wb')%0A%0A        f.write(tm%5B'content'%5D)%0A%0A%0Amain()%0A%0A

add dump_maps.py