Skip to content

Instantly share code, notes, and snippets.

@arvchristos
Last active March 26, 2020 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arvchristos/02091fae3b9048f41dc8caedf3f4ef8c to your computer and use it in GitHub Desktop.
Save arvchristos/02091fae3b9048f41dc8caedf3f4ef8c to your computer and use it in GitHub Desktop.
Get all youtube links of a Discourse topic
import urllib.request
import json
with urllib.request.urlopen("https://linux-user.gr/t/125.json") as url:
data = json.loads(url.read().decode())
# construct the biggest query of the world
start_url = "https://linux-user.gr/t/125/posts.json?"
for stream_id in data['post_stream']['stream']:
start_url = start_url + "post_ids[]=" + str(stream_id) + "&"
with urllib.request.urlopen(start_url) as posts_url:
post_data = json.loads(posts_url.read().decode())
for post in post_data['post_stream']['posts']:
try:
for link in post['link_counts']:
if link['title'] == 'YouTube':
print(link['url'])
except KeyError as e:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment