Created
February 3, 2013 19:55
-
-
Save vadimii/4703384 to your computer and use it in GitHub Desktop.
Load Vimeo channel feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
REQ_FROMAT = 'json' | |
CHANNEL_REQ = 'http://vimeo.com/api/v2/channel/%s/%s.%s' | |
SAMPLE_CHANNEL = 'leeseidenbergadvertising' | |
CHANNEL_INFO = 'info' | |
CHANNEL_VIDEOS = 'videos' | |
FEED_PAGE_SIZE = 20 | |
def read_channel_info(): | |
url = CHANNEL_REQ % (SAMPLE_CHANNEL, CHANNEL_INFO, REQ_FROMAT) | |
res = requests.get(url) | |
return res.json() | |
def read_feed_page(page): | |
url = CHANNEL_REQ % (SAMPLE_CHANNEL, CHANNEL_VIDEOS, REQ_FROMAT) | |
res = requests.get(url, params={'page': page}) | |
return res.json() | |
def read_channel_feed(): | |
s = FEED_PAGE_SIZE | |
info = read_channel_info() | |
total = info['total_videos'] | |
pages = total / s | |
if total % s: | |
pages += 1 | |
videos = [] | |
info['videos'] = videos | |
for p in range(1, pages+1): | |
page_videos = read_feed_page(p) | |
videos.extend(page_videos) | |
return info | |
def print_json(): | |
jdata = read_channel_feed() | |
print json.dumps(jdata, sort_keys=True, indent=4) | |
#print_json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment