Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 57 lines (41 sloc) 2.058 kb
a7c75b9 @coleifer Initial checkin
authored
1 micawber
2 ========
3
4 .. image:: http://i.imgur.com/QAnaa.jpg
5
6 A small library for extracting rich content from urls
7cabc54 @coleifer Adding example to the readme
authored
7
8
9 what does it do?
10 ----------------
11
12 micawber supplies a few methods for retrieving rich metadata about a variety of
13 links, such as links to youtube videos. micawber also provides functions for
14 parsing blocks of text and html and replacing links to videos with rich embedded
15 content.
16
17 examples
18 --------
19
20 here is a quick example::
21
22 import micawber
23
24 # load up rules for some default providers, such as youtube and flickr
25 providers = micawber.bootstrap_basic()
26
27 providers.request('http://www.youtube.com/watch?v=54XHDUOHuzU')
28
29 # returns the following dictionary:
30 {
31 'author_name': 'pascalbrax',
32 'author_url': u'http://www.youtube.com/user/pascalbrax'
33 'height': 344,
34 'html': u'<iframe width="459" height="344" src="http://www.youtube.com/embed/54XHDUOHuzU?fs=1&feature=oembed" frameborder="0" allowfullscreen></iframe>',
35 'provider_name': 'YouTube',
36 'provider_url': 'http://www.youtube.com/',
37 'title': 'Future Crew - Second Reality demo - HD',
38 'type': u'video',
39 'thumbnail_height': 360,
40 'thumbnail_url': u'http://i2.ytimg.com/vi/54XHDUOHuzU/hqdefault.jpg',
41 'thumbnail_width': 480,
42 'url': 'http://www.youtube.com/watch?v=54XHDUOHuzU',
43 'width': 459,
44 'version': '1.0',
45 }
46
47 micawber.parse_text('this is a test:\nhttp://www.youtube.com/watch?v=54XHDUOHuzU', providers)
48
49 # returns the following string:
50 this is a test:
51 <iframe width="459" height="344" src="http://www.youtube.com/embed/54XHDUOHuzU?fs=1&feature=oembed" frameborder="0" allowfullscreen></iframe>
52
53 micawber.parse_html('<p>http://www.youtube.com/watch?v=54XHDUOHuzU</p>', providers)
54
55 # returns the following html:
56 <p><iframe width="459" height="344" src="http://www.youtube.com/embed/54XHDUOHuzU?fs=1&amp;feature=oembed" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p>
Something went wrong with that request. Please try again.