1
0
Fork 0
mirror of https://github.com/Findus23/HNReader.git synced 2024-09-19 15:23:44 +02:00
HNReader/reader/__init__.py
2021-04-09 16:17:53 +02:00

17 lines
550 B
Python

import asyncio
import json
from pathlib import Path
class Reader:
async def readable_html(self, url: str):
php_file = Path(__file__).parent / "reader.php"
process = await asyncio.create_subprocess_exec(
"php", str(php_file),
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE)
stdout, stderr = await process.communicate(url.encode())
data = json.loads(stdout.decode().strip())
del data["headers"]
del data["summary"]
return json.dumps(data)