Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add of the python support #109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# kuliya for python

Algeria's college hierarchy dataset as python package
## **How to Use**
1. **Run the script** with the JSON file path as an argument:
```bash
python3 main.py <path-to-json-file>
```
42 changes: 42 additions & 0 deletions python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys
import json

# A node which contains the data from the JSON file in a python format
class Node:
def __init__(self, nameAr: str, nameEn: str, nameFr: str, univ: str):
self.nameAr = nameAr
self.nameEn = nameEn
self.nameFr = nameFr
self.univ = univ

def getNameAr(self):
return self.nameAr

def getNameEn(self):
return self.nameEn

def getNameFr(self):
return self.nameFr

def getUniv(self):
return self.univ

# Converts the data from the
def getNodeByPath(path: str) -> Node:
try:
file = open(path, "r")
fileText = file.read()
pythonData = json.loads(fileText)
node = Node(pythonData["name"]["ar"], pythonData["name"]["en"], pythonData["name"]["fr"], pythonData["type"])
return node
except OSError as e:
raise FileNotFoundError(f"Error with the file : {e}")


def main():
try:
node = getNodeByPath(sys.argv[1])
except FileNotFoundError as e:
print(e)

main()
Loading