Skip to content

Instantly share code, notes, and snippets.

@shekhirin
Last active January 21, 2021 18:14
Show Gist options
  • Save shekhirin/46b49c46b80c291f78de82def4a0041f to your computer and use it in GitHub Desktop.
Save shekhirin/46b49c46b80c291f78de82def4a0041f to your computer and use it in GitHub Desktop.
https://youtu.be/ipAnwilMncI in YouTube trends all over the world
import requests
from tqdm import tqdm
countries_response = requests.get('https://api.popular50.com/countries').json()
countries = [x['_id'] for x in countries_response['hits']]
data = {x: requests.get('https://api.popular50.com/v1videos', params={'country_code': x, 'category_id': 0}).json() for x in tqdm(countries)}
naval = {x: [i for i, z in enumerate(y['hits']) if z['_source']['video_id'] == 'ipAnwilMncI'] for x, y in data.items()}
countries_data = {x['_id']: x for x in countries_response['hits']}
print('\n'.join([f'{x[0]} – {x[1][0] + 1}' for x in sorted({countries_data[x]['_source']['country_name']: y for x, y in naval.items() if len(y) > 0}.items(), key=lambda x: x[1][0])]))
@foreverest
Copy link

lgtm ✊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment