Beispiel #1
0
def query_landmark():
    lat = request.args.get('lat')
    lng = request.args.get('lng')

    # if lat == None or lng == None:
    #     return '{}'
    #
    # latlng = str(lat) + "," + str(lng)
    #
    # if latlng not in landmark.LANDMARK_KEYWORDS:
    #     return '{}'

    lm = landmark.getlandmark(lat, lng)
    if lm == None:
        return '{}'

    first_keyword = landmark.LANDMARK_KEYWORDS[lm.location][0]
    related_news_ids = lm.related_news

    logging.info("Query position has " + str(len(related_news_ids)) + " news")

    return_dict = {'landmark_name': first_keyword}
    return_list = []
    for news_key in related_news_ids:
        key = db.Key(news_key)
        entry = NewsModel.all().filter('__key__ =', key).get()
        if entry != None:
            dic = {}
            dic['news_id'] = news_key
            dic['title'] = entry.title
            return_list.append(dic)
    return_dict['news_list'] = return_list

    return json.dumps(return_dict)
Beispiel #2
0
def query_landmark():
    lat = request.args.get('lat')
    lng = request.args.get('lng')

    # if lat == None or lng == None:
    #     return '{}'
    #
    # latlng = str(lat) + "," + str(lng)
    #
    # if latlng not in landmark.LANDMARK_KEYWORDS:
    #     return '{}'

    lm = landmark.getlandmark(lat, lng)
    if lm == None:
        return '{}'

    first_keyword = landmark.LANDMARK_KEYWORDS[lm.location][0]
    related_news_ids = lm.related_news

    logging.info("Query position has " + str(len(related_news_ids)) + " news")

    return_dict = {'landmark_name': first_keyword}
    return_list = []
    for news_key in related_news_ids:
        key = db.Key(news_key)
        entry = NewsModel.all().filter('__key__ =', key).get()
        if entry != None:
            dic = {}
            dic['news_id'] = news_key
            dic['title'] = entry.title
            return_list.append(dic)
    return_dict['news_list'] = return_list

    return json.dumps(return_dict)
Beispiel #3
0
def perform_create_landmark():

    logging.info("Start to create landmark database")

    all_news = NewsModel.all()
    for latlng in landmark.LANDMARK_KEYWORDS:
        counter = 0
        keywords = landmark.LANDMARK_KEYWORDS[latlng]
        related_news_keys = []
        for news in all_news:
            result = is_keyword_in_news(keywords, news.title, news.content)
            if result == True:
                related_news_keys.append(str(news.key()))
                counter += 1

        ret = str(related_news_keys)

        lm = landmark.Landmark(latlng, related_news_keys)
        lm.writetodb()
        logging.info("Create database for " + str(latlng) +
                     " completed, it has " + str(counter) + " news")

    logging.info("All database for landmark are completed")

    return "Write to db complete"
Beispiel #4
0
def query_article():
    key = db.Key(request.args.get('news_key'))
    entry = NewsModel.all().filter('__key__ =', key).get()
    if entry != None:
        return json.dumps({"title"      : entry.title,
                           "datetime"   : str(entry.news_datetime),
                           "article"    : entry.content,
                           "popularity" : entry.popularity,
                           "image_url"  : entry.news_first_image_url,
                           "url"        : entry.news_url})
    else:
        return '{}'
Beispiel #5
0
def query_article():
    key = db.Key(request.args.get('news_key'))
    entry = NewsModel.all().filter('__key__ =', key).get()
    if entry != None:
        return json.dumps({
            "title": entry.title,
            "datetime": str(entry.news_datetime),
            "article": entry.content,
            "popularity": entry.popularity,
            "image_url": entry.news_first_image_url,
            "url": entry.news_url
        })
    else:
        return '{}'
Beispiel #6
0
def perform_create_landmark():

    logging.info("Start to create landmark database")

    all_news = NewsModel.all()
    for latlng in landmark.LANDMARK_KEYWORDS:
        counter = 0
        keywords = landmark.LANDMARK_KEYWORDS[latlng]
        related_news_keys = []
        for news in all_news:
            result = is_keyword_in_news(keywords, news.title, news.content)
            if result == True:
                related_news_keys.append(str(news.key()))
                counter += 1

        ret = str(related_news_keys)

        lm = landmark.Landmark(latlng, related_news_keys)
        lm.writetodb()
        logging.info("Create database for " + str(latlng) + " completed, it has " + str(counter) + " news")

    logging.info("All database for landmark are completed")

    return "Write to db complete"