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


Python dbclient.DbClient类代码示例

本文整理汇总了Python中dbclient.DbClient的典型用法代码示例。如果您正苦于以下问题:Python DbClient类的具体用法?Python DbClient怎么用?Python DbClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: dealWithUnencryptedMessage

	def dealWithUnencryptedMessage(message):
		'''Decide what to do with the given unencrypted message'''
		if message.messageType == Message.TYPE_CONTACT_REQUEST:
			print("Received a contact request from", message.senderId)
			# Check config to see whether we accept these or not
			if Config.getProperty(Config.KEY_ALLOW_FRIEND_REQUESTS) \
			  and MessageShuffler._isProfileStatusOk(message.senderId, [None, 'requested', 'untrusted', 'trusted']):
				# Call DbClient to store new message in inbox
				rowToStore = {"messageType":"contactrequest", "fromId":message.senderId,
					"fromName":message.senderName, "messageBody":message.message,
					"publicKey":message.publicKey, "timestamp":message.timestamp,
					"messageRead":False, "messageReplied":False}
				DbClient.addMessageToInbox(rowToStore)
		elif message.messageType == Message.TYPE_CONTACT_RESPONSE:
			print("It's an unencrypted contact response, so it must be a refusal")
			sender = DbClient.getProfile(message.senderId, False)
			if MessageShuffler._isProfileStatusOk(message.senderId, ['requested']):
				senderName = sender.get("displayName") if sender else ""
				ContactMaker.handleReceiveDeny(message.senderId)
				# Call DbClient to store new message in inbox
				rowToStore = {"messageType":"contactresponse", "fromId":message.senderId,
					"fromName":senderName, "messageBody":"", "accepted":False,
					"messageRead":False, "messageReplied":False, "timestamp":message.timestamp,
					"recipients":MessageShuffler.getOwnTorId()}
				DbClient.addMessageToInbox(rowToStore)
		else:
			print("Hä?  It's unencrypted but the message type is", message.messageType)
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:27,代码来源:messageshuffler.py

示例2: getByCities

def getByCities():

    cities = [
        "Austin, TX",
        "San Jose, CA",
        "Portland, OR",
        " New York, NY",
        "Houston, TX",
        "Boston, MA",
        "Davis, CA",
        "Palo Alto, CA",
        " Irvine, CA",
        "Olathe, KS",
        "Columbia, MD",
        " Atlanta, GA",
    ]

    param = {"q": "software engineer", "fromage": "30"}

    collectionName = "job_se_10city"
    indeedClient = ApiClient(param)
    # client.getPage(0)
    dbClient = DbClient("localhost", 27017, "jobaly")
    collection = dbClient.getCollection(collectionName)
    for city in cities:
        print "-----prcoss city %s -------" % city
        indeedClient.processQuery(collection, "l", city)
开发者ID:pkushiqiang,项目名称:jobaly,代码行数:27,代码来源:joblist_getter.py

示例3: servePage

	def servePage(self, view, url, params):
		if url == "/edit":
			selectedLang = params.get('lang', None)
			if selectedLang and len(selectedLang) == 2:
				Config.setProperty(Config.KEY_LANGUAGE, selectedLang)
				# I18nManager will be triggered here because it listens to the Config
			fsf = params.get('friendsseefriends', None)
			friendsseefriends = fsf is not None and len(fsf) > 0
			Config.setProperty(Config.KEY_ALLOW_FRIENDS_TO_SEE_FRIENDS, friendsseefriends)
			slw = params.get('showlogwindow', None)
			showlogwindow = slw is not None and len(slw) > 0
			Config.setProperty(Config.KEY_SHOW_LOG_WINDOW, showlogwindow)
			# If Config has changed, may need to update profile to include/hide friends info
			DbClient.updateContactList(friendsseefriends)
			# When friends are notified next time, the profile's hash will be calculated and sent
			afw = params.get('allowfriendrequests', None)
			allowfriendrequests = afw is not None and len(afw) > 0
			Config.setProperty(Config.KEY_ALLOW_FRIEND_REQUESTS, allowfriendrequests)
			# Save config to file in case it's changed
			Config.save()
			contents = self.buildPage({'pageTitle' : I18nManager.getText("settings.title"),
				'pageBody' : "<p>Settings changed... should I go back to settings or back to home now?</p>",
				'pageFooter' : "<p>Footer</p>"})
			view.setHtml(contents)
		else:
			pageProps = {"friendsseefriends" : "checked" if Config.getProperty(Config.KEY_ALLOW_FRIENDS_TO_SEE_FRIENDS) else "",
				"allowfriendrequests" : "checked" if Config.getProperty(Config.KEY_ALLOW_FRIEND_REQUESTS) else "",
				"showlogwindow" : "checked" if Config.getProperty(Config.KEY_SHOW_LOG_WINDOW) else "",
				"language_en":"", "language_de":""}
			pageProps["language_" + Config.getProperty(Config.KEY_LANGUAGE)] = "selected"
			#print("body:", self.formtemplate.getHtml(pageProps))
			contents = self.buildPage({'pageTitle' : I18nManager.getText("settings.title"),
				'pageBody' : self.formtemplate.getHtml(pageProps),
				'pageFooter' : "<p>Footer</p>"})
			view.setHtml(contents)
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:35,代码来源:pages.py

示例4: handleInitiate

	def handleInitiate(torId, displayName):
		'''We have requested contact with another id, so we can set up
		this new contact's name with a status of "requested"'''
		# TODO: If row already exists then get status (and name/displayname) and error with it
		# Add new row in db with id, name and "requested"
		if torId and torId != DbClient.getOwnTorId():
			DbClient.updateContact(torId, {'displayName':displayName, 'name':displayName,
			  'status':'requested'})
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:8,代码来源:contactmgr.py

示例5: _createSubpayload

	def _createSubpayload(self):
		'''Use the stored fields to pack the payload contents together'''
		if self.profileHash is None or self.profileHash == "":
			self.profileHash = DbClient.calculateHash(DbClient.getProfile())
		return self.packBytesTogether([
			self.encodeNumberToBytes(1 if self.online else 0, 1),
			self.encodeNumberToBytes(1 if self.ping else 0, 1),
			self.profileHash])
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:8,代码来源:message.py

示例6: keyFingerprintChecked

	def keyFingerprintChecked(torId):
		'''The fingerprint of this contact's public key has been checked (over a separate channel)'''
		# Check that userid exists and that status is currently "untrusted" (trusted also doesn't hurt)
		profile = DbClient.getProfile(torId, False)
		if profile and profile.get("status", "nostatus") in ["untrusted", "trusted"]:
			# Update the user's status to trusted
			DbClient.updateContact(torId, {"status" : "trusted"})
			# Trigger a StatusNotify to tell them we're online
			notify = StatusNotifyMessage(online=True, ping=True, profileHash=None)
			notify.recipients = [torId]
			DbClient.addMessageToOutbox(notify)
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:11,代码来源:contactmgr.py

示例7: broadcastOnlineStatus

	def broadcastOnlineStatus(self):
		'''Queue a status notification message for each of our trusted contacts'''
		print("Outgoing postman is broadcasting the status...")
		self._broadcasting = True
		profileList = DbClient.getContactList("trusted")
		if profileList:
			msg = StatusNotifyMessage(online=True, ping=True, profileHash=None)
			msg.recipients = [c['torid'] for c in profileList]
			DbClient.addMessageToOutbox(msg)
		self._broadcasting = False
		self.flushSignal.emit()
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:11,代码来源:postmen.py

示例8: checkAllContactsKeys

	def checkAllContactsKeys():
		for c in DbClient.getMessageableContacts():
			torId = c.get("torid", None) if c else None
			if torId:
				keyId = c.get("keyid", None)
				if not keyId:
					print("No keyid found for torid", torId)
				elif not CryptoClient.getPublicKey(keyId):
					print("CryptoClient hasn't got a public key for torid", torId)
				if not keyId or not CryptoClient.getPublicKey(keyId):
					# We haven't got their key in our keyring!
					DbClient.updateContact(torId, {"status":"requested"})
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:12,代码来源:contactmgr.py

