darknet_diaries_llm/download_transcripts.py

31 lines
890 B
Python
Raw Permalink Normal View History

2023-10-06 21:35:53 +02:00
import requests
2023-10-07 00:30:46 +02:00
import os
2023-10-06 21:35:53 +02:00
from bs4 import BeautifulSoup
2023-10-07 08:32:07 +02:00
import json
2023-10-06 21:35:53 +02:00
2023-10-07 00:30:46 +02:00
folder_path = "transcripts"
if not os.path.exists(folder_path):
os.makedirs(folder_path)
2023-10-06 21:35:53 +02:00
for i in range(1, 139):
2023-10-07 08:32:07 +02:00
try:
url = f"https://darknetdiaries.com/transcript/{i}"
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
2023-10-06 21:35:53 +02:00
2023-10-07 08:32:07 +02:00
transcript = soup.find('pre').get_text()
2023-10-07 00:57:45 +02:00
2023-10-07 08:32:07 +02:00
url = f"https://api.darknetdiaries.com/{i}.json"
r = requests.get(url)
parsed_json = json.loads(r.text)
title = parsed_json["episode_name"]
number = parsed_json["episode_number"]
downloads = parsed_json["total_downloads"]
2023-10-07 00:57:45 +02:00
2023-10-07 08:32:07 +02:00
with open(f"{folder_path}/episode_{number}.txt", "w") as f:
f.write(f"{title}\n{downloads}\n{transcript}")
print(f"{number} {title}")
except Exception:
print(f"Failed scraping episode {i}")