def embedly_link(URL): #Takes a URL, returns a populated Link object #Returns "error" if Embedly API fails client = Embedly(embedly_key) response = client.extract(URL) try: #Get link information from Embedly headline = response['title'] URL = clean_url(response['url']) summary = response['description'] source = response['provider_name'] path = page_path(headline) keywords_response = response['keywords'] keyword1 = str(keywords_response[0]['name']) keyword2 = str(keywords_response[1]['name']) keyword3 = str(keywords_response[2]['name']) keyword4 = str(keywords_response[3]['name']) keyword5 = str(keywords_response[4]['name']) #Create Link object with info from Embedly link = Link(headline=headline, url=URL, source=source, summary=summary, path=path, keyword1=keyword1, keyword2=keyword2, keyword3=keyword3, keyword4=keyword4, keyword5=keyword5, votes=0) return link except: return "error"
def embedly_link(URL): #Takes a URL, returns a populated Link object #Returns "error" if Embedly API fails client = Embedly(embedly_key) response = client.extract(URL) try: #Get link information from Embedly headline = response['title'] URL = clean_url(response['url']) summary = response['description'] source = response['provider_name'] path = page_path(headline) keywords_response = response['keywords'] keyword1 = str(keywords_response[0]['name']) keyword2 = str(keywords_response[1]['name']) keyword3 = str(keywords_response[2]['name']) keyword4 = str(keywords_response[3]['name']) keyword5 = str(keywords_response[4]['name']) #Create Link object with info from Embedly link = Link(headline = headline, url = URL, source = source, summary = summary, path = path, keyword1 = keyword1, keyword2 = keyword2, keyword3 = keyword3, keyword4 = keyword4, keyword5 = keyword5, votes = 0) return link except: return "error"
def get_article(): url = request.args.get('url') client = Embedly('f2f84ff5013b443ab711b204590d9aa2') result = client.extract(url) article = {} article["url"] = result["url"] article["headline"] = result["title"] article["description"] = result["description"] article["content"] = result["content"] response = make_response(json.dumps(article, indent=4)) response.headers['Access-Control-Allow-Origin'] = "*" return response
def clean(self): # http://embed.ly/docs/api/extract/endpoints/1/extract#error-codes self.data = {} if settings.DJANGOCMS_EMBED_API_KEY is None: msg = _( 'DJANGOCMS_EMBED_API_KEY is not defined in the project settings.' ) logger.error(msg) raise ImproperlyConfigured(msg) client = Embedly(settings.DJANGOCMS_EMBED_API_KEY) try: data = client.extract(self.url) except ValueError, e: raise ValidationError(str(e))
# using embedly with python import csv import itertools import json import requests from urlparse import urljoin # below currently works in the command line, but not sure how to translate it into this python document, run it and have it work from embedly import Embedly # key = 'f2f84ff5013b443ab711b204590d9aa2' client = Embedly('f2f84ff5013b443ab711b204590d9aa2') result = client.extract( 'https://medium.com/message/yes-to-the-dress-5ec06c06aca4') article = {} article["url"] = result["url"] article["headline"] = result["title"] article["description"] = result["description"] article["content"] = result["content"] print "URL:", result["url"] print "Headline:", result["title"] print "Description:", result["description"] print "Article:", result["content"] subjects_file = open("../articles/dressarticle.json", "w") print >> json.dump(article, subjects_file, indent=4)
def __init__(self, url): self.url = url client = Embedly(settings.EMBEDLY_API_KEY) self.obj = client.extract(self.url)
def enrich(url, title): client = Embedly(EMBEDLY_KEY) data = client.extract(url) data['text'] = SmartHTMLDocument("<html><body>%s</body></html>" % data['content']).getText().strip() data['summary'] = Summarizer(data['text'], title).summary() return data
# using embedly with python import csv import itertools import json import requests from urlparse import urljoin # below currently works in the command line, but not sure how to translate it into this python document, run it and have it work from embedly import Embedly # key = 'f2f84ff5013b443ab711b204590d9aa2' client = Embedly('f2f84ff5013b443ab711b204590d9aa2') result = client.extract('https://medium.com/message/yes-to-the-dress-5ec06c06aca4') article = {} article["url"] = result["url"] article["headline"] = result["title"] article["description"] = result["description"] article["content"] = result["content"] print "URL:", result["url"] print "Headline:", result["title"] print "Description:", result["description"] print "Article:", result["content"] subjects_file = open("../articles/dressarticle.json", "w") print >> json.dump(article, subjects_file, indent=4)