mirror of
https://gitlab.com/moepoi/Quintal-Grabber.git
synced 2024-12-22 14:34:58 +01:00
Fix errors and improve codes
This commit is contained in:
parent
30fa210a39
commit
367e17b1eb
8 changed files with 89 additions and 53 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -102,3 +102,5 @@ venv.bak/
|
|||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
.idea/
|
||||
|
|
1
Quintal/__init__.py
Normal file
1
Quintal/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from .quintal import QuintalGrabber
|
62
Quintal/quintal.py
Normal file
62
Quintal/quintal.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
import requests
|
||||
import sys
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
except:
|
||||
import json
|
||||
|
||||
'''
|
||||
Author : Moe Poi <moepoi@protonmail.com>
|
||||
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)
|
19
README.md
19
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)
|
||||
|
|
7
example.py
Normal file
7
example.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from Quintal import QuintalGrabber
|
||||
|
||||
id = 123456
|
||||
quintal = QuintalGrabber(id)
|
||||
#x = quintal.get_data("email")
|
||||
x = quintal.get_data()
|
||||
print (x)
|
|
@ -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)))
|
38
quintal.py
38
quintal.py
|
@ -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)
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
requests
|
||||
ujson
|
Loading…
Reference in a new issue