om4r932 commited on
Commit
962c5f0
·
1 Parent(s): 284f82f

Fix ETSI error

Browse files
Files changed (2) hide show
  1. app.py +7 -2
  2. classes.py +6 -2
app.py CHANGED
@@ -195,6 +195,11 @@ valid_etsi_spec_format = re.compile(r'^\d{3} \d{3}(?:-\d+)?')
195
  def frontend():
196
  return FileResponse(os.path.join('templates', 'index.html'))
197
 
 
 
 
 
 
198
  @app.post("/find/single", response_model=DocResponse, tags=["Document Retrieval"], summary="Retrieve a single document by ID", responses={
199
  200: {
200
  "description": "Document found successfully",
@@ -229,9 +234,9 @@ def find_document(request: DocRequest):
229
  elif valid_3gpp_spec_format.match(document):
230
  url = get_spec_url(document)
231
  elif valid_etsi_doc_format.match(document):
232
- etsi_doc_finder.search_document(document)
233
  elif valid_etsi_spec_format.match(document):
234
- etsi_spec_finder.search_document(document)
235
  elif document.startswith("GP"):
236
  for sp in gp_spec_locations:
237
  if document.lower() in sp.lower():
 
195
  def frontend():
196
  return FileResponse(os.path.join('templates', 'index.html'))
197
 
198
+ @app.get("/reconnect", tags=["Misc"], summary="Reconnects to ETSI portal for document access")
199
+ def reconnect():
200
+ etsi_doc_finder.connect()
201
+ return {"status": "OK !"}
202
+
203
  @app.post("/find/single", response_model=DocResponse, tags=["Document Retrieval"], summary="Retrieve a single document by ID", responses={
204
  200: {
205
  "description": "Document found successfully",
 
234
  elif valid_3gpp_spec_format.match(document):
235
  url = get_spec_url(document)
236
  elif valid_etsi_doc_format.match(document):
237
+ url = etsi_doc_finder.search_document(document)
238
  elif valid_etsi_spec_format.match(document):
239
+ url = etsi_spec_finder.search_document(document)
240
  elif document.startswith("GP"):
241
  for sp in gp_spec_locations:
242
  if document.lower() in sp.lower():
classes.py CHANGED
@@ -7,9 +7,13 @@ import json
7
  class ETSIDocFinder:
8
  def __init__(self):
9
  self.main_ftp_url = "https://docbox.etsi.org/SET"
10
- self.session = requests.Session()
11
- req = self.session.post("https://portal.etsi.org/ETSIPages/LoginEOL.ashx", verify=False, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"}, data=json.dumps({"username": os.environ.get("EOL_USER"), "password": os.environ.get("EOL_PASSWORD")}))
 
 
 
12
  print(req.content, req.status_code)
 
13
 
14
  def get_workgroup(self, doc: str):
15
  main_tsg = "SET-WG-R" if any(doc.startswith(kw) for kw in ["SETREQ", "SCPREQ"]) else "SET-WG-T" if any(doc.startswith(kw) for kw in ["SETTEC", "SCPTEC"]) else "SET" if any(doc.startswith(kw) for kw in ["SET", "SCP"]) else None
 
7
  class ETSIDocFinder:
8
  def __init__(self):
9
  self.main_ftp_url = "https://docbox.etsi.org/SET"
10
+ self.session = self.connect()
11
+
12
+ def connect(self):
13
+ session = requests.Session()
14
+ req = session.post("https://portal.etsi.org/ETSIPages/LoginEOL.ashx", verify=False, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"}, data=json.dumps({"username": os.environ.get("EOL_USER"), "password": os.environ.get("EOL_PASSWORD")}))
15
  print(req.content, req.status_code)
16
+ return session
17
 
18
  def get_workgroup(self, doc: str):
19
  main_tsg = "SET-WG-R" if any(doc.startswith(kw) for kw in ["SETREQ", "SCPREQ"]) else "SET-WG-T" if any(doc.startswith(kw) for kw in ["SETTEC", "SCPTEC"]) else "SET" if any(doc.startswith(kw) for kw in ["SET", "SCP"]) else None