示例9: finish

	def finish(self):
		'''Finished the key gen'''
		# Store key, name in mongo under own profile
		selectedKey = self.privateKeys[self.keypairListWidget.currentRow()]
		ownid = TorClient.getOwnId()
		# See if a name was entered before, if so use that
		myname = self.keygenParamBoxes['name'].text()
		if not myname:
			# Extract the name from the string which comes back from the key as "'Some Name (no comment) <[email protected]>'"
			myname = self.extractName(selectedKey['uids'])
		profile = {"name" : myname, "keyid" : selectedKey['keyid'], "torid" : ownid, "status" : "self", "ownprofile" : True}
		DbClient.updateContact(ownid, profile)
		return True
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:13,代码来源:startupwizard.py

示例10: main

def main(): 
    targetDb = "jobaly"
    targetClient = DbClient('localhost', 27017, targetDb) 
    srcDb = "jobaly_daily" 
    srcClient = DbClient('localhost', 27017, srcDb)
    
    targetCollName = "job1000"     
    srcCollnames = "daily_job_info_2014-06-16"
    
    srcColl = srcClient.getCollection(srcCollnames)
    targetColl = targetClient.getCollection(targetCollName)
    
    size = 1000 
    copyCollection(srcColl, targetColl, size)
开发者ID:folagit,项目名称:resumatcher,代码行数:14,代码来源:collutils.py

示例11: generateListPage

	def generateListPage(self, doEdit=False, userid=None, extraParams=None):
		self.requirePageResources(['avatar-none.jpg', 'status-self.png', 'status-requested.png', 'status-untrusted.png', 'status-trusted.png'])
		# List of contacts, and show details for the selected one (or self if userid=None)
		selectedprofile = DbClient.getProfile(userid)
		if selectedprofile is None:
			selectedprofile = DbClient.getProfile()
		userid = selectedprofile['torid']
		ownPage = userid == DbClient.getOwnTorId()

		# Build list of contacts
		userboxes = []
		for p in DbClient.getContactList():
			box = Bean()
			box.dispName = p['displayName']
			box.torid = p['torid']
			box.tilestyle = "contacttile" + ("selected" if p['torid'] == userid else "")
			box.status = p['status']
			box.isonline = Contacts.isOnline(box.torid)
			userboxes.append(box)
		# expand templates using current details
		lefttext = self.listtemplate.getHtml({'webcachedir' : Config.getWebCacheDir(), 'contacts' : userboxes})
		pageProps = {"webcachedir" : Config.getWebCacheDir(), 'person':selectedprofile}
		# Add extra parameters if necessary
		if extraParams:
			pageProps.update(extraParams)

		# See which contacts we have in common with this person
		(sharedContactIds, possIdsForThem, possIdsForMe, nameMap) = ContactMaker.getSharedAndPossibleContacts(userid)
		sharedContacts = self._makeIdAndNameBeanList(sharedContactIds, nameMap)
		pageProps.update({"sharedcontacts" : sharedContacts})
		possibleContacts = self._makeIdAndNameBeanList(possIdsForThem, nameMap)
		pageProps.update({"possiblecontactsforthem" : possibleContacts})
		possibleContacts = self._makeIdAndNameBeanList(possIdsForMe, nameMap)
		pageProps.update({"possiblecontactsforme" : possibleContacts})

		# Which template to use depends on whether we're just showing or also editing
		if doEdit:
			# Use two different details templates, one for self and one for others
			detailstemplate = self.editowndetailstemplate if ownPage else self.editdetailstemplate
			righttext = detailstemplate.getHtml(pageProps)
		else:
			detailstemplate = self.detailstemplate  # just show
			righttext = detailstemplate.getHtml(pageProps)

		contents = self.buildTwoColumnPage({'pageTitle' : I18nManager.getText("contacts.title"),
			'leftColumn' : lefttext,
			'rightColumn' : righttext,
			'pageFooter' : "<p>Footer</p>"})
		return contents
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:49,代码来源:pages.py

