コード例 #1
0
ファイル: views.py プロジェクト: Zkiie/StockNewsGAE
    def get(self):
        user = users.get_current_user()
        if not user:
            self.response.out.write(
                '<html><body><a href="%s">Sign in or register</a>.</body></html>'
                % users.create_login_url('/'))
        profile = UserProfile.get_or_insert(user.user_id())

        if len(profile.key_word) < 1:
            self.redirect("/")

        # keys = EntryCollect.query(EntryCollect.key_word.IN(profile.key_word)).order(-EntryCollect.published)
        # top_entry = ndb.get_multi(keys.fetch(20, keys_only=True))

        keys = EntryCollect.query().order(-EntryCollect.published)
        entrys = ndb.get_multi(keys.fetch(PER_PAGE * 2, keys_only=True))
        top_entry = []
        for entry in entrys:
            if set(profile.key_word).intersection(set(entry.key_word)):
                top_entry.append(entry)

        template_values = {
            'user': user,
            'ecs': top_entry,
            "logout": users.create_logout_url('/'),
            "login": users.create_login_url('/'),
            'user_key_word': profile.key_word,
        }
        path = os.path.join(
            os.path.dirname(__file__) + '/templates/', 'index.html')
        self.response.out.write(template.render(path, template_values))
コード例 #2
0
ファイル: views.py プロジェクト: lichenxi/StockNewsGAE
    def get(self):
        user = users.get_current_user()
        if not user:
            self.response.out.write('<html><body><a href="%s">Sign in or register</a>.</body></html>' % users.create_login_url('/'))
        profile = UserProfile.get_or_insert(user.user_id())

        if len(profile.key_word) < 1:
            self.redirect("/")

        # keys = EntryCollect.query(EntryCollect.key_word.IN(profile.key_word)).order(-EntryCollect.published)
        # top_entry = ndb.get_multi(keys.fetch(20, keys_only=True))


        keys = EntryCollect.query().order(-EntryCollect.published)
        entrys = ndb.get_multi(keys.fetch(PER_PAGE*2, keys_only=True))
        top_entry = []
        for entry in entrys:
            if set(profile.key_word).intersection(set(entry.key_word)):
                top_entry.append(entry)

        template_values = {
            'user': user,
            'ecs': top_entry,
            "logout": users.create_logout_url('/'),
            "login": users.create_login_url('/'),
            'user_key_word': profile.key_word,

        }
        path = os.path.join(os.path.dirname(__file__)+'/templates/', 'index.html')
        self.response.out.write(template.render(path, template_values))
コード例 #3
0
ファイル: views.py プロジェクト: lichenxi/StockNewsGAE
    def get(self, keyword):

        user = users.get_current_user()
        if user:
            profile = UserProfile.get_or_insert(user.user_id())
            user_key_word = profile.key_word
        else:
            user_key_word = None

        # q = EntryCollect.query(EntryCollect.key_word == keyword).order(-EntryCollect.published)
        # top_entry = ndb.get_multi(q.fetch(50, keys_only=True))
        keys = EntryCollect.query().order(-EntryCollect.published)
        entrys = ndb.get_multi(keys.fetch(PER_PAGE*2, keys_only=True))
        top_entry = []
        for entry in entrys:
            if keyword.decode('utf-8') in entry.key_word:
                top_entry.append(entry)

        template_values = {
            'user': user,
            'ecs': top_entry,
            "logout": users.create_logout_url('/'),
            "login": users.create_login_url('/'),
            'user_key_word': user_key_word,
            'keyword': keyword
        }
        path = os.path.join(os.path.dirname(__file__)+'/templates/', 'index.html')
        self.response.out.write(template.render(path, template_values))
