Esempio n. 1
0
def gsc_tag():
    hour = datetime.now().hour
    minute = datetime.now().minute
    gsc_table = cache.get('supertaste_tag_cache')
    if not gsc_table or \
        ((hour>0 and minute > 0) and (hour>0 and minute <= 1)) or ((hour>6 and minute > 0) and (hour>6 and minute <= 1)) or \
        ((hour>8 and minute > 0) and (hour>8 and minute <= 1)) or ((hour>10 and minute > 0) and (hour>10 and minute <= 1)) or \
        ((hour>12 and minute > 0) and (hour>12 and minute <= 1)) or ((hour>14 and minute > 0) and (hour>14 and minute <= 1)) or \
        ((hour>16 and minute > 0) and (hour>16 and minute <= 1)) or ((hour>18 and minute > 0) and (hour>18 and minute <= 1)) or \
        ((hour>20 and minute > 0) and (hour>20 and minute <= 1)) or ((hour>22 and minute > 0) and (hour>22 and minute <= 1)):
        tag_gsc = read_gzip.tmp_read('dict', 'supertaste')
        tag_gsc['search_content'] = tag_gsc["search_content"].map(
            lambda tag: tag.replace(' ', ','))
        tag_gsc['search_content'].replace('', np.nan, inplace=True)
        tag_gsc = tag_gsc.dropna(how='all')
        tag_gsc = tag_gsc.reset_index().rename(
            columns={tag_gsc.index.name: 'nid'})
        gsc_list = dataframe_to_json(tag_gsc)
        gsc_table = jsonify(gsc_list)
        gsc_table.status_code = 200
        cache.set('supertaste_tag_cache', gsc_table, timeout=7200)
        return gsc_table
    else:
        print('supertaste_tag_cache')
        return gsc_table
Esempio n. 2
0
def tvbs_news_tag_analysis():
    hour = datetime.now().hour
    minute = datetime.now().minute
#    args = request.args
    search_console = request.args.get('gsc', 'Y', type = str)
    day = request.args.get('day',90 , type = int)
    news_tag_summary = cache.get('health_tag_cache'+str(day)+search_console)
    try:
        if (not news_tag_summary) or\
            ((hour>0 and minute > 0) and (hour>0 and minute <= 1)) or ((hour>6 and minute > 0) and (hour>6 and minute <= 1)) or \
            ((hour>8 and minute > 0) and (hour>8 and minute <= 1)) or ((hour>10 and minute > 0) and (hour>10 and minute <= 1)) or \
            ((hour>12 and minute > 0) and (hour>12 and minute <= 1)) or ((hour>14 and minute > 0) and (hour>14 and minute <= 1)) or \
            ((hour>16 and minute > 0) and (hour>16 and minute <= 1)) or ((hour>18 and minute > 0) and (hour>18 and minute <= 1)) or \
            ((hour>20 and minute > 0) and (hour>20 and minute <= 1)) or ((hour>22 and minute > 0) and (hour>22 and minute <= 1)):
#            if (not news_tag_summary):
            print('Not cache')
            back_tag_of_dfItem = tra.cache_article_table('health').get_aws_table_cache(day)
            if search_console =='Y':
                tag_summary = tra.editorTag('health',back_tag_of_dfItem,'Y').editor_tag_summary()
            else:
                tag_summary = tra.editorTag('health',back_tag_of_dfItem,'N').editor_tag_summary()
            summary_list = dataframe_to_json(tag_summary)
            news_tag_summary = jsonify(summary_list)
            news_tag_summary.status_code=200
            cache.set('health_tag_cache'+str(day)+search_console,news_tag_summary,timeout=7200)
            return news_tag_summary
        else:
            print('health_tag_cache')
            return news_tag_summary
    finally:
        print('request get /tvbs_health_tag_analysis')
