当前位置: 首页>>代码示例>>Python>>正文


Python User.all方法代码示例

本文整理汇总了Python中models.users.User.all方法的典型用法代码示例。如果您正苦于以下问题:Python User.all方法的具体用法?Python User.all怎么用?Python User.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.users.User的用法示例。


在下文中一共展示了User.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_friends_list

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
    def get_friends_list(self, user):
        twitterApi = Twitter.getInstance()
        friends_list = []
        l = []
        
        # Very bad hack. Need to move all these to model.validate
        try:
            # Twitter API doesn't allow to get all friends infor at once.
            # Instead you can only get all friends Ids and the use UserLookup
            # to get full user infor but only in batches of 100 user at once
            follow_list = twitterApi.api.GetFriendIDs(user.twitter)["ids"]

            while len(follow_list) > 100:
                l = l + twitterApi.api.UsersLookup(follow_list[0:100])
                follow_list = follow_list[100:len(follow_list)]
            l = l + twitterApi.api.UsersLookup(follow_list[0:len(follow_list)])

            for friend in l:
                friend_in_db = User.all().filter("twitter =", friend.screen_name)
                if friend_in_db.count() == 1:
                    friends_list.append(friend.screen_name)
            
        except TwitterError: 
            friends_list = ['not_authorized']

        return friends_list
开发者ID:dazbur,项目名称:languagebot,代码行数:28,代码来源:profile.py

示例2: prepareEmailMessagesGenerator

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
def prepareEmailMessagesGenerator():
    # This must be run after buildDailyList
    # Since only there a daily message limit is applied
    # though, this limit can be different for emails
    path_current = os.path.dirname(__file__)
    root_path = os.path.split(path_current)[0]
    view_path = root_path + "/views/daily_email.html"

    today = datetime.date.today()
    emails_dict = {}
    for user in User.all().filter("account_status =", "enabled").\
        filter("use_daily_email =", "yes"):

        parameters = {}
        parameters["dict_row"] = []
        for lli in LearnList.all().\
            filter("next_serve_date =", today).\
            filter("twitter_user =", user.twitter):
            l = []
            l.append(lli.dict_entry.word + " " + lli.dict_entry.pronounce)
            l.append(lli.dict_entry.meaning)
            parameters["dict_row"].append(l)
        emails_dict["email"] = user.email
        emails_dict["message"] = template.\
            render(view_path, parameters)
        yield emails_dict
开发者ID:dazbur,项目名称:languagebot,代码行数:28,代码来源:learnlist.py

示例3: get_user

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
 def get_user(self):
     """
     Gets the current user that is logged on based on session data
     """
     session_id = self.get_cookie('session')
     if session_id is not None:
         return User.all().filter('session =', session_id) \
             .filter('session_expiry >', datetime.datetime.now()).get()
开发者ID:matts1,项目名称:MajorWork-appengine,代码行数:10,代码来源:base.py

示例4: getUsers

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
def getUsers():
    userlist = []
    for user in User.all().order("-total_points").run():
        c = Dictionary.all().\
            filter("twitter_user =", user.twitter).count()
        userlist.append({"username": user.twitter, "points": user.total_points,
                        "wordscount": c})
    return json.dumps(userlist)
开发者ID:dazbur,项目名称:languagebot,代码行数:10,代码来源:rpchandler.py

