Ivan000 commited on
Commit
7e4c8eb
·
verified ·
1 Parent(s): 5be97e9

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -7
main.py CHANGED
@@ -1,7 +1,7 @@
1
  # File: main.py
2
 
3
- from fastapi import FastAPI, Query, Response
4
- from fastapi.responses import XMLResponse
5
  import requests
6
  from bs4 import BeautifulSoup
7
  from urllib.parse import quote
@@ -23,7 +23,8 @@ def html_to_fb2(title: str, body: str) -> str:
23
  </title-info>
24
  </description>
25
  <body>
26
- <section><title><p>{title}</p></title>
 
27
  <p>{clean_text}</p>
28
  </section>
29
  </body>
@@ -69,14 +70,14 @@ def generate_opds(query: str, results):
69
  })
70
  return ET.tostring(feed, encoding="utf-8", xml_declaration=True)
71
 
72
- @app.get("/opds", response_class=XMLResponse)
73
- def opds_catalog(q: str = Query(..., description="Search query")):
74
  results = duckduckgo_search(q)
75
  xml_data = generate_opds(q, results)
76
  return Response(content=xml_data, media_type="application/atom+xml")
77
 
78
  @app.get("/download")
79
- def download_fb2(url: str):
80
  res = requests.get(url, headers={"User-Agent": "Mozilla/5.0"}, timeout=10)
81
  res.raise_for_status()
82
  soup = BeautifulSoup(res.text, "html.parser")
@@ -89,4 +90,3 @@ def download_fb2(url: str):
89
  media_type="application/fb2+xml",
90
  headers={"Content-Disposition": f"attachment; filename={filename}"}
91
  )
92
-
 
1
  # File: main.py
2
 
3
+ from fastapi import FastAPI, Query
4
+ from fastapi.responses import Response
5
  import requests
6
  from bs4 import BeautifulSoup
7
  from urllib.parse import quote
 
23
  </title-info>
24
  </description>
25
  <body>
26
+ <section>
27
+ <title><p>{title}</p></title>
28
  <p>{clean_text}</p>
29
  </section>
30
  </body>
 
70
  })
71
  return ET.tostring(feed, encoding="utf-8", xml_declaration=True)
72
 
73
+ @app.get("/opds")
74
+ def opds_catalog(q: str = Query(..., description="Search query")) -> Response:
75
  results = duckduckgo_search(q)
76
  xml_data = generate_opds(q, results)
77
  return Response(content=xml_data, media_type="application/atom+xml")
78
 
79
  @app.get("/download")
80
+ def download_fb2(url: str) -> Response:
81
  res = requests.get(url, headers={"User-Agent": "Mozilla/5.0"}, timeout=10)
82
  res.raise_for_status()
83
  soup = BeautifulSoup(res.text, "html.parser")
 
90
  media_type="application/fb2+xml",
91
  headers={"Content-Disposition": f"attachment; filename={filename}"}
92
  )