コード例 #4
0
ファイル: views.py プロジェクト: Zkiie/StockNewsGAE
    def get(self, keyword):

        user = users.get_current_user()
        if user:
            profile = UserProfile.get_or_insert(user.user_id())
            user_key_word = profile.key_word
        else:
            user_key_word = None

        # q = EntryCollect.query(EntryCollect.key_word == keyword).order(-EntryCollect.published)
        # top_entry = ndb.get_multi(q.fetch(50, keys_only=True))
        keys = EntryCollect.query().order(-EntryCollect.published)
        entrys = ndb.get_multi(keys.fetch(PER_PAGE * 2, keys_only=True))
        top_entry = []
        for entry in entrys:
            if keyword.decode('utf-8') in entry.key_word:
                top_entry.append(entry)

        template_values = {
            'user': user,
            'ecs': top_entry,
            "logout": users.create_logout_url('/'),
            "login": users.create_login_url('/'),
            'user_key_word': user_key_word,
            'keyword': keyword
        }
        path = os.path.join(
            os.path.dirname(__file__) + '/templates/', 'index.html')
        self.response.out.write(template.render(path, template_values))
コード例 #5
0
ファイル: controller.py プロジェクト: Zkiie/StockNewsGAE
 def get(self):
     entrys = EntryCollect.query(EntryCollect.need_notice == True).order(-EntryCollect.published).fetch()
     # q_entry = EntryCollect.query().order(-EntryCollect.published)
     # entrys = ndb.get_multi(q_entry.fetch(CONT*2, keys_only=True))
     for entry in entrys:
         if entry.need_notice and len(entry.key_word) > 0:
             self.push_msg(entry)
     self.response.out.write("It's done!")
コード例 #6
0
ファイル: controller.py プロジェクト: Zkiie/StockNewsGAE
 def get(self):
     entrys = EntryCollect.query(EntryCollect.need_collect_word == True).order(-EntryCollect.published).fetch()
     # q = EntryCollect.query().order(-EntryCollect.published)
     # entrys = ndb.get_multi(q.fetch(CONT*2, keys_only=True))
     for entry in entrys:
         if entry.need_collect_word:
             self.collect_word(entry)
     self.response.out.write("It's done!")
コード例 #7
0
ファイル: views.py プロジェクト: lichenxi/StockNewsGAE
    def get(self):
        q = EntryCollect.query().order(-EntryCollect.published)
        top_entry = ndb.get_multi(q.fetch(PER_PAGE, keys_only=True))
        user = users.get_current_user()
        if user:
            profile = UserProfile.get_or_insert(user.user_id())
            user_key_word = profile.key_word
        else:
            user_key_word = None

        template_values = {
            'user': user,
            'ecs': top_entry,
            "logout": users.create_logout_url('/'),
            "login": users.create_login_url('/'),
            'user_key_word': user_key_word
        }
        path = os.path.join(os.path.dirname(__file__)+'/templates/', 'index.html')
        self.response.out.write(template.render(path, template_values))
コード例 #8
0
ファイル: views.py プロジェクト: Zkiie/StockNewsGAE
    def get(self):
        q = EntryCollect.query().order(-EntryCollect.published)
        top_entry = ndb.get_multi(q.fetch(PER_PAGE, keys_only=True))
        user = users.get_current_user()
        if user:
            profile = UserProfile.get_or_insert(user.user_id())
            user_key_word = profile.key_word
        else:
            user_key_word = None

        template_values = {
            'user': user,
            'ecs': top_entry,
            "logout": users.create_logout_url('/'),
            "login": users.create_login_url('/'),
            'user_key_word': user_key_word
        }
        path = os.path.join(
            os.path.dirname(__file__) + '/templates/', 'index.html')
        self.response.out.write(template.render(path, template_values))
コード例 #9
0
ファイル: controller.py プロジェクト: Zkiie/StockNewsGAE
 def del_old_entry():
     earliest = datetime.datetime.now() - datetime.timedelta(days=ENTRY_SAVE_DAYS)
     keys = EntryCollect.query(EntryCollect.published <= earliest).fetch(keys_only=True)
     ndb.delete_multi(keys)