Ejemplo n.º 1
0
 def test_insert_news(self):
     name = "test suitcase"
     Topics_model.db_insert_one_topic(name)
     topic_obj = Topics_model.db_get_one_topic_by_name(name)
     c_date =  timezone.now()
     News_model.db_insert_one_news(_title="test news title", _news_date=c_date, _summary="testing_news_summary_16",
                                   _news_url="wwww.google", _topic=topic_obj,
                                   _image_url="https://pbs.twimg.com/profile_images/626307178563960833/lKjVudoW.jpg")
Ejemplo n.º 2
0
 def db2_get_n_recent_hot_topic_rest(topics_num, topics_start):
     topic_set = Topics_model.db_get_n_recent_hot_topics_rest(
         topics_num, topics_start)
     if topic_set is not None:
         return topic_set
     else:
         return None
Ejemplo n.º 3
0
def cluster_test_flow():
    try:
        test_topic_name = "White House Press Secretary"
        test_topic = Topics_model.db_get_one_topic_by_name(test_topic_name)
        if test_topic is None:
            return None
        one_topic_news_dynamic_cluster_flow(test_topic)
    except Exception as e:
        logger.error("cluster_test_flow() failed: " + str(e))
Ejemplo n.º 4
0
def generate_news(topic):
    topic_obj = Topics_model.db_get_one_topic_by_name(topic)
    news_date = timezone.now()
    news_url = "https://www.google.ie/"
    img_url = "http://lorempixel.com/400/250/"
    if topic_obj is not None:
        for i in range(3):
            news_title = topic + " - news - " + str(i)
            summary = topic + " - news summary - " + str(i)
            News_model.db_insert_one_news(news_title, news_date, summary,
                                          news_url, topic_obj, img_url)
Ejemplo n.º 5
0
 def db2_add_one_filter_news(news_date, news_title, news_summary,
                             news_topic_id, news_url, image_rul):
     if len(news_summary) < 200:
         return None
     if len(image_rul) < 3:
         return None
     flag = -1
     topic = Topics_model.db_get_one_topic_by_id(news_topic_id)
     if topic is not None:
         news = News_model.db_insert_one_news(news_title, news_date,
                                              news_summary, news_url, topic,
                                              image_rul)
         if news is not None:
             flag = 1
             topic.latest_filter_time = timezone.now()
             topic2 = Topics_model.db_update_one_topic(topic)
     else:
         news = None
         topic = None
     return flag, news, topic
Ejemplo n.º 6
0
 def db2_get_all_topics(start_id, amount):
     topic_list = []
     count = 0
     last_id = None
     for i in range(start_id, start_id + amount):
         topic = Topics_model.db_get_one_topic_by_id(i)
         if topic is not None:
             topic_list.append(topic)
             count = count + 1
             last_id = topic.id
     return topic_list, amount, count, last_id
Ejemplo n.º 7
0
 def db2_get_all_old_topics(start_id, amount, date_input):
     return_list = []
     count = 0
     last_id = None
     topic_list = Topics_model.db_get_all_topics_created_before_date(
         date_input)
     for topic in topic_list:
         if topic.id in range(start_id, start_id + amount):
             return_list.append(topic)
             count = count + 1
             last_id = topic.id
     return return_list, amount, count, last_id
Ejemplo n.º 8
0
def latest_cluster_time_mark_clean():
    try:
        test_topic_name = "White House Press Secretary"
        test_topic = Topics_model.db_get_one_topic_by_name(test_topic_name)
        if test_topic is None:
            return None
        test_topic.latest_filter_time = None
        test_topic.latest_cluster_time = None
        test_topic.save()

        Model_Interfaces.db2_get_filter_news_of_one_topic(
            test_topic.id).delete()
    except Exception as e:
        logger.error("latest_cluster_time_mark_clean() failed: " + str(e))
