• Stars
    star
    209
  • Rank 188,325 (Top 4 %)
  • Language
    Python
  • Created about 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sublime Text package for converting CSV data to other formats

Sublime DataConverter

This Sublime Text package converts csv files to various other formats. It's been adapted from the wonderful Mr. Data Converter.

After installing, you'll find commands look like DataConverter: to foo in the Command Palette. DataConverter will convert a selection or multiple selections. If nothing is selected, the entire document is converted.

Examples

Turn this:

name,value,fruit,date
Alice,10,Apple,"Sep. 12, 2016"
Bob,11,Blueberry,"Sep. 13, 2016"
Chris,12,Orange,"Sep. 14, 2016"

into this (Ruby):

[{"name"=>"Alice", "value"=>10, "fruit"=>"Apple", "date"=>"Sep. 12, 2016"},
{"name"=>"Bob", "value"=>11, "fruit"=>"Blueberry", "date"=>"Sep. 13, 2016"},
{"name"=>"Chris", "value"=>12, "fruit"=>"Orange", "date"=>"Sep. 14, 2016"}];

or this (JSON):

[
  {"fruit": "Apple", "name": "Alice", "value": "10", "date": "Sep. 12, 2016"},
  {"fruit": "Blueberry", "name": "Bob", "value": "11", "date": "Sep. 13, 2016"},
  {"fruit": "Orange", "name": "Chris", "value": "12", "date": "Sep. 14, 2016"}
]

Formats supported

  • ActionScript
  • ASP
  • HTML tables
  • Gherkin
  • JIRA (Atlassian Confluence)
  • JSON
  • JSON (array of columns)
  • JSON (array of rows)
  • JSON (object, first column is key)
  • Javascript object
  • Markdown (Github-flavored)
  • Perl
  • PHP (two formats)
  • Python (list of dicts)
  • Python (list of lists)
  • Ruby
  • SQL (Postgres, MySQL and SQLite)
  • text table
  • Wiki markup
  • XML
  • XML (property list)
  • XML for data-driven Adobe Illustrator
  • YAML

Additionally, DataConverter can convert between delimiters. By default, this includes commands to convert to CSV and TSV, and it's possible to add your own delimiter (create a User.sublime-commands file following the pattern in DataConverter.sublime-commands).

Installation

With Package Control

If you have Package Control installed, you can install DataConverter from within Sublime Text. Open the Command Palette and enter "Package Control: Install Package", then search for DataConverter.

Without Package Control

Clone the repository into your Sublime Text packages directory:

git clone git://github.com/fitnr/SublimeDataConverter.git

Without Package Control or Git

Click Download Zip above to download the package. Unzip it, rename the folder "DataConverter" and move it into your Sublime Text 2 packages directory (Preferences > Browse Packages in the application menu).

Limitations

CSV containing Unicode characters aren't supported in the Sublime Text 2 version of the package. This is due to limitations in the Python 2.6 csv module. Unicode is fully supported in the Sublime Text 3 version of the package.

Problems?

Submit an issue.

Contributing

Pull requests with additional formats are encouraged.

Configuration

DataConverter reads the following options from your settings file (Preferences > Package Settings > DataConverter > Settings - User).

headers

Possible values: "sniff", true, or false.

"headers": "sniff"

