本文整理汇总了Python中HelperFunctions.generateKey方法的典型用法代码示例。如果您正苦于以下问题:Python HelperFunctions.generateKey方法的具体用法?Python HelperFunctions.generateKey怎么用?Python HelperFunctions.generateKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HelperFunctions
的用法示例。
在下文中一共展示了HelperFunctions.generateKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addOfflineChallenge
# 需要导入模块: import HelperFunctions [as 别名]
# 或者: from HelperFunctions import generateKey [as 别名]
def addOfflineChallenge(self , fromUser, toUid , challengeData, offlineChallengeId=None):
toUser = self.getUserByUid(toUid)
offlineChallenge = OfflineChallenge()
if(offlineChallengeId!=None):
offlineChallenge.offlineChallengeId = offlineChallengeId
else:
offlineChallenge.offlineChallengeId = HelperFunctions.generateKey(10)
offlineChallenge.fromUid_userChallengeIndex = fromUser.uid+"_"+str(fromUser.userChallengesIndex.index) # yeah , its a little bit funny too
offlineChallenge.toUid_userChallengeIndex = toUid+"_"+str(toUser.userChallengesIndex.getAndIncrement(toUser).index)
offlineChallenge.challengeData = challengeData
offlineChallenge.save()
return offlineChallenge
示例2: addOfflineChallenge
# 需要导入模块: import HelperFunctions [as 别名]
# 或者: from HelperFunctions import generateKey [as 别名]
def addOfflineChallenge(self , fromUser, toUid , challengeData, offlineChallengeId=None):
toUser = self.getUserByUid(toUid)
offlineChallenge = OfflineChallenge()
if(offlineChallengeId!=None):
offlineChallenge.offlineChallengeId = offlineChallengeId
else:
offlineChallenge.offlineChallengeId = HelperFunctions.generateKey(10)
offlineChallenge.fromUid_userChallengeIndex = fromUser.uid+"_"+str(fromUser.userChallengesIndex.index) # yeah , its a little bit funny too # fuck you , i was not funny , that was over optimization for an unreleased app !!!
offlineChallenge.toUid_userChallengeIndex = toUid+"_"+str(toUser.userChallengesIndex.getAndIncrement(toUser).index)
offlineChallenge.challengeData = challengeData
offlineChallenge.save()
return offlineChallenge
示例3: generateProgressiveQuiz
# 需要导入模块: import HelperFunctions [as 别名]
# 或者: from HelperFunctions import generateKey [as 别名]
def generateProgressiveQuiz(quizId , uids):
quiz = dbUtils.getQuizDetails(quizId)
if(quizId):
nQuestions = quiz.nQuestions
else:
nQuestions = 7
questions = dbUtils.getRandomQuestions(quiz)
id = HelperFunctions.generateKey(10)
userStates={}
for i in uids:
userStates[i]={}
runningQuizes[id] = quizState = { QUESTIONS: questions,
CURRENT_QUESTION :0,
N_CURRENT_QUESTION_ANSWERED:[],
USERS:userStates,##{uid:something}
CREATED_AT:datetime.datetime.now(),
POINTS:{},
N_CURRENT_REMATCH_REQUEST:set(),
N_CURRENT_USERS_READY:set()
}
return id , quizState
示例4: open
# 需要导入模块: import HelperFunctions [as 别名]
# 或者: from HelperFunctions import generateKey [as 别名]
def open(self, user=None):
# print self.request.arguments
runningQuizId = self.get_argument("isRunningQuiz", None)
self.isChallenge = isChallenge = self.get_argument("isChallenge", None) # uid of other user
self.isChallenged = isChallenged = self.get_argument("isChallenged", None) # uid of the first user
quizId = self.get_argument("quizId")
if runningQuizId:
pass
self.quiz = quiz = dbUtils.getQuizDetails(quizId)
self.quizPoolWaitId = quizPoolWaitId = "_".join(quiz.tags) + "_" + str(quiz.nPeople)
self.user = user
self.uid = user.uid
if isChallenge != None:
self.quizPoolWaitId = quizPoolWaitId = self.user.uid + "_" + HelperFunctions.generateKey(10)
elif isChallenged != None:
self.quizPoolWaitId = quizPoolWaitId = isChallenged
quizConnections = quizWaitingConnectionsPool.get(quizPoolWaitId, None)
if quizConnections:
quizConnections.append(self)
else:
if not isChallenged: # not challenge type , so we add insert into new pool
quizConnections = quizWaitingConnectionsPool[quizPoolWaitId] = [self]
else: # is challenged then user have definitely left
self.write_message(json.dumps({"messageType": USER_HAS_LEFT_POOL}))
return # client should close connection after this
self.quizConnections = quizConnections
# print self.user
# print self.uid
# print self.quizConnections
if isChallenge != None: # send notification to other user
addToGcmQueue(
self.isChallenge,
{
"fromUser": self.uid,
"fromUserName": self.user.name,
"quizPoolWaitId": self.quizPoolWaitId,
"serverId": Config.serverId,
"quizId": quiz.quizId,
"quizName": quiz.name,
"messageType": NOTIFICATION_GCM_CHALLENGE_NOTIFICATION,
"timeStamp": HelperFunctions.toUtcTimestamp(datetime.datetime.now()),
},
)
if len(quizConnections) >= int(quiz.nPeople): # we have enough people
self.quizConnections = [
quizConnections.pop() for i in range(0, quiz.nPeople)
] # nPeople into current quiz
uids = map(lambda x: x.uid, self.quizConnections)
_runningQuizId, _runningQuiz = generateProgressiveQuiz(quiz.quizId, uids)
for conn in self.quizConnections:
conn.runningQuizId = _runningQuizId
conn.runningQuiz = _runningQuiz
if conn != self:
conn.quizConnections = self.quizConnections
# question_one = self.runningQuiz[QUESTIONS][0]
self.broadcastToAll(
{
"messageType": LOAD_QUESTIONS,
"payload": self.runningQuizId,
"payload1": "[" + ",".join(map(lambda uid: dbUtils.getUserByUid(uid).toJson(), uids)) + "]",
"payload2": "[" + ",".join(map(lambda x: x.to_json(), self.runningQuiz[QUESTIONS])) + "]",
},
self.quizConnections,
)
示例5: registerUser
# 需要导入模块: import HelperFunctions [as 别名]
# 或者: from HelperFunctions import generateKey [as 别名]
def registerUser(self, name, deviceId, emailId, pictureUrl, coverUrl , birthday, gender, place, ipAddress,facebookToken=None , gPlusToken=None, isActivated=False, preUidText = "" , fbUid=None, gPlusUid=None , gPlusFriends = None , fbFriends = [], connectUid=None):
if(connectUid!=None):
user = Users.objects(uid=connectUid)
else:
user = Users.objects(emailId=emailId)
if(user or len(user)>0):
user = user.get(0)
else:
user = Users()
user.uid = preUidText+HelperFunctions.generateKey(10)
user.stats = {}
user.winsLosses = {}
user.activationKey = ""
user.badges = []
user.offlineChallenges = []
#user feed index , # few changes to the way lets see s
user.userFeedIndex = userFeedIndex = UserActivityStep()
userFeedIndex.uid = user.uid+"_feed"
userFeedIndex.index = 0
userFeedIndex.userLoginIndex = 0
userFeedIndex.save()
###
user.userChallengesIndex = userChallengesIndex = UserActivityStep()
userChallengesIndex.uid = user.uid+"_challenges"
userChallengesIndex.index = 0
userChallengesIndex.userLoginIndex = 0
userChallengesIndex.save()
###
user.subscribers = []
user.subscribedTo = []
user.emailId = emailId
user.createdAt = datetime.datetime.now()
user.loginIndex = 0
subscribersList = []
if(fbUid!=None):
user.fbUid = fbUid
newFriends = []
if(user.fbFriends==None):
newFriends= fbFriends
else:
newFriends = list(set(fbFriends) - set(json.loads(user.fbFriends)))
for i in newFriends:
if(i==fbUid): continue
user2 = Users.objects(fbUid = i)
if(user2):
user2= user2.get(0)
# mutual friends
subscribersList.append(user2)
if(gPlusUid!=None):
user.gPlusUid = gPlusUid
newFriends = []
if(user.gPlusFriends==None):
newFriends= gPlusFriends
else:
newFriends = list(set(gPlusFriends) - set(json.loads(user.gPlusFriends)))
for i in newFriends:
if(i==gPlusUid): continue
user2 = Users.objects(gPlusUid = i)
if(user2):
user2= user2.get(0)
subscribersList.append(user2)
# mutual friends
user.newDeviceId = deviceId
user.name = name
user.deviceId = deviceId
user.pictureUrl = pictureUrl
user.coverUrl = coverUrl
user.birthday = birthday
user.gender = gender
user.place = place
user.ipAddress = ipAddress
user.facebook = facebookToken if facebookToken!=None else user.facebook
user.googlePlus = gPlusToken if gPlusToken!=None else user.googlePlus
user.isActivated = isActivated
user.save()
for user2 in subscribersList:
self.addsubscriber(user, user2)
self.addsubscriber(user2, user)
self.publishFeedToUser(user.uid, user2, FEED_USER_JOINED, user.uid,None)
return user
示例6: main
# 需要导入模块: import HelperFunctions [as 别名]
# 或者: from HelperFunctions import generateKey [as 别名]
def main():
global dbUtils
global routerServer
global logger
global HTTP_PORT
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--port", help="display a square of a given number",
type=int, required=True)
parser.add_argument("--isFirstInit", help="display a square of a given number",
type=bool)
parser.add_argument("--gcmServerAuth", help="gcm key for push notifications",
type=str)
parser.add_argument("--serverId", help="serverId",
type=str, required=True)
parser.add_argument("--serverAddr", help="external ip address ",
type=str , required=True)
parser.add_argument("--serverGroup", help="unique to identify group , like main , development-1 etc",
type=str)
args = parser.parse_args()
Config.serverGroup = args.serverGroup if args.serverGroup else Config.serverGroup
Config.serverId = args.serverId
Utils.logger = logger = create_timed_rotating_log('quizapp_logs/quizapp'+"_"+Config.serverId+'.log')
logger.info("PROCESS_PID: "+str(os.getpid()))
logger.info("initializing dbUtils..")
Utils.dbUtils = dbUtils = Db.DbUtils(Config.dbServer)#initialize Db
# if(not args.serverAddr.endswith(str(args.port))):
# print "Serveradd should end with port, continue only if you have configured domain-name:port to your serving host"
if(not args.serverAddr.startswith("http")):
print "Serveraddr should shart with http or https"
return
if(dbUtils.isServerIdExists(Config.serverId, Config.serverGroup)):
print "there is already a server entry with the same serverId %s in this group %s clear , if there is no such such server running you can continue"% (Config.serverId, Config.serverGroup)
if(raw_input("y/n : ").lower()=="n"):
return
dbUtils.updateServerMap({Config.serverId: args.serverAddr }, Config.serverGroup)
##generate a random key and send an email to help manage
dbUtils.addSecretKey(HelperFunctions.generateKey(10))
logger.info("initialing router utilities")
Utils.routerServer = routerServer = RouterServerUtils.RouterServerUtils(dbUtils)
HTTP_PORT = args.port
if(args.isFirstInit):
from CreateBots import createBots
bots = createBots(dbUtils, Db.UserWinsLosses)
logger.info("creating bots..")
print bots
dbUtils.loadBotUids()
if(not args.gcmServerAuth):
print "You must supply a gcm key on first init"
return
if(args.gcmServerAuth):
dbUtils.config("gcmauth",args.gcmServerAuth)
reloadGcmConfig()
http_server = tornado.httpserver.HTTPServer(QuizApp())
http_server.listen(HTTP_PORT)
## this should be moved to seperate queuing service
tornado.ioloop.PeriodicCallback(sendGcmMessages, 2000).start()
tornado.ioloop.IOLoop.instance().start()