def load_keywords(): hottrends = nihongodeok.async_get(nihongodeok.hiwihhi_api_base + "/hottrends") keywords = nihongodeok.async_get(nihongodeok.hiwihhi_api_base + "/keywords/splitted?offset=1") hottrends = hottrends.decode_json() keywords = keywords.decode_json() kwd = {} for hottrend in hottrends: hashcode = hottrend[1] if hashcode not in kwd: kwd[hashcode] = nihongodeok.async_get(nihongodeok.api_base + "/search", {"q": hottrend[0], "limit": 0}) for keyword in keywords: hashcode = keyword[1] if hashcode not in kwd: kwd[hashcode] = nihongodeok.async_get(nihongodeok.api_base + "/search", {"q": keyword[0], "limit": 0}) for hashcode in kwd: kwd[hashcode] = kwd[hashcode].decode_json()[0] for hottrend in hottrends: hashcode = hottrend[1] if hashcode in kwd: hottrend.append(kwd[hashcode]) for keyword in keywords: hashcode = keyword[1] if hashcode in kwd: keyword.append(kwd[hashcode]) return (hottrends, keywords)
def edit_synonym(): keyword = flask.request.args["keyword"] synonyms = nihongodeok.async_get(nihongodeok.api_base + "/synonyms", {"q": keyword}) synonyms = synonyms.decode_json() data = {"keyword": keyword} if keyword in synonyms: data["synonyms"] = synonyms[keyword] data["count"] = nihongodeok.async_get( nihongodeok.api_base + "/search", {"q": data["synonyms"], "limit": 0} ).decode_json()[0] else: data["count"] = nihongodeok.async_get( nihongodeok.api_base + "/search", {"q": keyword, "limit": 0} ).decode_json()[0] return flask.render_template("edit_synonyms.html", **data)
def missing_synonyms(): sold_keywords = nihongodeok.async_get(nihongodeok.hiwihhi_api_base + "/keywords") synonyms = nihongodeok.async_get(nihongodeok.api_base + "/synonyms") sold_keywords = sold_keywords.decode_json() synonyms = synonyms.decode_json() keywords = set() for sold_keyword in sold_keywords: kws = re.split(u"[ ]", sold_keyword[0]) for kw in kws: if kw != "": keywords.add(kw) missings = [] for keyword in keywords: if keyword not in synonyms: missings.append(keyword) return flask.render_template("missing_synonyms.html", keywords=missings)
#!/usr/bin/python from __future__ import print_function import sys import urllib import urllib2 import json import nihongodeok def run(article_id): return nihongodeok.create_and_push_bag_of_words(article_id, True) if __name__ == '__main__': if len(sys.argv) > 1: articles = sys.argv[1:] else: articles = map(lambda x:x["id"], nihongodeok.async_get(nihongodeok.api_base + "/latest_articles/ja").decode_json()) for article_id in articles: print(run(article_id))