File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed
Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Release
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*.*.*'
7+
8+ jobs :
9+ build :
10+ runs-on : ubuntu-latest
11+ steps :
12+ - uses : actions/checkout@v2
13+ - name : copy sources
14+ run : |
15+ mkdir -p .debpkg/usr/bin
16+ cp src/csvToJson.py .debpkg/usr/bin
17+ chmod 755 .debpkg/usr/bin/csvToJson.py
18+ - uses : jiro4989/build-deb-action@v3
19+ with :
20+ package : sesame-csvtojson
21+ package_root : .debpkg
22+ maintainer : Libertech
23+ version : ${{ github.ref }} # refs/tags/v*.*.*
24+ depends : ' phyton3'
25+ desc : ' convert csv to json'
26+ homepage : ' https://github.com/Libertech-FR/sesame-csvtojson'
27+ - uses : svenstaro/upload-release-action@v2
28+ with :
29+ repo_token : ${{ secrets.GITHUB_TOKEN }}
30+ file : sesame*
31+ overwrite : true
32+ file_glob : true
33+
Original file line number Diff line number Diff line change 11# sesame-csvtojson
22convert csv file to json for sesame-crawler
3+
4+ ## Usage
5+ ```
6+ csvToJson.py --csv=CSVFILE --json=JSONFILE
7+ ```
8+
9+ ```
10+ csvToJson.py --csv=CSVFILE --json=JSONFILE --delimiter=FILEDELIMITER --linedelimiter=LINEDELIMITER
11+ ```
12+
13+ ## Exemple
14+
15+ ```
16+ csvToJson.py --csv=monimport.csv --json=import/cache/import.json --delimiter=";" --linedelimiter="\n"
17+ ```
18+
Original file line number Diff line number Diff line change 1+ #!/usr/bin/python3
2+ import json
3+ import csv
4+ import argparse
5+
6+
7+ def main ():
8+ parser = argparse .ArgumentParser ()
9+ parser .add_argument ('--csv' , help = 'Csv File' )
10+ parser .add_argument ('--json' , help = 'output json file ' )
11+ parser .add_argument ('--separator' , help = 'Separator' ,default = ";" )
12+ parser .add_argument ('--lineseparator' , help = 'Line separator' , default = "\n " )
13+ args = parser .parse_args ()
14+ csv_to_json (args )
15+
16+
17+ def csv_to_json (args ):
18+ data = {}
19+ with open (args .csv , encoding = 'utf-8' ) as file_handler :
20+ reader = csv .DictReader (file_handler , delimiter = args .separator , lineterminator = args .lineseparator )
21+ data = [row for row in reader ]
22+ with open (args .json , 'w' ) as jsonfile :
23+ data1 = {
24+ 'data' : data
25+ }
26+ json .dump (data1 , jsonfile ,indent = 4 )
27+
28+
29+ if __name__ == '__main__' :
30+ main ()
You can’t perform that action at this time.
0 commit comments