本文整理汇总了Python中micawber.bootstrap_basic函数的典型用法代码示例。如果您正苦于以下问题:Python bootstrap_basic函数的具体用法?Python bootstrap_basic怎么用?Python bootstrap_basic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bootstrap_basic函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
if micawber is None:
msg = req_missing(['micawber'], 'use the media directive', optional=True)
return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]
providers = micawber.bootstrap_basic()
return [nodes.raw('', micawber.parse_text(" ".join(self.arguments), providers), format='html')]
示例2: import_posts
def import_posts(self, zipfile, names):
"""Import all posts."""
out_folder = 'posts'
providers = micawber.bootstrap_basic()
for name in names:
with zipfile.open(name, 'r') as post_f:
data = json.load(post_f)
title = data['title']
slug = utils.slugify(title)
if not slug: # should never happen
LOGGER.error("Error converting post:", title)
return
description = ''
post_date = dateutil.parser.parse(data["published"])
content = data["object"]["content"]
for obj in data["object"].get("attachments", []):
content += '\n<div> {} </div>\n'.format(micawber.parse_text(obj["url"], providers))
tags = []
self.write_metadata(os.path.join(self.output_folder, out_folder, slug + '.meta'), title, slug, post_date, description, tags)
self.write_content(
os.path.join(self.output_folder, out_folder, slug + '.html'),
content)
示例3: _build_provider_list
def _build_provider_list():
"""
Construct the provider registry, using the app settings.
"""
registry = None
if appsettings.FLUENT_OEMBED_SOURCE == 'basic':
registry = bootstrap_basic()
elif appsettings.FLUENT_OEMBED_SOURCE == 'embedly':
params = {}
if appsettings.MICAWBER_EMBEDLY_KEY:
params['key'] = appsettings.MICAWBER_EMBEDLY_KEY
registry = bootstrap_embedly(**params)
elif appsettings.FLUENT_OEMBED_SOURCE == 'noembed':
registry = bootstrap_noembed(nowrap=1)
elif appsettings.FLUENT_OEMBED_SOURCE == 'list':
# Fill list manually in the settings, e.g. to have a fixed set of supported secure providers.
registry = ProviderRegistry()
for regex, provider in appsettings.FLUENT_OEMBED_PROVIDER_LIST:
registry.register(regex, Provider(provider))
else:
raise ImproperlyConfigured("Invalid value of FLUENT_OEMBED_SOURCE, only 'basic', 'list', 'noembed' or 'embedly' is supported.")
# Add any extra providers defined in the settings
for regex, provider in appsettings.FLUENT_OEMBED_EXTRA_PROVIDERS:
registry.register(regex, Provider(provider))
return registry
示例4: media_create_tags
def media_create_tags(request, match, instance=None, template_name='media_form.html'):
if request.method == 'POST':
form = MediaForm(request.POST, instance=instance if instance is not None else Media())
if form.is_valid():
providers = micawber.bootstrap_basic()
try:
provider_obj = providers.request(form.cleaned_data['url'])
except micawber.exceptions.ProviderNotFoundException as msg:
return render(request, template_name, {'object_form': form, 'error_message': msg})
except micawber.exceptions.ProviderException as msg:
return render(request, template_name, {'object_form': form, 'error_message': "Embedding disabled by request"})
media = form.save(commit=False)
media.title = provider_obj.get('title') if len(provider_obj.get('title')) < 200 else provider_obj.get('title')[:200]
media.media_type = provider_obj['type']
media.thumbnail_url = provider_obj.get('thumbnail_url', provider_obj.get('url'))
media.submitted_by = request.user if instance is None else instance.submitted_by
media.blog_type = 1 # media
media.save()
media.tags.clear()
for tag in form.cleaned_data['tags']:
media.tags.add(tag.lower())
return redirect(media)
else:
if match:
tag_list = ['"%s"' % tag.replace('-', ' ') for tag in match.split('|')]
form = MediaForm(initial={'tags': ','.join(tag_list)})
else:
form = MediaForm(instance=instance)
return render(request, template_name, {'object_form': form})
示例5: bookmark
def bookmark(ctx, url):
providers = micawber.bootstrap_basic()
bookmark = {
'url': url
}
try:
oembed = providers.request(url)
soup = BeautifulSoup(oembed['html'], 'html.parser')
except:
oembed = {}
content = '<!-- TODO Write something here. -->'
if oembed.get('type') == 'video':
iframe_src = soup.iframe.get('src')
content = ' include c_video.html iframe_url="{0}" '.format(iframe_src)
bookmark = oembed
if oembed.get('type') == 'photo':
oembed['image_src'] = soup.img.get('src')
content = (' include c_image.html src="{image_src}" '
'alt="{title}" ')
post = Post(content, title=ctx.obj['TITLE'], layout='post_bookmark',
category='bookmark', date=ctx.obj['NOW'].isoformat(),
tags=ctx.obj.get('TAGS'), bookmark=bookmark)
write_post('bookmark', ctx.obj['NOW'], ctx.obj['SLUG'], post)
示例6: getIframeForVideo
def getIframeForVideo(videoUrl):
providers = micawber.bootstrap_basic()
try:
embed = providers.request(videoUrl, maxwidth=580, maxheight=377)
except (InvalidResponseException,
ProviderException,
ProviderNotFoundException):
return None
return embed['html']
示例7: get_title_with_oembed
def get_title_with_oembed(url):
providers = micawber.bootstrap_basic()
try:
res = providers.request(url)
except micawber.ProviderException as e:
logger.info(e)
return ''
return '{} - {}'.format(res.get('title'), res.get('provider_name'))
示例8: getInformationsForVideo
def getInformationsForVideo(videoUrl):
providers = micawber.bootstrap_basic()
try:
embed = providers.request(videoUrl)
except (InvalidResponseException,
ProviderException,
ProviderNotFoundException):
return {'title': 'Vidéo introuvable',
'thumb': ''}
return {'title': embed['title'],
'thumb': embed['thumbnail_url']}
示例9: run
def run(self):
if micawber is None:
msg = (
"To use the media directive you need to install "
"the micawber module."
)
utils.logger.WARN(msg)
return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]
providers = micawber.bootstrap_basic()
return [nodes.raw('', micawber.parse_text(" ".join(self.arguments), providers), format='html')]
示例10: test_oembed_services
def test_oembed_services(self):
'''
A test various oembed services and a simple howto use micawber to discover oembed services (soundcloud, vimeo etc) from urls
Note: it doesn't work with ISSUU
'''
import micawber
mic = micawber.bootstrap_basic()
you = mic.request('https://www.youtube.com/watch?v=GGyLP6R4HTE') # youtube
vim = mic.request('http://vimeo.com/17081933') # vimeo
try:
nothing = mic.request('http://en.wikipedia.org/wiki/The_Boat_Race_2000')
except micawber.exceptions.ProviderNotFoundException, e:
pass
示例11: run
def run(self):
if micawber is None:
msg = "To use the media directive, isntall micawber first."
return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]
url = " ".join(self.arguments)
providers = micawber.bootstrap_basic()
data = providers.request(url)
html = '<h3>{}</h3>{}'.format(
data['title'],
micawber.parse_text(url, providers)
)
return [nodes.raw('', html, format='html')]
示例12: html_content
def html_content(self):
app = current_app._get_current_object()
# hilite = CodeHiLiteExtension(linenums=False, css_class='highlight')
extras = ExtraExtension()
#TODO why can I not add CodeHiLiteExtension????
# markdown_content = markdown(self.body, extensions=[hilite, extras])
markdown_content = markdown(self.body, extensions=[extras])
oembed_providers = bootstrap_basic(OEmbedCache())
oembed_content = parse_html(
markdown_content,
oembed_providers,
urlize_all=True,
maxwidth=app.config['SITE_WIDTH'])
return Markup(oembed_content)
示例13: save
def save(self, *args, **kwargs):
providers = micawber.bootstrap_basic()
providers.register(WISTIA_REGEX, micawber.Provider("http://fast.wistia.com/oembed/"))
oembed_response = providers.request(self.media_url,maxwidth=600, maxheight=500, width=600)
self.embed_code=oembed_response["html"]
if oembed_response["type"]=="photo":
self.media_type = IMAGE
#request the image again, add full-size link to the embed code
second_oembed_response = providers.request(self.media_url)
link_text = '<div class="viewfullsize-link"><a href="%s">View full-size image</a></div>' % second_oembed_response["url"]
self.embed_code = "".join([self.embed_code,link_text])
elif oembed_response["type"]=="video":
self.media_type = VIDEO
elif oembed_response["type"]=="rich":
self.media_type = RICH
try:
if "thumbnail_url" in oembed_response:
self.thumbnail_url=oembed_response["thumbnail_url"]
elif oembed_response["type"]=="photo":
self.thumbnail_url = oembed_response["url"]
else:
self.thumbnail_url = os.path.join(settings.STATIC_URL,"images/rich.png")
except:
self.thumbnail_url=""
'''
TODO some hacky Wistia-specific additions here
'''
if re.match(WISTIA_REGEX,self.media_url):
self.thumbnail_url = "%s?image_crop_resized=260x180" % self.thumbnail_url.split("?")[0]
if self.media_type == IMAGE:
self.embed_code = re.sub("image_crop_resized","image_resize",self.embed_code)
elif self.media_type == RICH:
if oembed_response["url"]:
link_text = '<div class="viewfullsize-link"><a href="%s">Download this file</a></div>' % oembed_response["url"]
self.embed_code = "".join([self.embed_code,link_text])
super(MediaArtefact, self).save(*args, **kwargs)
示例14: index
def index():
#import shit
providers = micawber.bootstrap_basic()
add_oembed_filters(app, providers)
#connect to db
db_obj = connect_db('data.db')
#assign cursor and connection to variables
cur = db_obj[0]
con = db_obj[1]
#get list of all threads
cur.execute('SELECT * FROM thread;')
threads = cur.fetchall()
#get original post belonging to each thread
cur.execute('SELECT * FROM post WHERE id = 1 ;')
posts = cur.fetchall()
if request.method == 'POST':
#grab form data
subject = request.form['subjectLine']
comment = request.form['comment']
embed = request.form['embed']
if subject == "" or comment == "" or embed =="":
return "need javascript"
#get highest threadID
cur.execute('SELECT MAX(id) FROM thread;')
#current post is 1 higher
threadID = cur.fetchone()[0] + 1
thread = [threadID, subject]
#adds thread to the database by passing it the item
cur.execute('insert into thread values(?,?)',thread)
#create original post
post = [1, threadID, strftime("%I:%M %B %d, %Y"), comment, embed]
cur.execute('insert into post values(?,?,?,?,?)',post)
#save the changes
con.commit()
con.close()
return redirect(url_for('index'))
con.close()
return render_template('listthreads.html', threads=reversed(threads), posts=posts)
示例15: test_oembed_services
def test_oembed_services(self):
import micawber
mic = micawber.bootstrap_basic()
you = mic.request('https://www.youtube.com/watch?v=GGyLP6R4HTE') # youtube
vim = mic.request('http://vimeo.com/17081933') # vimeo
print self.assertEqual(you['provider_name'], u'YouTube')
print self.assertEqual(vim['provider_name'], u'Vimeo')
document = Document(corpus=self.corpus, name=u'N-L_FR_20140305_.txt')
document.mimetype = "text/html"
document.save()
t1, created = Tag.objects.get_or_create(type=Tag.OEMBED_PROVIDER_NAME, name=vim['provider_name'])
t1, created = Tag.objects.get_or_create(type=Tag.OEMBED_TITLE, name=vim['title'])
t2, created = Tag.objects.get_or_create(type=Tag.OEMBED_THUMBNAIL_URL, name=vim['thumbnail_url'])