示例5: sendMessagesGenerator

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
def sendMessagesGenerator(TwitterAPI, logging):
    current_time = int(time.time())
    # Are there messages to send out in next SCHEDULERUN seconds?
    next_planned_interval = current_time + SCHEDULERUN
    today = datetime.date.today()

    for lli in LearnList.all().\
        filter("next_serve_time <=", next_planned_interval):
        result = None
        # Don't send messages if user is disabled
        user = User.all().filter("twitter =", lli.twitter_user).\
            filter("account_status =", "enabled").fetch(1)
        if user == []:
            yield result
            # If user has messages in todays list but is disabled now
            # Let's just reschedule it to tomorrow
            lli.next_serve_date = addDays(lli.next_serve_date, 1)
            lli.next_serve_time = sys.maxint
            lli.put()
            continue

        # If there is a question to send, prepare a different
        # Twitter message format
        question = Question.all().filter("lli_ref =", lli).\
            filter("answer_received =", None).fetch(1)

        if question != []:
            message = prepareQuestionMessage(lli)
        else:
            message = prepareTwitterMessage(lli)

        try:
            #status = TwitterAPI.api.PostUpdate(message)
            status = TwitterAPI.api.PostDirectMessage(lli.twitter_user,\
             message)
            result = message
            # For questions we do no recalculate new interval right away
            # We do it when answer is recieved or no received
            # Instead we update Question entity
            if question == []:
                answer_rating = lli.latest_answer_rating
                rescheduleLearnListItem(lli, answer_rating)
            else:
                question[0].question_sent = today
                question[0].question_message_id = status.id
                question[0].put()
                # We also need to make sure this message is not sent again automatically
                # Until answer is recieved or it expires
                lli.next_serve_time = sys.maxint
                lli.put()

        except TwitterError:
            print TwitterError.message
            logging.error("Twitter error when sending message %s" % message)
        yield result
开发者ID:dazbur,项目名称:languagebot,代码行数:57,代码来源:learnlist.py

示例6: get

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
 def get(self):
     user = current_user()
     if not user:
         self.redirect("/login")
     else:
         parameters = {}
         parameters["total_points"] = User.all().\
             filter("twitter =", user.twitter).get().total_points
         parameters["total_words"] = Dictionary.all().\
             filter("twitter_user =", user.twitter).count()
         self.view(parameters)
开发者ID:dazbur,项目名称:languagebot,代码行数:13,代码来源:details.py

示例7: get

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
 def get(self):
     self.twitter = Twitter.getInstance()
     current_time = int(time.time())
     
     # Is there a user to process in next SCHEDULERUN seconds?
     next_planned_interval = current_time + SCHEDULERUN
      
     for user in User.all().filter("account_status =","enabled").filter("next_run_time <=", next_planned_interval):
         next_run_time = current_time + self.getNextRunInterval(user.messages_per_day)
         user.next_run_time = next_run_time
         user.put()
         message = self.postMessage(user)
开发者ID:dazbur,项目名称:languagebot,代码行数:14,代码来源:sendmessages.py

示例8: get

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
 def get(self):
     user_name = self.request.path.split('/')[-1]
     viewed_user = User.all().filter("username =", user_name)\
                             .get()
     curr_user = current_user()
     # If non-existing user is specified on URL
     if (user_name != "") and (viewed_user is None):
         self.error(404)
     if viewed_user:
         parameters = getParameters(viewed_user)
         self.view(parameters, "views/view_vocabulary.html")
     elif curr_user:
         parameters = getParameters(curr_user)
         self.view(parameters, "views/vocabulary.html")
开发者ID:dazbur,项目名称:languagebot,代码行数:16,代码来源:vocabulary.py

示例9: update_followed_by_list

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
    def update_followed_by_list(self, add_list, remove_list, by_user):
        # First add current user to followed_by lists for all users he follows
        for user in add_list:
            
            dbUser =  User.all().filter("twitter =", user).fetch(1)[0]
            followed_by_list = dbUser.followed_by.split(',')
            if '' in followed_by_list:
                followed_by_list.remove('')
            if not by_user in followed_by_list:
                followed_by_list.append(by_user)
            dbUser.followed_by = ",".join(followed_by_list)
            dbUser.put()

        # Then remove current user from followed_by list for all user he
        # stopped following
        for user in remove_list:
            dbUser =  User.all().filter("twitter =", user).fetch(1)[0]
            followed_by_list = dbUser.followed_by.split(',')
            if '' in followed_by_list:
                followed_by_list.remove('')
            if by_user in followed_by_list:
                followed_by_list.remove(by_user)
            dbUser.followed_by = ",".join(followed_by_list)
            dbUser.put()
开发者ID:dazbur,项目名称:languagebot,代码行数:26,代码来源:profile.py

