Пример #1
0
def save_post():
    post_data = json.loads(request.data)
    url = post_data["url"]
    json_data = make_readable(url)

    title = post_data["title"]
    slug = userutils.make_slug(title)
    author = User.objects(username=current_user.username).first()

    p = Post(title=title, slug=slug)
    p.saved_date = datetime.now()
    p.thumbnail = post_data["thumbnail"]
    p.url = url
    p.author = author
    p.content = json_data["content"]
    p.excerpt = json_data["excerpt"]
    p.domain = post_data["domain"]
    p.save()

    q.enqueue(insert_new_relation, p)

    author.posts.append(p)
    author.save()

    return "ok"
Пример #2
0
def submit():
    url = request.args.get("url")
    if url.endswith(".pdf"):
        user = get_user()
        parsed_uri = urlparse(url)
        domain = '{uri.netloc}'.format(uri=parsed_uri)
        return render_template(
            'unparsed.html', user=user, url=url, domain=domain
        )
    else:
        json_data = make_readable(url)
        user = get_user()
        return render_template('parsed.html', data=json_data, user=user)
Пример #3
0
def parse():
    url = request.form.get("url")
    json_data = make_readable(url)
    user = get_user()
    return render_template('parsed.html', data=json_data, user=user)