<commit_before>from optparse import make_option
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from django.template.defaultfilters import slugify

import os
import timeside.core
from timeside.server.models import *
from timeside.core.tools.test_samples import generateSamples
from telemeta.models import *
from telemeta.util.unicode import *


class Command(BaseCommand):
    help = "Export all items or collections metadata to a CSV file"

    def handle(self, *args, **options):
        path = args[-1]
        element_type = args[-2]
        f = open(path, 'w')
        if element_type == "item":
            elements = MediaItem.objects.all()
        elif element_type == "collection":
            elements = MediaCollection.objects.all()
        else:
            raise TypeError('type should be "item" or "collection"')
        writer = UnicodeWriter(f)
        csv = CSVExport(writer)
        csv.write(elements)
        f.close()<commit_msg>fix dump order<commit_after>from optparse import make_option
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from django.template.defaultfilters import slugify

import os
import timeside.core
from timeside.server.models import *
from timeside.core.tools.test_samples import generateSamples
from telemeta.models import *
from telemeta.util.unicode import *


class Command(BaseCommand):
    help = "Export all items or collections metadata to a CSV file"

    def handle(self, *args, **options):
        path = args[-1]
        element_type = args[-2]
        f = open(path, 'w')
        if element_type == "item":
            elements = MediaItem.objects.all().order_by('id')
        elif element_type == "collection":
            elements = MediaCollection.objects.all().order_by('id')
        else:
            raise TypeError('type should be "item" or "collection"')
        writer = UnicodeWriter(f)
        csv = CSVExport(writer)
        csv.write(elements)
        f.close()
{'fraction_non_alphanumeric': 0.09335219236209336, 'fraction_numerical': 0.001885902876001886, 'mean_word_length': 3.168958742632613, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1460310', 'n_tokens_mistral': 585, 'n_tokens_neox': 560, 'n_words': 173}