googleSheetConvert.py
1 | #!/usr/bin/env python
|
---|---|
2 | #Converts a Google Spreadsheet that's been downloaded in CSV
|
3 | #format to Redmine's table format. The output is sent to STDOUT.
|
4 | #File: googleSheetConvert.py
|
5 | #License: Apache 2.0
|
6 | |
7 | import sys |
8 | |
9 | #Check to make sure we got the right number of arguments
|
10 | if (len(sys.argv) == 2): |
11 | #Assume that the file name is the 1st argument (no checks)
|
12 | fileName = sys.argv[1]
|
13 | else:
|
14 | print "Usage: googleSheetConvert.py CSV_FILE" |
15 | quit() |
16 | |
17 | #Line counter variable
|
18 | lineCounter = 0
|
19 | |
20 | #Holds the edited line
|
21 | editedLine = ""
|
22 | |
23 | #Step through the lines of the file
|
24 | with open(fileName) as f: |
25 | for line in f: |
26 | #Check to see if this is the first (header) line
|
27 | if (lineCounter == 0): |
28 | #Make sure the headers end up in bold
|
29 | editedLine = line.replace(",", "|_.") |
30 | |
31 | #Mark the beginning and the end of the line
|
32 | editedLine = "|_." + editedLine
|
33 | editedLine = editedLine.replace("\n", "|") |
34 | |
35 | print editedLine
|
36 | else:
|
37 | #Delimit the columns
|
38 | editedLine = line.replace(",", "|") |
39 | |
40 | #Mark the beginning and end of the line
|
41 | editedLine = "|" + editedLine
|
42 | editedLine = editedLine.replace("\n", "|") |
43 | |
44 | print editedLine
|
45 | |
46 | lineCounter += 1
|