Esempio n. 1
0
    def export_to_file(filename):
        fieldnames = ['card_id', 'image_id']

        with open(filename, 'wb') as file:
            writer = csv_utf.UnicodeWriter(file)
            writer.writerow(fieldnames)
            session = DBSession()
            images = [[cards_image.card_id, cards_image.image_id]
                      for cards_image in session.query(CardsImages).order_by(
                          CardsImages.card_id, CardsImages.image_id).all()]
            session.close()
            writer.writerows(images)
Esempio n. 2
0
    def export_to_file(filename):
        fieldnames = ['id', 'name', 'description', 'url', 'local', 'size']

        with open(filename, 'wb') as file:
            writer = csv_utf.UnicodeWriter(file)
            writer.writerow(fieldnames)
            session = DBSession()
            images = [[
                image.id, image.name, image.description, image.url,
                image.local, image.size
            ] for image in session.query(Images).order_by(Images.id).all()]
            session.close()
            writer.writerows(images)
Esempio n. 3
0
def update_csv(initial_data_dir_name):
    from nextgisbio.utils import csv_utf
    for csv_file_name, new_csv_data in data.iteritems():
        csv_path = path.join(initial_data_dir_name, csv_file_name)
        with open(csv_path, "w"):
            pass
        with open(csv_path, 'wb') as csv_file:
            writer = csv_utf.UnicodeWriter(csv_file)

            for new_csv_data_row in new_csv_data:
                writer.writerow(new_csv_data_row)

            print '%s updated successfully.' % csv_file_name
Esempio n. 4
0
    def export_to_file(filename):
        from nextgisbio.utils import csv_utf

        fieldnames = Cards.get_all_fields_names()

        with open(filename, 'wb') as file:
            writer = csv_utf.UnicodeWriter(file)
            writer.writerow(fieldnames)

            dbsession = DBSession()

            cards = [
                card.to_row()
                for card in dbsession.query(Cards).order_by(Cards.id).all()
            ]
            dbsession.close()
            writer.writerows(cards)
Esempio n. 5
0
    def export_to_file(filename):
        fieldnames = ['id', 'species', 'inserter', 'key_area', 'identifier', 'collecter',
                'biblioref',
                'original_name', 'location', 'lon', 'lat',
                'biotop', 'difference', 'substrat', 'status',
                'frequency', 'quantity', 'annotation',
                'infosourse', 'year', 'month', 'day', 'exposure']
        
        with open(filename, 'wb') as file:
            writer = csv_utf.UnicodeWriter(file)
            writer.writerow(fieldnames)
        
            dbsession = DBSession()
            
            annotations = [[ann.id, ann.species, ann.inserter, ann.key_area, ann.identifier, ann.collecter,
                ann.biblioref,
                ann.original_name, ann.location, ann.lon, ann.lat,
                ann.biotop, ann.difference, ann.substrat, ann.status,
                ann.frequency, ann.quantity, ann.annotation,
                ann.infosourse, ann.year, ann.month, ann.day, ann.exposure] for ann in
                           dbsession.query(Annotation).order_by(Annotation.id).all()]

            writer.writerows(annotations)
Esempio n. 6
0
def dump(filename, attributes, objects, fieldnames=None, is_array=False):
    from nextgisbio.utils import csv_utf

    with open(filename, 'wb') as file:
        writer = csv_utf.UnicodeWriter(file)

        if fieldnames:
            writer.writerow(fieldnames)
        else:
            writer.writerow(attributes)

        if is_array:
            writer.writerows(objects)
            return

        object_rows = []
        for object in objects:
            object_as_array = []
            for attribute_name in attributes:
                object_as_array.append(getattr(object, attribute_name))
            object_rows.append(object_as_array)

        writer.writerows(object_rows)