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


Python Firebase.child方法代码示例

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


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

示例1: translate

# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import child [as 别名]
def translate():
	if not request.json:
		abort(400)
	else:
		req = request.json
		if not 'chatId' in req or not 'for' in req or not 'message' in req:
			abort(400)
		else:
			try:
				gs = goslate.Goslate()
				chatObj = Firebase('https://vivid-inferno-6896.firebaseio.com/' + req['chatId'])
				language1 = chatObj.child("language1").get()
				language2 = chatObj.child("language2").get()

				translatedText = ""

				if req['for'] == 1:
					print language1
					# translatedText = gs.translate(req['message'], language1)
					r = requests.post(microsoftAuthUrl, data=payload)
					resJSON = r.json()
					accessToken = resJSON["access_token"]
					translationParams = {"text":req['message'], "from":language2, "to":language1}
					translationUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?" + urllib.urlencode(translationParams)
					translationHeader = {'Authorization': "Bearer " + accessToken}
					r = requests.get(translationUrl, headers=translationHeader)
					print r.status_code
					print r.text
				elif req['for'] == 2:
					# translatedText = gs.translate(req['message'], language2) 
					print "Stuff"

				print translatedText
				# direct_To = firebase.get('https://vivid-inferno-6896.firebaseio.com/123456789/123456789/messages/0/for')
				# print direct_To
				# messageList = Firebase('https://vivid-inferno-6896.firebaseio.com/123456789/123456789/messages')
				# print "Before" + messageList

				# language1 = Firebase('https://vivid-inferno-6896.firebaseio.com/123456789/123456789/language1').get()
				# print language1
				# language2 = Firebase('https://vivid-inferno-6896.firebaseio.com/123456789/123456789/language2').get()
				# print language2
				# if gs.detect(inputMessage) == language1: #Confirms language of input text
				# 	outputMessage = gs.translate(inputMessage,language2);
				# #Add condition which changes value of "for" field based on last "for" value in previous message dictionary
				# messageList.post({"text":"outputMessage","for":"1","read":"false"})
				# print "After" + messageList
			except Exception, err:
				print traceback.format_exc()
开发者ID:GonMolon,项目名称:PennApps16,代码行数:51,代码来源:app.py

示例2: main

# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import child [as 别名]
def main():
	"""
	"""

	root_reference = Firebase('https://burning-fire-8681.firebaseio.com')
	this_event_ref = root_reference.child('zE0001')
	R1_ref = this_event_ref.child('R1')
	R2_ref = this_event_ref.child('R2')
	R3_ref = this_event_ref.child('R3')

	for eun in range(1,11,1):
		for R_ref in [R1_ref, R2_ref, R3_ref]:
			eu_ref = R_ref.child("eu_{}".format(get_euns(eun)))
			eu_ref.put(
				{
				"n": random.randint(0,15),
				"mn": random.randint(0,15),
				"my": random.randint(0,15),
				"y": random.randint(0,15)
				}
			)
开发者ID:AlexChick,项目名称:daeious-event-dev,代码行数:23,代码来源:__DEV__setup_firebase_structure.py

示例3: Firebase

# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import child [as 别名]
fb = Firebase('http://gamma.firebase.com/mikexstudios/zephyr')

#Subscribe to the most popular zephyr classes
zephyr.Subscriptions().add(('help', '*', '*'))
zephyr.Subscriptions().add(('sipb', '*', '*'))
zephyr.Subscriptions().add(('mxh', '*', '*')) #for testing

#To send a message, ex.
#zephyr.ZNotice(cls='sipb', message="zsig\x00Message body\n", ...).send()

#Wait for messages. It's probably better to poll for messages than to use
#blocking loop.
print 'Listening to zephyr messages...'
while True:
    m = zephyr.receive(True) #True -> blocks up to a minute
    [zsig, body] = m.message.split("\x00")
    body = body.strip()

    #Send message to Firebase
    ref = fb.child(m.cls) #separate by class
    ref.push({'class': m.cls, 
              'instance': m.instance, 
              'sender': m.sender,
              'time': m.time, #seconds since epoch
              'zsig': zsig,
              'body': body,})
    print "%s / %s / %s %s (%s)\n   %s" % (m.cls, m.instance, m.sender, 
                                           time.ctime(m.time), zsig, body)

  
开发者ID:mikexstudios,项目名称:zephyrlog,代码行数:30,代码来源:zlog.py


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