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


Python User.query方法代码示例

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


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

示例1: delete_db

# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import query [as 别名]
def delete_db(drop_users=False):
  if drop_users:
    ndb.delete_multi(User.query().fetch(keys_only=True))
  ndb.delete_multi(Relay.query().fetch(keys_only=True))
  ndb.delete_multi(SentRelay.query().fetch(keys_only=True))
  ndb.delete_multi(Friendship.query().fetch(keys_only=True))
  ndb.delete_multi(FriendRequest.query().fetch(keys_only=True))
开发者ID:Magicjarvis,项目名称:relay-backend,代码行数:9,代码来源:__init__.py

示例2: getAllUsers

# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import query [as 别名]
	def getAllUsers():
		user_query = (User.query()).fetch()
		to_print_str = 'The list of registered users:\n'
		counter = 1
		for q in user_query:
			to_print_str += (str(counter) + '. ' + q.user_name + '\n')
			counter += 1

		return to_print_str
开发者ID:nelsongoh,项目名称:tembotsu,代码行数:11,代码来源:registration.py

示例3: signUp

# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import query [as 别名]
	def signUp(username, userid):
		CONST_ERROR_ALR_REG = 0
		CONST_OPTION_REG_SUCCESS = 1

		user_query = (User.query()).fetch()	# Get all users in the datastore
		# If this user already exists
		if (any(q.user_id == userid for q in user_query)):
			return CONST_ERROR_ALR_REG
		# Else if this user has not been registered
		else:
			new_user = User(user_name=str(username), user_id=userid)
			new_user.put()
			return CONST_OPTION_REG_SUCCESS
开发者ID:nelsongoh,项目名称:tembotsu,代码行数:15,代码来源:registration.py

示例4: run

# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import query [as 别名]
    def run(self, incoming_msg=None):

        # If there actually is a message to be broadcasted
        if ((incoming_msg is not None) and (incoming_msg is not '') and (incoming_msg is not ' ')):
            # Retrieve all registered members
            all_users = (User.query()).fetch()
            # For each registered user
            for each_user in all_users:
                # Send them an update message
                try:
                    resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
                        'chat_id': str(each_user.user_id),
                        'text': incoming_msg.encode('utf-8'),
                        'disable_web_page_preview': 'true',
                    })).read()
                # Catch the HTTP error exception, usually happens if the user has not initiated a message
                # with the bot
                except urllib2.HTTPError:
                    continue
            return
开发者ID:nelsongoh,项目名称:tembotsu,代码行数:22,代码来源:eventannouncer.py

示例5: getBusNums

# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import query [as 别名]
    def getBusNums(path, busStopNum, userId):
        # API parameters
        uri = 'http://datamall2.mytransport.sg/' # Main URL

        # Build the query string and specify the type of API calls
        target = urlparse(uri + path)
        method = 'GET'
        body = ''
        headers = { 'AccountKey' : 'WSqBv4EpQQuPWrFBJNGdVA==',
                    'UniqueUserID' : '4a00c635-e027-45af-a793-c34ac1a293d9',
                    'accept' : 'application/json' } # Results in JSON format

        # HTTP Handler
        h = http.Http()

        # Results
        response, content = h.request(
            target.geturl(),
            method,
            body,
            headers
        )

        content = ast.literal_eval(content)
        list_of_buses = []  # List of all buses at this bus stop
        for each_bus_detail in content['Services']:
            list_of_buses.append('/bus: ' + str(each_bus_detail['ServiceNo']))

        if (len(list_of_buses) != 0):
            user_query = (User.query()).fetch()
            for q in user_query:
                if (q.user_id == userId):   # If this is the user we are looking for
                    q.user_bus_stop_reply = int(busStopNum)
                    q.put()
                    break

        return list_of_buses
开发者ID:nelsongoh,项目名称:tembotsu,代码行数:39,代码来源:lta.py

示例6: post

# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import query [as 别名]

