Skip to content

Commit

Permalink
feat: align columns in csv with json
Browse files Browse the repository at this point in the history
  • Loading branch information
kshychko committed Feb 13, 2024
1 parent 3daf7f2 commit 9db5053
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## Code List
<!-- Leave only the code list recommendation this PR is related to -->
[Recommendation No. 20 Codes for Units of Measure Used in International Trade](https://github.com/uncefact/vocab-codes/tree/main/CLR/Rec20)
[Recommendation No. 21 Codes for Passengers, Types of Cargo, Packages and Packaging Materials](https://github.com/uncefact/vocab-codes/tree/main/CLR/Rec21)
[Recommendation No. 23 Freight Cost Code (FCC)](https://github.com/uncefact/vocab-codes/tree/main/CLR/Rec23)
[Recommendation No. 24 Trade and Transport Status Codes](https://github.com/uncefact/vocab-codes/tree/main/CLR/Rec24)
[Recommendation No. 28 Codes for Types of Means of Transport](https://github.com/uncefact/vocab-codes/tree/main/CLR/Rec28)

## Maintenance Request issue
<!--- Specify the GitHub issue number with original Maintenance Request after '#' -->
<!--- Specify the GitHub issue(s) number with original Maintenance Request after '#' -->
Ref #{issue_number}

### Mentions:
Expand Down
32 changes: 32 additions & 0 deletions CLR/Rec20/csv_to_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import csv
import json

def csv_to_json(csvFilePath, jsonFilePath):
data = {}
data["label"] = "Recommendation Code List 20"
data["uri"] = "rec20"
data["comment"] = "CODES FOR UNITS OF MEASURE USED IN INTERNATIONAL TRADE"
values = []

#read csv file
with open(csvFilePath, encoding='utf-8') as csvf:
#load csv file data using csv library's dictionary reader
csvReader = csv.DictReader(csvf)

#convert each csv row into python dict
for row in csvReader:
#add this python dict to json array
row["uri"] = "unece:rec20#"+row["CommonCode"]
values.append(row)

data["values"] = values
data["referencedBy"] = []

#convert python jsonArray to JSON String and write to file
with open(jsonFilePath, 'w', encoding='utf-8') as jsonf:
jsonString = json.dumps(data, indent=4)
jsonf.write(jsonString)

csvFilePath = r'current/Annex || & Annex |||/code-list.csv'
jsonFilePath = r'current/rec20.json'
csv_to_json(csvFilePath, jsonFilePath)
2 changes: 1 addition & 1 deletion CLR/Rec20/current/Annex || & Annex |||/code-list.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Status,"CommonCode",Name,Description,"Level/Category",Symbol,ConversionFactor
Status,"CommonCode",Name,Description,"LevelCategory",Symbol,ConversionFactor
X,05,lift,,3.9,,
X,06,small spray,,3.9,,
X,08,heat lot,,3.9,,
Expand Down
2 changes: 1 addition & 1 deletion CLR/Rec21/current/code-list.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Status,Code,Name,Description,Numeric code
Status,Code,Name,Description,NumericCode
,1A,"Drum, steel",,34
,1B,"Drum, aluminium",,34
,1D,"Drum, plywood",,34
Expand Down
2 changes: 1 addition & 1 deletion CLR/Rec23/current/code-list.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CI,Group,Subgroup,Detail,Description,Mode/Site Indicator,Duplicate Indicator
CI,Group,Subgroup,Detail,Description,ModeSiteIndicator,DuplicateIndicator
,1,00,000, FREIGHT CHARGES,,
,1,00,999,All freight charges,,
,1,01,000, BASIC FREIGHT,,
Expand Down

0 comments on commit 9db5053

Please sign in to comment.