-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proper VERSION file, fixed cr,mga ... selector
- Loading branch information
1 parent
0bb00e0
commit 2ddbcc1
Showing
11 changed files
with
238 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
include README.md LICENSE.txt requirements.txt | ||
recursive-include siscad *.py | ||
recursive-include siscad *.py VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
import setuptools | ||
import os | ||
import ast | ||
here = os.path.abspath(os.path.dirname(__file__)) | ||
exec(next(iter(open(os.path.join(here,"siscad","__init__.py"))))) #exec first line of init, get __version__ | ||
setuptools.setup( | ||
name='siscad', | ||
license='GPLv3', | ||
version=__version__, | ||
author="Giuliano Oliveira De Macedo", | ||
author_email="giuliano.llpinokio@gmail.com", | ||
description="Module for siscad.ufms.br", | ||
long_description=open("README.md").read(), | ||
download_url=f"https://github.com/llpinokio/siscad.py/archive/v{__version__}.tar.gz", | ||
long_description_content_type="text/markdown", | ||
keywords=["web-scraping"], | ||
url="https://github.com/llpinokio/siscad.py", | ||
packages=setuptools.find_packages(), | ||
install_requires=open("requirements.txt").read().split(), | ||
classifiers=[ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)", | ||
"Operating System :: OS Independent", | ||
], | ||
) | ||
from setuptools import setup, find_packages | ||
from pathlib import Path | ||
|
||
version = Path("./siscad/VERSION").read_text().strip() | ||
setup( | ||
name="siscad", | ||
license="GPLv3", | ||
version=version, | ||
author="Giuliano Oliveira De Macedo", | ||
author_email="giuliano.llpinokio@gmail.com", | ||
description="Module for siscad.ufms.br", | ||
long_description=Path("README.md").read_text(), | ||
download_url=f"https://github.com/llpinokio/siscad.py/archive/v{version}.tar.gz", | ||
long_description_content_type="text/markdown", | ||
keywords=["web-scraping"], | ||
url="https://github.com/llpinokio/siscad.py", | ||
packages=find_packages(), | ||
install_requires=Path("requirements.txt").read_text().split(), | ||
classifiers=[ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)", | ||
"Operating System :: OS Independent", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,92 @@ | ||
import requests | ||
from bs4 import BeautifulSoup as BS | ||
from collections import namedtuple | ||
from urllib.parse import urljoin | ||
import os | ||
import re | ||
from .model import Nota,Disciplina,Semestre | ||
from .model import Disciplina, Semestre | ||
from . import HEADERS | ||
from .utils import parse_table | ||
|
||
regex_extract_number=lambda s:int(re.search(r"\d+",s).group(0)) | ||
regex_extract_number = lambda s: int(re.search(r"\d+", s).group(0)) | ||
|
||
base_url_join=lambda *args:urljoin(Siscad.base_url,os.path.join(*args)) | ||
base_url_join = lambda *args: urljoin(Siscad.base_url, os.path.join(*args)) | ||
|
||
|
||
class Siscad: | ||
base_url="https://siscad.ufms.br" | ||
def __init__(self,passaporte,senha): | ||
base_url = "https://siscad.ufms.br" | ||
|
||
def __init__(self, passaporte, senha): | ||
""" | ||
login no SISCAD | ||
passaporte:str | ||
senha:str | ||
atributos: | ||
rga:str | ||
nome:str | ||
carga_hor:float | ||
cr:float | ||
discs_feitas:int | ||
discs:list de tipo Disciplina | ||
login no SISCAD | ||
passaporte:str | ||
senha:str | ||
atributos: | ||
rga:str | ||
nome:str | ||
carga_hor:float | ||
cr:float | ||
discs_feitas:int | ||
discs:list de tipo Disciplina | ||
""" | ||
self.sess=requests.Session() | ||
self.sess.headers=HEADERS | ||
res=self.sess.post( | ||
base_url_join("login"), | ||
data={"passaporte":passaporte,"senha":senha} | ||
self.sess = requests.Session() | ||
self.sess.headers = HEADERS | ||
res = self.sess.post( | ||
base_url_join("login"), data={"passaporte": passaporte, "senha": senha} | ||
) | ||
if res.url!=base_url_join("academico"): | ||
if res.url != base_url_join("academico"): | ||
raise RuntimeError("Senha/Passaporte Invalido") | ||
self.__main_parser(res.text) | ||
def __request_getter(self,*args): | ||
|
||
def __request_getter(self, *args): | ||
return self.sess.get(base_url_join(*args)) | ||
|
||
def get_semestres(self): | ||
res=self.__request_getter("academico","disciplinas") | ||
res = self.__request_getter("academico", "disciplinas") | ||
if not res.ok: | ||
raise RuntimeError("Falha ao acessar endereço \"%s\""%res.url) | ||
raise RuntimeError('Falha ao acessar endereço "%s"' % res.url) | ||
return self.__disciplinas_parser(res.text) | ||
def __disciplinas_parser(self,doc): | ||
soup=BS(doc,"html.parser") | ||
ans=[] | ||
|
||
def __disciplinas_parser(self, doc): | ||
soup = BS(doc, "html.parser") | ||
ans = [] | ||
|
||
for div in soup.select("div.box-primary")[1:]: | ||
date=div.select_one("h3.box-title.color-gray").text.strip() | ||
sem=Semestre( | ||
re.search(r"\d+\/\d+",date).group(0), | ||
[] | ||
) | ||
date = div.select_one("h3.box-title.color-gray").text.strip() | ||
sem = Semestre(re.search(r"\d+\/\d+", date).group(0), []) | ||
for d in parse_table(div.select_one("table")): | ||
try: | ||
_id= regex_extract_number(d["Código da Disciplina"].select_one("a").attrs["href"]) | ||
nome= d["Nome da Disciplina"].text.strip() | ||
situacao= d["Situação"].text.strip() | ||
ch= regex_extract_number(d["C.H."].text.strip()) | ||
_id = regex_extract_number( | ||
d["Código da Disciplina"].select_one("a").attrs["href"] | ||
) | ||
nome = d["Nome da Disciplina"].text.strip() | ||
situacao = d["Situação"].text.strip() | ||
ch = regex_extract_number(d["C.H."].text.strip()) | ||
except KeyError as e: | ||
print("keys available:",list(d.keys())) | ||
print("keys available:", list(d.keys())) | ||
raise e | ||
sem.discs.append(Disciplina(Siscad.base_url,self.sess.cookies.get("CAKEPHP"),nome,ch,_id)) | ||
sem.discs.append( | ||
Disciplina( | ||
Siscad.base_url, self.sess.cookies.get("CAKEPHP"), nome, ch, _id | ||
) | ||
) | ||
ans.append(sem) | ||
return ans[::-1] | ||
|
||
def __main_parser(self,doc): | ||
soup=BS(doc,"html.parser") | ||
def __main_parser(self, doc): | ||
soup = BS(doc, "html.parser") | ||
# nome / rga | ||
self.rga=soup.select_one("li.user-header>p>small").text.strip().split(" ")[-1] | ||
self.nome=soup.select_one("div.pull-left.info>p").text | ||
#carga_hor,cr,discs_feitas | ||
box_content=soup.select("div.info-box-content") | ||
carga_hor,cr,discs_feitas=( | ||
self.rga = soup.select_one("li.user-header>p>small").text.strip().split(" ")[-1] | ||
self.nome = soup.select_one("div.pull-left.info>p").text | ||
# carga_hor,cr,discs_feitas | ||
box_content = soup.select("div.info-box-content") | ||
carga_hor, discs_feitas, mga, cr = ( | ||
elem.select_one("span.info-box-number").text.strip() for elem in box_content | ||
) | ||
self.carga_hor=float(carga_hor.replace(",",".")[:-1]) | ||
self.cr=float(cr.replace(",",".")) | ||
self.discs_feitas=int(discs_feitas) | ||
#ultima_matricula | ||
self.ultima_matricula=soup.select_one("h3.box-title.color-gray").text.split(":")[-1].strip() | ||
self.carga_hor = float(carga_hor.replace(",", ".")[:-1]) | ||
self.cr = float(cr.replace(",", ".")) | ||
self.mga = float(mga.replace(",", ".")) | ||
self.discs_feitas = int(discs_feitas) | ||
# ultima_matricula | ||
self.ultima_matricula = ( | ||
soup.select_one("h3.box-title.color-gray").text.split(":")[-1].strip() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
__version__="0.0.3" #FIRST LINE MUST BE THE VERSION | ||
from pathlib import Path | ||
|
||
script_path = Path(__file__).parent | ||
__version__ = (script_path / "VERSION").read_text().strip() | ||
|
||
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent | ||
# Mozilla/<version> (<system-information>) <platform> (<platform-details>) <extensions> | ||
import requests | ||
import platform | ||
HEADERS={ | ||
"Accept-Encoding": "gzip, deflate", | ||
"Accept": "*/*", | ||
"Connection": "keep-alive", | ||
"User-Agent":f"python-requests/{requests.__version__} ({platform.platform()}) {__package__}-{__version__}", | ||
"pypi-url":"https://pypi.org/project/siscad" | ||
|
||
HEADERS = { | ||
"Accept-Encoding": "gzip, deflate", | ||
"Accept": "*/*", | ||
"Connection": "keep-alive", | ||
"User-Agent": f"python-requests/{requests.__version__} ({platform.platform()}) {__package__}-{__version__}", | ||
"pypi-url": "https://pypi.org/project/siscad", | ||
} | ||
from .Siscad import Siscad |
Oops, something went wrong.