#.........这里部分代码省略.........
                buses_at_stop = Bus.getBusNums(path, '19051', fr['id'])
                output_msg = 'Please select a bus:'
                Keyboard.one_time_btn_keyboard(Utils.arrSeparator(buses_at_stop), chat_id, message_id, output_msg)
                return

            elif (text.lower() == '/oppbuona'):
                path = 'ltaodataservice/BusArrival?BusStopID=11369&SST=True'
                buses_at_stop = Bus.getBusNums(path, '11369', fr['id'])
                output_msg = 'Please select a bus:'
                Keyboard.one_time_btn_keyboard(Utils.arrSeparator(buses_at_stop), chat_id, message_id, output_msg)
                return

            elif ('/bus' in text.lower()):
                CONST_ERROR_BUS_STOP_NAN = 0    # This error ID is if the bus stop number is NaN
                #CONST_ERROR_BUS_NUM_NAN = 2        # This error ID is if the bus number is NaN
                CONST_OPTION_GET_BUSES = 1  # This option ID is for getting a list of buses for a given bus stop
                CONST_OPTION_GET_BUS_TIMING = 3 # This option ID is for getting the bus arrival timing for a given bus at a given bus stop
                CONST_OPTION_GET_SHORTCUT = 4   # This option ID is for getting the bus timings for favourited buses

                option_id = Bus.busTextParser(text.lower())

                if (option_id == CONST_ERROR_BUS_STOP_NAN):
                    error_msg_reply = 'Please enter a bus stop NUMBER.'
                    Keyboard.norm_keyboard_reply(chat_id, message_id, error_msg_reply)
                    return

                # Removed because there may be bus numbers that contain alphabets, e.g. 70M
                #elif (option_id == CONST_ERROR_BUS_NUM_NAN):
                #   error_msg_reply = 'Please enter a bus NUMBER.'
                #   norm_keyboard_reply(error_msg_reply)
                #   return

                elif (option_id == CONST_OPTION_GET_SHORTCUT):
                    user_query = (User.query()).fetch()
                    for q in user_query:
                        if (q.user_id == fr['id']): # If this is the user we are looking for
                            bus_stop_num = q.user_bus_stop_reply    # Get the bus stop number this user is referring to
                            if (bus_stop_num != 0): # If there is an actual bus stop number, i.e. NOT 0
                                bus_num = text.lower().split(' ', 1)[1]
                                path = '/ltaodataservice/BusArrival?BusStopID=' + str(bus_stop_num) + '&ServiceNo=' + bus_num + '&SST=True'
                                bus_arr_timing_msg = Bus.getBusTiming(path) # Get the bus timing
                                Keyboard.norm_keyboard_reply(chat_id, message_id, bus_arr_timing_msg)
                                q.user_bus_stop_reply = 0   # Reset the user's bus stop that they are referring to, to 0
                                q.put() # Update the Datastore
                                return
                            else:   # If there is no actual bus stop number stored
                                Keyboard.norm_keyboard_reply(chat_id, message_id, 'Tembotsu does not know which bus stop you are referring to, check your bus timing again.')
                                return
                    # If the code reaches this point, this means that the user cannot be found in our datastore
                    # Prompt the user to register first before using
                    str_reply = 'I\'m sorry but I can\'t find you in our database! Please type /reg to register before using the rest of the bot!'
                    Keyboard.norm_keyboard_reply(chat_id, message_id, str_reply)
                    return

                elif (option_id == CONST_OPTION_GET_BUSES):
                    bus_stop_num = text.lower().split(' ')[1]
                    path = '/ltaodataservice/BusArrival?BusStopID=' + bus_stop_num + '&SST=True'
                    buses_at_stop = Bus.getBusNums(path, bus_stop_num, fr['id'])

                    if (len(buses_at_stop) == 0):   # If there are no buses at this bus stop
                        str_reply = 'There are no buses for bus stop number: ' + str(bus_stop_num)
                        Keyboard.norm_keyboard_reply(chat_id, message_id, str_reply)
                        return

                    else:   # If there are buses at this bus stop
                        output_msg = 'Please select a bus:'
开发者ID:nelsongoh,项目名称:tembotsu,代码行数:70,代码来源:main.py


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