示例12: getPublicKey

	def getPublicKey(self, torid):
		'''Use the keyid stored in mongo, and get the corresponding public key from the Crypto module'''
		profile = DbClient.getProfile(torid)
		if profile is not None:
			keyid = profile.get('keyid', None)
			if keyid is not None:
				return CryptoClient.getPublicKey(keyid)
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:7,代码来源:message.py

示例13: main

def main():
    pageSize = 100
    startPageNo = 13
    endPageNo = 10000
    dbClient = DbClient('localhost', 27017, "SimilarQuestion")
    collection = dbClient.getCollection("question_test")
    
    questionGetter = QuestionGetter(pageSize,"python")
    for  pg in range(startPageNo, endPageNo):
        print "--get page at : %d -----" % pg
        items = questionGetter.getPage(pg)
        if items == "NO_ITEMS":
            break
        print "--page at : %d have %d questions--" % (pg, len(items))
        questionGetter.savePage(collection,items)   
        time.sleep(10)
开发者ID:pkushiqiang,项目名称:SimilarQuestions,代码行数:16,代码来源:apiclient.py

示例14: dealWithMessage

	def dealWithMessage(message):
		'''Examine the received message and decide what to do with it'''
		print("Hmm, the MessageShuffler has been given some kind of message")
		# We must be online if we've received a message
		Contacts.comeOnline(MessageShuffler.getOwnTorId())

		if message.senderMustBeTrusted:
			sender = DbClient.getProfile(message.senderId, False)
			if not sender or sender['status'] != "trusted":
				return # throw message away

		if not message.isComplete():
			print("A message of type", message.encryptionType, "was received but it's not complete - throwing away")
			return # throw message away

		# if it's not encrypted, it's for us -> save in inbox
		if message.encryptionType == Message.ENCTYPE_NONE:
			MessageShuffler.dealWithUnencryptedMessage(message)

		elif message.encryptionType == Message.ENCTYPE_SYMM:
			# if it's symmetric, forget it for now
			pass

		elif message.encryptionType == Message.ENCTYPE_ASYM:
			MessageShuffler.dealWithAsymmetricMessage(message)

		else:
			print("Hä?  What kind of encryption type is that? ", message.encryptionType)

		# Log receipt of message (do we want to know about relays at all?)
		if message.encryptionType in [Message.ENCTYPE_NONE, Message.ENCTYPE_ASYM]:
			logMessage = "Message of type: %s received from %s" % (message.getMessageTypeKey(), message.senderId)
			MessageShuffler.getTannoy().shout(logMessage)
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:33,代码来源:messageshuffler.py

示例15: generateFingerprintsPage

	def generateFingerprintsPage(self, userid):
		'''Build the page for checking the fingerprints of the selected user'''
		# First, get the name of the user
		person = DbClient.getProfile(userid, False)
		dispName = person.get('displayName', '')
		fullName = person.get('name', '')
		if not dispName: dispName = fullName
		if dispName != fullName:
			fullName = dispName + " (" + fullName + ")"
		fc = self._makeFingerprintChecker(userid)
		# check it's ok to generate
		status = person.get('status', '')
		if not fc.valid \
		  or status not in ['untrusted', 'trusted']:
			print("Not generating fingerprints page because status is", status)
			return None

		# Get one set of words for us and three sets for them
		printsAlreadyChecked = (person.get('status', '') == "trusted")
		bodytext = self.fingerprintstemplate.getHtml(
			{"mywords":fc.getCodeWords(True, 0, "en"), "theirwords0":fc.getCodeWords(False, 0, "en"),
			 "theirwords1":fc.getCodeWords(False, 1, "en"), "theirwords2":fc.getCodeWords(False, 2, "en"),
			 "fullname":fullName, "shortname":dispName, "userid":userid, "alreadychecked":printsAlreadyChecked})
		return self.buildPage({'pageTitle' : I18nManager.getText("contacts.title"),
			'pageBody' : bodytext,
			'pageFooter' : "<p>Footer</p>"})
开发者ID:activityworkshop,项目名称:Murmeli,代码行数:26,代码来源:pages.py


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