def add(url, title=''): result = { } if len(url) > 0: if utils.page_exists(url): try: link = database.add_link(url, datetime.now()) if title and (len(title) > 0): database.edit_title_without_counting(link.id, title) if link.embed_type == 0: duration = utils.reading_time(link.word_count) elif link.embed_type == 1: duration = utils.video_duration(link.word_count) else: duration = "" result = { 'success': True, 'valid_url': True, 'link': { 'id': link.id, 'title': link.title, 'url': link.url, 'domain': link.domain, 'embed_type': link.embed_type, 'embed_url': link.embed_url, 'image_url': link.image_url, 'screenshot_url': screenshots.get_screenshot(link.url), 'duration': duration } } except Exception as error: print "(API) Couldn't add link. " + str(type(error)) + " - " + str(error) result = { 'success': False, 'valid_url': True, 'message': str(error) } else: result = { 'success': False, 'valid_url': False, 'no_url': False } else: result = { 'success': False, 'valid_url': False, 'no_url': True} return jsonify(result)
def reading_time(words): return utils.reading_time(words)