Ejemplo n.º 9
0
 def db2_add_new_topics(topic_name_list):
     flag = -1
     add_list = []
     fail_list = []
     if topic_name_list is not None:
         try:
             for name in topic_name_list:
                 topic = Topics_model.db_insert_one_topic(name)
                 if topic == None:
                     fail_list.append(name)
                     flag = 0
                 else:
                     add_list.append(name)
             if add_list == topic_name_list:
                 flag = 1
             for e_name in fail_list:
                 topic = Topics_model.db_get_one_topic_by_name(e_name)
                 if topic is not None:
                     topic.db_update_recent_hot_date()
         except Exception as e:
             logger.error("db2_add_new_topics failed: " + str(e))
             return flag, add_list, fail_list
     return flag, add_list, fail_list
Ejemplo n.º 10
0
class TopicUpdateToday(generics.ListAPIView):
    queryset = Topics_model.db_today_updated_topics()

    serializer_class = TopicsSerializer


# # api/topics_latest/N => return N topics order by id descending
# # class Topics_Latest_N(APIView):
# #     # Get top 'N' hottest topics.
# #     def get(self, request, topics_num, format=None):
# #         n_topics = Model_Interfaces.db2_get_n_recent_hot_topic(topics_num)
# #         serializer = TopicsSerializer(n_topics, many=True)
# #         if len(serializer.data)>0:
# #             return Response(serializer.data)
# #         return Response(status=status.HTTP_204_NO_CONTENT)
Ejemplo n.º 11
0
def generate_ori_news(topic):
    topic_obj = Topics_model.db_get_one_topic_by_name(topic)
    current_date = timezone.now()
    news_url = "https://www.google.ie/"
    img_url = "http://lorempixel.com/400/250/"
    if topic_obj is not None:
        for day in range(1, 5):
            news_date = current_date - timedelta(days=day)
            for i in range(randint(0, 6)):
                news_title = topic + " - day - " + str(
                    day) + " - news - " + str(i)
                summary = topic + " - day - " + str(
                    day) + " - news summary - " + str(i)
                Ori_News_model.db_insert_one_news(news_title, news_date,
                                                  summary, news_url, topic_obj,
                                                  img_url)
Ejemplo n.º 12
0
 def test_get_topic_name(self):
     name = self.topic.topic_name
     topic_check = Topics_model.db_get_one_topic_by_name(name)
     self.assertEqual(name, topic_check.topic_name)
Ejemplo n.º 13
0
def generate_news(topic):
    topic_obj = Topics_model.db_get_one_topic_by_name(topic)
    news_date = timezone.now()
    news_url = "https://www.google.ie/"
    img_url = "http://lorempixel.com/400/250/"
    if topic_obj is not None:
        for i in range(3):
            news_title = topic + " - news - " + str(i)
            summary = topic + " - news summary - " + str(i)
            News_model.db_insert_one_news(news_title, news_date, summary,
                                          news_url, topic_obj, img_url)


for name in topic_name:
    Topics_model.db_insert_one_topic(name)
    generate_news(name)


