Skip to content

Commit f8f2f23

Browse files
committed
Add of the python support
1 parent fb38f2c commit f8f2f23

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

python/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# kuliya for python
2-
3-
Algeria's college hierarchy dataset as python package
2+
## **How to Use**
3+
1. **Run the script** with the JSON file path as an argument:
4+
```bash
5+
python3 main.py <path-to-json-file>
6+
```

python/main.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import sys
2+
import json
3+
4+
# A node which contains the data from the JSON file in a python format
5+
class Node:
6+
def __init__(self, nameAr: str, nameEn: str, nameFr: str, univ: str):
7+
self.nameAr = nameAr
8+
self.nameEn = nameEn
9+
self.nameFr = nameFr
10+
self.univ = univ
11+
12+
def getNameAr(self):
13+
return self.nameAr
14+
15+
def getNameEn(self):
16+
return self.nameEn
17+
18+
def getNameFr(self):
19+
return self.nameFr
20+
21+
def getUniv(self):
22+
return self.univ
23+
24+
# Converts the data from the
25+
def getNodeByPath(path: str) -> Node:
26+
try:
27+
file = open(path, "r")
28+
fileText = file.read()
29+
pythonData = json.loads(fileText)
30+
node = Node(pythonData["name"]["ar"], pythonData["name"]["en"], pythonData["name"]["fr"], pythonData["type"])
31+
return node
32+
except OSError as e:
33+
raise FileNotFoundError(f"Error with the file : {e}")
34+
35+
36+
def main():
37+
try:
38+
node = getNodeByPath(sys.argv[1])
39+
except FileNotFoundError as e:
40+
print(e)
41+
42+
main()

0 commit comments

Comments
 (0)