示例10: processMessage

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
def processMessage(message):
    today = datetime.date.today()
    # You can get addressee name by checking current
    # Twitter bot username, but this requires additional API call
    twitter_user = message.sender_screen_name
    # Get User
    user = User.all().filter("twitter =", twitter_user).get()
    # Exit if user is not registred. This is to avoid spam
    if not user:
        return
    parsed_dict = parseMessage(message.text, message.recipient_screen_name)
    # Exit if message is not a valid dict_entry format
    if parsed_dict == {}:
        return
    question = checkForAnswer(parsed_dict, twitter_user)

    # Check if message is an answer to a previously sent question
    if question:
        answer_rating = calculateAnswerRating(question.lli_ref.dict_entry.meaning,\
             parsed_dict["meaning"])
        question.answer_received = today
        question.answer_rating = answer_rating
        question.lli_ref.latest_answer_rating = answer_rating
        question.answer_text = parsed_dict["meaning"]
        question.put()
        question.lli_ref.put()
        if (user.total_points + answer_rating) > 0:
            user.total_points = user.total_points + answer_rating
        else:
            user.total_points = 0
        user.put()
        # If answer_rating is very poor, we need to show correct answer right away
        # else reschedule as normal accorsing to answer_rating
        if answer_rating < 0:
            question.lli_ref.next_serve_time = 0
            question.lli_ref.next_serve_date = today
            question.put()
            question.lli_ref.put()
        else:
            rescheduleLearnListItem(question.lli_ref, answer_rating)
        return
    # If message is a valid dictionary entry -- save it to database
    addNewWord(parsed_dict, user, message.id)
    user.put()
开发者ID:dazbur,项目名称:languagebot,代码行数:46,代码来源:incoming.py

示例11: post

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
    def post(self):
        model = {}
        username = self.request.get("username")
        password = self.request.get("password")
        
        model["user_name"] = username
        model["password"] = password

        # load user by username and password...
        user = User.all()\
                .filter("username =", username)\
                .filter("password =", password)\
                .get()
        if user:
            set_current_user(user)
            self.redirect("/")
        else:
            model["login"] = "fail"
            self.response.out.write(template.render("views/login.html", model))
开发者ID:randomdeveloper,项目名称:drinkdrankdrunk,代码行数:21,代码来源:login.py

示例12: buildDailyList

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
def buildDailyList(day, logging):
    logging.debug("Entered Build Daily List")
    current_timestamp = int(time.time())
    for user in User.all().filter("account_status =", "enabled"):
        llQuery = LearnList.all().filter("twitter_user =",\
                user.twitter).filter("next_serve_date =", day)
        use_questions = user.use_questions
        utc_offset = 0
        if user.utc_offset != None:
            utc_offset = user.utc_offset
        i = 0
        message_list = []
        for learnListItem in llQuery.run():
            # If we are within limit of messages per dat, keep adding
            if i < user.messages_per_day:
                message_list.append(learnListItem)
                i = i + 1
            # if we exceeded limit per day, reschedule to next day
            else:
                learnListItem.next_serve_date =\
                     addDays(learnListItem.next_serve_date, 1)
                learnListItem.put()
                i = i + 1
        # Set next run timestamp for words scheduled for today
        interval_gen = getNextRunInterval(len(message_list))
        for l in message_list:
            try:
                time_shift = FIRSTMESSAGEHOUR * 3600 - utc_offset * 3600
                s = interval_gen.next()
                l.next_serve_time = current_timestamp + s + time_shift
                # Create new question entry for every second serve
                # If user has this option enabled
                if use_questions == "yes" and (l.total_served % 2 == 0):
                    q = Question()
                    q.lli_ref = l
                    q.twitter_user = user.twitter
                    q.word = l.dict_entry.word
                    q.put()
                l.put()
            except StopIteration:
                pass
开发者ID:dazbur,项目名称:languagebot,代码行数:43,代码来源:learnlist.py

示例13: testProcessMessageNormalAddForExistingUser

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
 def testProcessMessageNormalAddForExistingUser(self):
     json_file = open("files/direct_message1.json")
     message_json = simplejson.load(json_file)
     twitter_dm = DirectMessage.NewFromJsonDict(message_json)
     processMessage(twitter_dm)
     query = Dictionary.all()        
     results =   query.fetch(1)
     self.assertEqual(1, len(results))
     self.assertEqual("", results[0].pronounce)
     self.assertEqual("da_zbur", results[0].twitter_user)
     self.assertEqual(289180663729512448L, results[0].message_id)
     self.assertEqual("to advet", results[0].word)
     self.assertEqual(u"обращаться к,ссылаться на",\
      results[0].meaning)
     self.assertEqual(0, results[0].served)
     self.assertEqual(None, results[0].source_lang)
     self.assertEqual(1, User.all().filter("twitter =",\
      "da_zbur").get().total_points)
     # Test integration with LearnList
     query = LearnList.all()
     ll_results = query.fetch(2)
     self.assertEqual(1, len(ll_results))
     # Check if LearnList references same object
     self.assertEqual(ll_results[0].dict_entry.key(), results[0].key())
