def translate_post(article_id): subject = flask.request.form["subject"].encode("utf-8") body = flask.request.form["body"].encode("utf-8") params = {"article_id": article_id, "language": "ja", "subject": subject, "body": body} req = urllib2.Request(nihongodeok.api_base + "/translate_article", urllib.urlencode(params)) result = json.load(urllib2.urlopen(req)) article = nihongodeok.get_article(article_id) nihongodeok.request_page_capture(article["url"]) words_en, words_ja = nihongodeok.create_bag_of_words(article) nihongodeok.push_bag_of_words(article_id, words_en, words_ja) return translate_get(article_id)
def article(article_id): article = nihongodeok.async_get_article(article_id) related_articles = nihongodeok.async_get_related_articles(article_id) if article.response.status == 404: return "404 Not found", 404 article = article.decode_json() related_articles = related_articles.decode_json() url = article["url"] pagecapture_path = "/%s/%s.png" % (article_id[:2], article_id) img_exists = nihongodeok.async_head(nihongodeok.pagecapture_base + pagecapture_path) pagecapture = None if img_exists.response.status == 200: pagecapture = nihongodeok.pagecapture_external_base + pagecapture_path else: nihongodeok.request_page_capture(url) return flask.render_template( "article.html", article=article, pagecapture=pagecapture, related_articles=related_articles )