aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-10-29 20:12:02 +0100
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-10-29 20:12:02 +0100
commit937c1690909f8a8645916fed943ea0506f86634c (patch)
treedf37579dc350aa351159c1b7b946bb82dbbc2393
parent3b308c48415811ffcefef62be8a9c6439f556a5c (diff)
Structure list gathering now WORKS!
-rwxr-xr-xsgdfi/_dbs/_st.py2
-rwxr-xr-xsgdfi/_decode.py1
-rwxr-xr-xsgdfi/_intranet.py67
3 files changed, 48 insertions, 22 deletions
diff --git a/sgdfi/_dbs/_st.py b/sgdfi/_dbs/_st.py
index e5f669a..59020ae 100755
--- a/sgdfi/_dbs/_st.py
+++ b/sgdfi/_dbs/_st.py
@@ -65,7 +65,7 @@ _StructureTypeData = {
StructureType.AUTRES: ("Autres", 1211),
- StructureType.SOMMET: ("Sommet", 1205),
+ StructureType.SOMMET: ("Sommet", 1207),
StructureType.TERRITOIRE: ("Territoire", 1203),
StructureType.GROUPE: ("Groupe", 1200),
StructureType.ASSOCIES_N: ("Membres associés National", 1206),
diff --git a/sgdfi/_decode.py b/sgdfi/_decode.py
index b6b359f..0606ca4 100755
--- a/sgdfi/_decode.py
+++ b/sgdfi/_decode.py
@@ -438,7 +438,6 @@ class Decoder:
more = False
pgn = _Pagination(curpage, numpages, more)
- print(pgn)
return pgn
def _decode_html_intranet_operations(self, tree):
diff --git a/sgdfi/_intranet.py b/sgdfi/_intranet.py
index 497a1e9..8804cbe 100755
--- a/sgdfi/_intranet.py
+++ b/sgdfi/_intranet.py
@@ -68,6 +68,7 @@ class AnonymousIntranetSession:
self.__base = base
self.__session = _Session()
self.__oldsess = None
+ self.__dfs = {}
self.__dbg = bool(debug or manager._debug)
self._ref(manager)
@@ -122,6 +123,26 @@ class AnonymousIntranetSession:
self.__session = self.__oldsession
self.__oldsession = None
+ def __get_fields(self, content):
+ """ Get the fields in a content. """
+
+ it = _BeautifulSoup(content, 'lxml').find_all('input',
+ recursive = True)
+ fields = {}
+ for elt in it:
+ try:
+ name = elt['name']
+ except:
+ continue
+ try:
+ value = elt['value']
+ except:
+ value = ''
+
+ fields[name] = value
+
+ return fields
+
def get_page(self, path, args = {}, method = METHOD_BASIC, hint = None,
new_session = False):
""" Gather a page:
@@ -149,6 +170,8 @@ class AnonymousIntranetSession:
def ret(r):
""" Treat the response to know what to return """
+ nonlocal path
+
status_code = r.status_code
# Check if it is a redirection.
@@ -197,6 +220,7 @@ class AnonymousIntranetSession:
elif ct == 'text/html':
self.__log(f"Decoding HTML content{htext}.")
+ self.__dfs[path] = self.__get_fields(r.text)
return self.__mgr.feed(r.text, 'text/html', hint)
elif ct == 'text/xml':
self.__log(f"Decoding XML content{htext}.")
@@ -228,10 +252,17 @@ class AnonymousIntranetSession:
# prédéfinis.
# ---
- df = {}
+ if method == self.METHOD_JSONPOST:
+ # No need to GET the page, there is no form, it is probably
+ # for one of the WebServices.
+
+ df = {}
+ elif path in self.__dfs:
+ # Some fields exist for us to use them. Let's do that!
- if method != self.METHOD_JSONPOST:
- # Récupération à proprement parler.
+ df = self.__dfs.pop(path)
+ else:
+ # Page gathering.
tm = _monotime()
r = self.__session.get(self.__base + path, headers = headers)
@@ -247,19 +278,7 @@ class AnonymousIntranetSession:
# défaut de l'ensemble des champs, dont `__EVENTVALIDATION`
# qui sert de cookie CSRF.
- it = _BeautifulSoup(r.text, 'lxml').find_all('input',
- recursive = True)
- for elt in it:
- try:
- name = elt['name']
- except:
- continue
- try:
- value = elt['value']
- except:
- value = ''
-
- df[name] = value
+ df = self.__get_fields(r.text)
# ---
# Préparation des paramètres POST (payload).
@@ -614,8 +633,8 @@ class IntranetSession(AnonymousIntranetSession):
path = '/Specialisation/Sgdf/Popups/RechercheStructure.aspx?' \
f'dummy=1&operations={iid.urlsafe()}'
args = {
- '__EVENTARGUMENT': f"Page${page}",
- '__EVENTTARGET': 'ctl00$Popup$_recherche$_gvResultats',
+ '__EVENTARGUMENT': "",
+ '__EVENTTARGET': "",
'ctl00_Popup__recherche__pnlFormulaire_CurrentState': 'true',
'ctl00$Popup$_recherche': {
'_ddDepartement': st_dept,
@@ -629,10 +648,18 @@ class IntranetSession(AnonymousIntranetSession):
'_tbNom': st_name,
'Rechercher': None,
- 'Rechercher.x': '45',
- 'Rechercher.y': '5',
'_btnAnnuler': None}}
+ if page == 1:
+ args['ctl00$Popup$_recherche']['Rechercher.x'] = '45'
+ args['ctl00$Popup$_recherche']['Rechercher.y'] = '5'
+ else:
+ # TODO: if this is the first page ever gathered, first gather
+ # page 1 so we can then get the page?
+
+ args['__EVENTARGUMENT'] = f"Page${page}"
+ args['__EVENTTARGET'] = 'ctl00$Popup$_recherche$_gvResultats'
+
return self.get_page(path, args, method = self.METHOD_FORM,
hint = 'intranet_structure_search')