开发者ID:dazbur,项目名称:languagebot,代码行数:26,代码来源:tests.py

示例14: get

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
 def get(self):
     for u in User.all():
         u.total_points = 0
         u.put()
开发者ID:dazbur,项目名称:languagebot,代码行数:6,代码来源:admin.py

示例15: postMessage

# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import all [as 别名]
    def postMessage(self, user):
        #print "You are %s " % user.twitter
        words = Dictionary.all()\
                        .filter("twitter_user =", user.twitter)\
                        .filter("served < ", user.repeat_times)
            
        dict_entry_list = []
        message = ""
        
        for entry in words:
            dict_entry_list.append(entry)

        #If user has enough his own words to fill all slots for the day
        # If not we need to fill slots with words from people he follows
        if len(dict_entry_list) < user.messages_per_day:
            follow_list = user.i_follow.split(",")
            # for an empty string split() return list with one '' element
            if follow_list == ['']:
                follow_list = []
            # Let's shuffle the list so we get some variety in users
            random.shuffle(follow_list)
            for follow_user in follow_list:
                f_repeat = 0
                for f_user in User.all().filter("twitter =", follow_user):
                    f_repeat = f_user.repeat_times
                    # Getting list of languages user follows
                    follow_lang_list = f_user.follow_lang_list
                    l = []
                    for lang in follow_lang_list.split(","):
                        l.append("'"+lang+"'")
                    lang_str = "(" + ",".join(l) + ")"
                        
                words = Dictionary.all()\
                .filter("twitter_user =", follow_user)\
                .filter("served < ", f_repeat)\
                .filter("source_lang IN ", lang_str)
                for entry in words:
                    dict_entry_list.append(entry)
                    #print "Adding %s from %s" % (entry.word, follow_user)
                if len(dict_entry_list) >= user.messages_per_day:
                    break
        #print "You have %d words in your list" % len(dict_entry_list)    

        # If we have any messages to send at all
        if len(dict_entry_list) > 0:
            dict_entry = random.sample(dict_entry_list,1)[0]
            served = dict_entry.served + 1
            if dict_entry.pronounce:
                pronounce = dict_entry.pronounce
            else:
                pronounce = ""
            count = " [%s]" % served
            # If we are posting message from one of the followed_by list
            # need to add (via @username) if total message is less than 140
            # characters
            if dict_entry.twitter_user != user.twitter:
                via = "(via " + dict_entry.twitter_user + ")"
            else:
                via = ""
            
            if user.default_source_lang != dict_entry.source_lang:
                lang = " ("+dict_entry.source_lang+")"
            else:
                lang = ""

            message = dict_entry.word+lang+pronounce+": "+dict_entry.meaning+count

            if len(message+via) < 140:
                message = message + via

            if user.message_type == "reply":
                try:
                    self.twitter.api.PostUpdate("@" +  user.twitter + " " + message,
                    in_reply_to_status_id=dict_entry.message_id)
                    #print "You will be sent word %s %s" % (dict_entry.word, via)
                except TwitterError:
                    logging.error("Twitter error: %s when sending message %s" %
                    (TwitterError.message, "@" +  dict_entry.twitter_user+
                    " " + message))
                        
                # Direct message are no longer user
                #if user.message_type == "direct":
                #    self.twitter.api.PostDirectMessage(dict_entry.twitter_user, message)

            # We do not change served field for word from other users
            if via == "":
                dict_entry.served = dict_entry.served + 1
                dict_entry.put()


        return message
开发者ID:dazbur,项目名称:languagebot,代码行数:93,代码来源:sendmessages.py


注:本文中的models.users.User.all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。