When true, the first row is always treated as the header row. When "sniff", DataConverter will sniff for headers (sniffing isn't perfect). When false, DataConverter will assume there are no headers, and use default headers ([val1, val2, ...]).

dialects

Object

"dialects": {
  "example": {
    "delimiter": ",",
    "quotechar": "\"",
    "escapechar": "\\",
    "doublequote": false
    "skipinitialspace": false,
    "strict": false,
    "quoting": "QUOTE_MINIMAL"
  }
}

Defines a dialect for the CSV reader. Check the python docs for a description of how to define a dialect.

DataConverter will try to detect a dialect, but it may fail. Define a dialect with this setting and then tell DataConverter to use it with the use_dialect option.

Note that Python's csv reader is hard-coded to recognise either '\r' or '\n' as end-of-line, and ignores lineterminator.

use_dialect

String

"use_dialect": "example"

Mandate a dialect for DataConverter to use. Could be a dialect defined in your settings file, or one defined in the csv module ("excel", "excel_tab", "unix_dialect"). This may be useful for specifying custom commands in a .sublime-commands file.

html_utf8

Boolean

"html_utf8": true

Modern HTML served with a proper character encoding can accept UTF-8 characters. If you're using another charset for your html, set this to false. When false, the 'DataConverter: to HTML Table' function will escape non-ascii characters (e.g. – for –). (XML is always returned with escaped characters.)

delimiter

Character

"delimiter": ","

DataConverter will try to detect the delimiter used in your data. If it has a problem, it will fall back on this value. This must be one character long. Use "\t" for tab.

header_joiner

String

"header_joiner": "_"

For formats where keys can't have spaces, field names will be joined with this character. By default, an underscore is used, e.g. 'Col Name' becomes 'Col_Name'. An empty string is OK.

deselect_after

Boolean

"deselect_after": false

If true: after converting, deselects and moves the pointer to the top. If false: leaves selection(s) in place

default_variable

"default_variable": "DataConverter"

For some conversions (SQL, ASP), DataConverter must name the table or array being created. By default, it's called 'DataConverter', any string value is accepted.

More Repositories

1

svgis

Draw SVG maps with geodata
Python
84
star
2

sqlite-json

Node module for converting Sqlite3 tables to JSON
JavaScript
81
star
3

everylotbot

Create Twitter bots that post Google Streetview pictures of a property database
Python
80
star
4

censusgeocode

Python wrapper for the US Census Geocoder
Python
72
star
5

acris-download

Download NYC real estate transaction data and drop it in a database
Makefile
62
star
6

twitter_markov

Create markov chain ("_ebooks") accounts on Twitter
Python
59
star
7

convertdate

Utils for converting between date formats and calculating holidays
Python
47
star
8

mxd2qgs

Python script for converting ArcGIS .mxd files to QGIS. Not under development
Python
43
star
9

twitter_bot_utils

Python utilities to make it a little easier to set up and run a Twitter bot
Python
42
star
10

visvalingamwyatt

Python simplication of geodata
Python
42
star
11

addfips

Add state and county fips codes to data
Python
42
star
12

get-tiger

Make workflow for downloading Census geodata and joining it to survey data
Makefile
38
star
13

SublimeCSSTidy

Sublime Text package for tidying CSS.
HTML
26
star
14

buoyant

Grab data from buoys around the world
Python
22
star
15

stateplane

Convert between state plane coordinate systems and long/lat
Python
21
star
16

osm-tiny-maps

Download slices of OSM data and create similarly-scaled svg/png/eps graphics from the data
Makefile
11
star
17

unwiki

Python module to remove wiki markup text.
Python
11
star
18

getfars

load FARS data on fatal traffic crashes from the NHTSA into a PostgreSQL database
Makefile
10
star
19

nycre

Download and pre-process NYC real estate sales date
Makefile
10
star
20

taft

Generate static html files from Handlebars files with YAML front matter
JavaScript
10
star
21

census2dbf

Convert US Census CSV files into DBFs
Python
10
star
22

twittergeo

Download geotagged tweets into GeoJSON
Python
9
star
23

portolan

Convert between compass points and degrees
Python
6
star
24

yaml-cat

Concatenate YAML front matter from several files into one object
JavaScript
6
star
25

savi-750

Course guide and syllabus for Mining the Web (Fall 2018)
JavaScript
5
star
26

rentregulated

Database of rent regulated buildings in New York state
Python
5
star
27

whatsupbot

What's up with your bots?
Python
4
star
28

get-pluto

download and summaries NYC property data
Makefile
4
star
29

fleetmonger

wrapper for the fleetmon.com ship tracking API
Python
4
star
30

censusname

Generate random names. Use any data, US Census data included by default
Python
4
star
31

tidetable

Thin Python wrapper for working with NOAA tide prediction tables
Python
4
star
32

cta-bus-archive

archiving cta bus data
Python
3
star
33

breaks

Add data classes to geodata files on the command line
Python
3
star
34

transitfeeds-api

Python wrapper for the transitfeeds.com API
Python
3
star
35

polyencoder

Encode geometries Google polyencoder style
Python
3
star
36

fionautil

helpful utilities for working with geodata with Fiona
Python
3
star
37

nyc-bus-gtfs

download MTA GTFS and load into an SQL database
Shell
2
star
38

imagebotkit

kit for building a twitter bot that bosts images
Python
2
star
39

glob-concat

Merge a mixed list of files and globs into a list of files.
JavaScript
2
star
40

sheetstack

Combine multiple XLS/X sheets into a single CSV
JavaScript
1
star
41

acronymlister

Python
1
star
42

alignschema

Use a CSV to align the schema of many data layers with ogr2ogr
Python
1
star
43

avroll-download

download the NYC assessed value roll into your very own MySQL db
Makefile
1
star
44

tiger-geocoder-loader

Makefile adaptation of PostGIS Tiger geocoder loading scripts
Makefile
1
star
45

state-generator

JavaScript
1
star