def test_db(): db_config.aws_db() insert = """SELECT news_id AS nid, news_get_type AS get_type, news_title AS title, news_tag AS tag, news_summary AS summary, cast(DATE(news_published_date)as char) AS date FROM tvbs_news_v4.news_v4 WHERE DATE(news_published_date) >= SUBDATE(CURDATE(), INTERVAL 1 DAY) AND DATE(news_published_date) <= CURDATE() AND news_status = 1 AND news_get_type != 8 AND news_id not in (select news_id FROM tvbs_news_v4.news_v4_category_mapping where news_category_id=14);""" conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute(insert) rows = cur.fetchall() news_table = jsonify(rows) cur.close() conn.close() return (news_table)
def health_article_cache(): args = request.args # now = datetime.now() hour = datetime.now().hour minute = datetime.now().minute day = args.get('day') if 'day' in args else 90 health_table = cache.get('supertaste_cache_' + str(day)) if day == 90: if not health_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)): # if not news_table or(now_time >= time(00,0) and now_time <= time(00,2)) : db_config.aws_db() insert = """SELECT id AS nid, title AS title, keyword AS tag, cast(DATE(publish)as char) AS date FROM tvbs_v4.eatdrink_articles WHERE DATE(publish) >= SUBDATE(CURDATE(), INTERVAL 90 DAY) AND DATE(publish) <= CURDATE() AND status = 1;""" print('Not cache') conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute(insert) rows = cur.fetchall() health_table = jsonify(rows) health_table.status_code = 200 cache.set('supertaste_cache_' + str(day), health_table, timeout=7200) cur.close() conn.close() return health_table else: print('the day is 90 and health_caches') return health_table else: if not health_table: print('Not cache') db_config.aws_db() insert = """SELECT id AS nid, title AS title, keyword AS tag, cast(DATE(publish)as char) AS date FROM tvbs_v4.eatdrink_articles WHERE DATE(publish) >= SUBDATE(CURDATE(), INTERVAL %s DAY) AND DATE(publish) <= CURDATE() AND status = 1;""" % (day) conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute(insert) rows = cur.fetchall() health_table = jsonify(rows) health_table.status_code = 200 cache.set('supertaste_cache_' + str(day), health_table, timeout=3600) cur.close() conn.close() return health_table else: print('supertaste_cache_') return health_table
def aws_news_api(): args = request.args # now = datetime.now() hour = datetime.now().hour minute = datetime.now().minute day = args.get('day') if 'day' in args else 90 news_table = cache.get('news_cache_' + str(day)) if day == 90: if not news_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)): # if not news_table or(now_time >= time(00,0) and now_time <= time(00,2)) : db_config.aws_db() insert = """SELECT news_id AS nid, news_get_type AS get_type, news_title AS title, news_tag AS tag, news_summary AS summary, cast(DATE(news_published_date)as char) AS date FROM tvbs_news_v4.news_v4 WHERE DATE(news_published_date) >= SUBDATE(CURDATE(), INTERVAL 90 DAY) AND DATE(news_published_date) <= CURDATE() AND news_get_type != 8 AND news_status = 1 AND news_id not in (select news_id FROM tvbs_news_v4.news_v4_category_mapping where news_category_id=14);""" print('Not cache') conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute(insert) rows = cur.fetchall() news_table = jsonify(rows) news_table.status_code = 200 cache.set('news_cache_' + str(day), news_table, timeout=7200) cur.close() conn.close() return news_table else: print('the day is 90 and news_cache') return news_table else: if not news_table: print('Not cache') db_config.aws_db() insert = """SELECT news_id AS nid, news_get_type AS get_type, news_title AS title, news_tag AS tag, news_summary AS summary, cast(DATE(news_published_date)as char) AS date FROM tvbs_news_v4.news_v4 WHERE DATE(news_published_date) >= SUBDATE(CURDATE(), INTERVAL %s DAY) AND DATE(news_published_date) <= CURDATE() AND news_get_type != 8 AND news_status = 1 AND news_id not in (select news_id FROM tvbs_news_v4.news_v4_category_mapping where news_category_id=14);""" % ( day) conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute(insert) rows = cur.fetchall() news_table = jsonify(rows) news_table.status_code = 200 cache.set('news_cache_' + str(day), news_table, timeout=3600) cur.close() conn.close() return news_table else: print('news_cache') return news_table