def generate_ori_news(topic):
    topic_obj = Topics_model.db_get_one_topic_by_name(topic)
    current_date = timezone.now()
    news_url = "https://www.google.ie/"
    img_url = "http://lorempixel.com/400/250/"
    if topic_obj is not None:
        for day in range(1, 5):
            news_date = current_date - timedelta(days=day)
            for i in range(randint(0, 6)):
                news_title = topic + " - day - " + str(
                    day) + " - news - " + str(i)
                summary = topic + " - day - " + str(
Ejemplo n.º 14
0
 def db2_delete_all_topics_without_news():
     Topics_model.db_delete_all_topics_without_news()
Ejemplo n.º 15
0
def generate_topics(names):
    Topics_model.db_insert_one_topic(names)
Ejemplo n.º 16
0
 def db2_get_all_topicsv2():
     topics_list = Topics_model.db_get_all_topics()
     if topics_list is not None:
         return topics_list
     else:
         return None
Ejemplo n.º 17
0
 def setUp(self):
     self.topic = Topics_model.db_insert_one_topic("Test topic")
Ejemplo n.º 18
0
 def test_insert_duplicated_topic(self):
     d_topic = Topics_model.db_insert_one_topic("Test topic")
     #print("test2", "topic2 type",type(d_topic))
     self.assertIsNone(d_topic)
Ejemplo n.º 19
0
 def db2_get_all_latest_topics(date_input):
     topic_list = Topics_model.db_get_all_recent_hot_topics(date_input)
     return topic_list
Ejemplo n.º 20
0
 def db2_topics_search(inputValue):
     topic_set = Topics_model.db_search_topics(inputValue)
     # return topic_set if len(topic_set) > 0 else None
     return topic_set
Ejemplo n.º 21
0
 def test_get_topic_name_by_unexist_id(self):
     id = 100
     name = self.topic.topic_name
     topic_check = Topics_model.db_get_one_topic_by_id(id)
     self.assertIsNone(topic_check)
Ejemplo n.º 22
0
 def test_get_topic_name_by_id(self):
     id = self.topic.id
     name = self.topic.topic_name
     topic_check = Topics_model.db_get_one_topic_by_id(id)
     # self.assertIsNotNone(topic_check)
     self.assertEqual(name, topic_check.topic_name)
Ejemplo n.º 23
0
 def db2_topic_update_latest_cluster_time(topic_id, _latest_cluster_time):
     topic = Topics_model.db_update_latest_cluster_time(
         topic_id, _latest_cluster_time)
     return topic
Ejemplo n.º 24
0
 def test_get_topic_unexist_name(self):
     name = "Test topic 0"
     topic_check = Topics_model.db_get_one_topic_by_name(name)
     self.assertIsNone(topic_check)
Ejemplo n.º 25
0
 def db2_get_only_latest_topics(date_input):
     topic_list = Topics_model.db_get_all_topics_created_before_date(
         date_input)
     return topic_list
Ejemplo n.º 26
0
 def test_get_all_recent_hot_topics(self):
     today = datetime.date.today()
     topic_check = Topics_model.db_get_all_recent_hot_topics(today)
     self.assertIsNotNone(topic_check)
Ejemplo n.º 27
0
 def test_get_all_recent_hot_topics_failed(self):
     today = datetime.date(2000,1,1)
     topic_check = Topics_model.db_get_all_recent_hot_topics(today)
     self.assertEqual([],topic_check)
Ejemplo n.º 28
0
 def test_get_recent_hot_topics(self):
     topic_check = Topics_model.db_get_recent_hot_topics()
     self.assertEqual([],topic_check)
Ejemplo n.º 29
0
 def db2_get_recent_hot_topic_rest():
     topic_set = Topics_model.db_get_recent_hot_topics_rest()
     if topic_set is not None:
         return topic_set
     else:
         return None
Ejemplo n.º 30
0
import django

django.setup()
import datetime
# inmport models from your model application
from dataCollector.models import Topics_model, News_model, Medium_model
from dataCollector.model_interfaces import Model_Interfaces

# test for Topic_model
# test 1 -- test 4.1.2.1
# Test Name: Insert one new topic
# Expect Output: topic's str
print("\ntest 1 -- test 4.1.2.1")
print("Test Name: Insert one new topic")
print("Expect Output: topic's id, name, date")
topic = Topics_model.db_insert_one_topic("Technology")
temp_id = topic.id
temp_name = topic.topic_name
print("Actual Output:")
print(topic.id)
print(topic.topic_name)
print(topic.create_date)
topic.delete()

Topics_model.db_insert_one_topic("Science")
Topics_model.db_insert_one_topic("Mathematic")
Topics_model.db_insert_one_topic("Trump election")
Topics_model.db_insert_one_topic("Presentent Putin")
Topics_model.db_insert_one_topic("ISIS")
Topics_model.db_insert_one_topic("Sourth China Sea")
Topics_model.db_insert_one_topic("North Korea Nuclear Weapon")