Esempio n. 3
0
def tvbs_news_tag_analysis():
    hour = datetime.now().hour
    minute = datetime.now().minute
    args = request.args
    day = args.get('day') if 'day' in args else 90
    news_tag_summary = cache.get('news_tag_cache' + str(day))
    try:
        if (not news_tag_summary) or\
            ((hour>0 and minute > 0) and (hour>0 and minute <= 1)) or ((hour>6 and minute > 0) and (hour>6 and minute <= 1)) or \
            ((hour>8 and minute > 0) and (hour>8 and minute <= 1)) or ((hour>10 and minute > 0) and (hour>10 and minute <= 1)) or \
            ((hour>12 and minute > 0) and (hour>12 and minute <= 1)) or ((hour>14 and minute > 0) and (hour>14 and minute <= 1)) or \
            ((hour>16 and minute > 0) and (hour>16 and minute <= 1)) or ((hour>18 and minute > 0) and (hour>18 and minute <= 1)) or \
            ((hour>20 and minute > 0) and (hour>20 and minute <= 1)) or ((hour>22 and minute > 0) and (hour>22 and minute <= 1)):
            #            if (not news_tag_summary):
            print('Not cache')
            back_tag_of_dfItem = tra.cache_article_table(
                'news').get_aws_table_cache(day)
            tag_summary = tra.editorTag('news', back_tag_of_dfItem,
                                        'N').editor_tag_summary()
            summary_list = dataframe_to_json(tag_summary)
            news_tag_summary = jsonify(summary_list)
            news_tag_summary.status_code = 200
            cache.set('news_tag_cache' + str(day),
                      news_tag_summary,
                      timeout=7200)
            return news_tag_summary
        else:
            print('news_tag_cache')
            return news_tag_summary
    finally:
        print('request get /tvbs_news_tag_analysis')
Esempio n. 4
0
def user_prefer():
    hour = datetime.now().hour
    minute = datetime.now().minute
    prefer_cache = cache.get('prefer_cache')
    try:
        if (not prefer_cache) or \
        ((hour>9 and minute > 0) and (hour>9 and minute <= 2)):
            df_users_prefer_score = qr.user_prefer()
            js_user_prefer_score = dataframe_to_json(df_users_prefer_score)
            json_user_prefer = jsonify(js_user_prefer_score)
            json_user_prefer.status_code = 200
            cache.set('prefer_cache', json_user_prefer, timeout=7200)
            return (json_user_prefer)
        else:
            print('prefer_cache')
            return prefer_cache
    finally:
        print('request get /prefer_cache')
Esempio n. 5
0
def user_recomment():
    hour = datetime.now().hour
    minute = datetime.now().minute
    user_article_recommend = cache.get('user_article_recommend')
    try:
        if (not user_article_recommend) or \
        ((hour>9 and minute > 0) and (hour>9 and minute <= 2)):
            df_users_prefer_score = requests.get(
                f"http://127.0.0.1:8010/recommend_api/user_prefer")
            recommend_article = requests.get(
                f"http://127.0.0.1:8010/recommend_api/recommend_article")
            top_rank = requests.get(
                f"http://127.0.0.1:8010/recommend_api/top_rank")
            df_users_prefer_score = pd.DataFrame.from_records(
                df_users_prefer_score.json())
            recommend_article = recommend_article.json()
            top_rank = top_rank.json()
            df_user_recommend = qr.user_recomment(df_users_prefer_score,
                                                  recommend_article,
                                                  top_rank["top_rank"])
            df_user_recommend["recommend_article"] = [
                ','.join(map(str, l))
                for l in df_user_recommend['recommend_article']
            ]
            js_user_recommend = dataframe_to_json(df_user_recommend)
            json_user_recommend = jsonify(js_user_recommend)
            json_user_recommend.status_code = 200
            cache.set('user_article_recommend',
                      json_user_recommend,
                      timeout=86400)
            return (json_user_recommend)
        else:
            print('user_article_recommend')
            return user_article_recommend
    finally:
        print('request get /user_article_recommend')