Spaces:
Sleeping
Sleeping
Update
Browse files- app.py +5 -4
- classes.py +7 -3
app.py
CHANGED
|
@@ -195,11 +195,12 @@ 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.get("/reconnect", tags=["Misc"], summary="Reconnects to ETSI portal for document access")
|
| 199 |
def reconnect():
|
| 200 |
-
etsi_doc_finder.connect()
|
| 201 |
-
|
| 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",
|
|
|
|
| 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", include_in_schema=False)
|
| 199 |
def reconnect():
|
| 200 |
+
data = etsi_doc_finder.connect()
|
| 201 |
+
if data.get('error', None) and not data.get('error'):
|
| 202 |
+
return data['message']
|
| 203 |
+
raise HTTPException(status_code=400, detail=data['message'])
|
| 204 |
@app.post("/find/single", response_model=DocResponse, tags=["Document Retrieval"], summary="Retrieve a single document by ID", responses={
|
| 205 |
200: {
|
| 206 |
"description": "Document found successfully",
|
classes.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import requests
|
| 2 |
import re
|
| 3 |
from bs4 import BeautifulSoup
|
|
@@ -7,13 +8,16 @@ import json
|
|
| 7 |
class ETSIDocFinder:
|
| 8 |
def __init__(self):
|
| 9 |
self.main_ftp_url = "https://docbox.etsi.org/SET"
|
| 10 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 16 |
-
|
|
|
|
| 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
|
|
|
|
| 1 |
+
from fastapi import HTTPException
|
| 2 |
import requests
|
| 3 |
import re
|
| 4 |
from bs4 import BeautifulSoup
|
|
|
|
| 8 |
class ETSIDocFinder:
|
| 9 |
def __init__(self):
|
| 10 |
self.main_ftp_url = "https://docbox.etsi.org/SET"
|
| 11 |
+
req_data = self.connect()
|
| 12 |
+
print(req_data['message'])
|
| 13 |
+
self.session = req_data['session']
|
| 14 |
|
| 15 |
def connect(self):
|
| 16 |
session = requests.Session()
|
| 17 |
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")}))
|
| 18 |
+
if req.text == "Failed":
|
| 19 |
+
return {"error": True, "session": session, "message": "Login failed ! Check your credentials"}
|
| 20 |
+
return {"error": False, "session": session, "message": "Login successful"}
|
| 21 |
|
| 22 |
def get_workgroup(self, doc: str):
|
| 23 |
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
|