diff --git a/.gitignore b/.gitignore index 894a44c..f82a459 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,5 @@ venv.bak/ # mypy .mypy_cache/ + +.idea/ diff --git a/Quintal/__init__.py b/Quintal/__init__.py new file mode 100644 index 0000000..5bbe021 --- /dev/null +++ b/Quintal/__init__.py @@ -0,0 +1 @@ +from .quintal import QuintalGrabber \ No newline at end of file diff --git a/Quintal/quintal.py b/Quintal/quintal.py new file mode 100644 index 0000000..2d5b12e --- /dev/null +++ b/Quintal/quintal.py @@ -0,0 +1,62 @@ +import requests +import sys + +try: + import ujson as json +except: + import json + +''' +Author : Moe Poi +License MIT +''' + +class QuintalGrabber: + + def __init__(self, id): + self.host = "https://quintal.id" + self.id = id + + def get_data(self, query=None): + endpoint = "/id/api/initial_data/{}/?format=json".format(str(self.id)) + try: + req = requests.get(self.host + endpoint) + data = json.loads(req.text) + except: + print ("Invalid ID") + sys.exit() + x = { + "lastlogin": data["student_class_semester"]["profile"]["user"]["last_login"], + "username": data["student_class_semester"]["profile"]["user"]["username"], + "firstname": data["student_class_semester"]["profile"]["user"]["first_name"], + "lastname": data["student_class_semester"]["profile"]["user"]["last_name"], + "email": data["student_class_semester"]["profile"]["user"]["email"], + "gender": data["student_class_semester"]["profile"]["gender"], + "phonenumber": data["student_class_semester"]["profile"]["mobile_no"], + "address": data["student_class_semester"]["profile"]["address"], + "city": data["student_class_semester"]["profile"]["city"], + "province": data["student_class_semester"]["profile"]["province"], + "country": data["student_class_semester"]["profile"]["country"], + "profilephoto": self.host + data["student_class_semester"]["profile"]["profile_photo"], + "birthdate": data["student_class_semester"]["profile"]["birth_date"], + "sectionname": data["student_class_semester"]["section_name"], + "gradename": data["student_class_semester"]["grade_name"], + "classname": data["student_class_semester"]["class_name"], + "i_fullname": data["student_class_semester"]["profile"]["institution"]["full_name"], + "i_shortname": data["student_class_semester"]["profile"]["institution"]["short_name"], + "i_address": data["student_class_semester"]["profile"]["institution"]["address"], + "i_city": data["student_class_semester"]["profile"]["institution"]["city"], + "i_province": data["student_class_semester"]["profile"]["institution"]["province"], + "i_country": data["student_class_semester"]["profile"]["institution"]["country"], + "i_logo": self.host + data["student_class_semester"]["profile"]["institution"]["logo"], + "i_domain": data["student_class_semester"]["profile"]["institution"]["sch_domain"] + } + if query is None: + return(x) + else: + try: + xm = x["{}".format(str(query))] + return (xm) + except Exception as e: + xm = "type {} not found".format(str(query)) + return (xm) diff --git a/README.md b/README.md index c245615..4f13553 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,26 @@ # Quintal Grabber -*Get Information from Quintal Private API* +*Get Data from Quintal Private API* ----- +## Installation + +Installation is simple. It can be installed from pip using the following command: +```sh +$ pip3 install -r requirements.txt +``` ## Usage ```sh -$ python3 example_run.py +from Quintal import QuintalGrabber + +id = 123456 +quintal = QuintalGrabber(id) +#x = quintal.get_data("email") +x = quintal.get_data() +print (x) ``` -## Created By +## Credit Moe Poi ~ / [@moepoi](https://gitlab.com/moepoi) diff --git a/example.py b/example.py new file mode 100644 index 0000000..e6b3917 --- /dev/null +++ b/example.py @@ -0,0 +1,7 @@ +from Quintal import QuintalGrabber + +id = 123456 +quintal = QuintalGrabber(id) +#x = quintal.get_data("email") +x = quintal.get_data() +print (x) \ No newline at end of file diff --git a/example_run.py b/example_run.py deleted file mode 100644 index 7e34e52..0000000 --- a/example_run.py +++ /dev/null @@ -1,11 +0,0 @@ -from quintal import Quintal - -id = input("Quintal ID : ") -data = Quintal(id).studentinfo() -username = data[1] -name = data[2] + data[3] -email = data[4] -address = data[7] -profilephoto = data[11] -grade = data[14] -print ("Username : {}\nName : {}\nEmail : {}\nAddress : {}\nClass : {}\nProfile photo : {}".format(str(username), str(name), str(email), str(address), str(grade), str(profilephoto))) diff --git a/quintal.py b/quintal.py deleted file mode 100644 index bce03af..0000000 --- a/quintal.py +++ /dev/null @@ -1,38 +0,0 @@ -import requests as rq -import json - -class Quintal(object): - - def __init__(self, id): - self.host = "https://quintal.id" - self.id = id - - def studentinfo(self): - endpoint = "/id/api/initial_data/{}/?format=json".format(str(self.id)) - req = rq.get(self.host + endpoint) - data = json.loads(req.text) - lastlogin = data["student_class_semester"]["profile"]["user"]["last_login"] - username = data["student_class_semester"]["profile"]["user"]["username"] - firstname = data["student_class_semester"]["profile"]["user"]["first_name"] - lastname = data["student_class_semester"]["profile"]["user"]["last_name"] - email = data["student_class_semester"]["profile"]["user"]["email"] - gender = data["student_class_semester"]["profile"]["gender"] - phonenumber = data["student_class_semester"]["profile"]["mobile_no"] - address = data["student_class_semester"]["profile"]["address"] - city = data["student_class_semester"]["profile"]["city"] - province = data["student_class_semester"]["profile"]["province"] - country = data["student_class_semester"]["profile"]["country"] - profilephoto = self.host + data["student_class_semester"]["profile"]["profile_photo"] - birthdate = data["student_class_semester"]["profile"]["birth_date"] - sectionname = data["student_class_semester"]["section_name"] - gradename = data["student_class_semester"]["grade_name"] - classname = data["student_class_semester"]["class_name"] - i_fullname = data["student_class_semester"]["profile"]["institution"]["full_name"] - i_shortname = data["student_class_semester"]["profile"]["institution"]["short_name"] - i_address = data["student_class_semester"]["profile"]["institution"]["address"] - i_city = data["student_class_semester"]["profile"]["institution"]["city"] - i_province = data["student_class_semester"]["profile"]["institution"]["province"] - i_country = data["student_class_semester"]["profile"]["institution"]["country"] - i_logo = self.host + data["student_class_semester"]["profile"]["institution"]["logo"] - i_domain = data["student_class_semester"]["profile"]["institution"]["sch_domain"] - return (lastlogin, username, firstname, lastname, email, gender, phonenumber, address, city, province, country, profilephoto, birthdate, sectionname, gradename, classname, i_fullname, i_shortname, i_address, i_city, i_province, i_country, i_logo, i_domain) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2e521bc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests +ujson \ No newline at end of file