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


Python datastore.DataStore类代码示例

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


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

示例1: __init__

class Achievements:
    __borg_state = {}
    __achievements_id = "account_achievements"

    def __init__(self, config):
        self.__dict__ = self.__borg_state
        self.config = config
        self.api = GW2_API(config)
        self.ds = DataStore(config)
        self.render = Render(config)

    def _get_current(self):
        """Get the current achievements for the character."""

        cheeves = self.api.get("account/achievements")
        cheeves_by_id = {}
        for cheeve in cheeves:
            cheeves_by_id[cheeve.id] = cheeve

        return cheeves_by_id

    def _get_new_unlock_cheeves(self, old_cheeves, new_cheeves):
        """Given a dict of old and new Achievements, find those that are
        newly unlocked.

        Returns a tuple of:
            (unlocks, newness) where
                    -unlocks is newly completed cheeves
                    -newness is new added cheeves
        """

        unlocks = []
        newness = []
        for cheeve in new_cheeves:
            if cheeve['id'] not in old_cheeves:
                newness.append(cheeve)
            elif cheeve['done'] != old_cheeves[cheeve['id']]['done']:
                unlocks.append(cheeve)
        return (unlocks, newness)

    def _get_new_progress_cheeves(self, old_cheeves, new_cheeves):
        """Given a dict of old and new Achievements, find those that have
        new progress on them."""

        new_prog = []
        for cheeve in new_cheeves:
            if cheeve.get('current', 0) != \
                    old_cheeves[cheeve['id']].get('current', 0):
                new_prog.append(cheeve)

    def update(self, cheeves=None):
        """Will update the datastore with the current cheeves. Intended to be
        called once per day, per week, per cycle (whatever).

        If 'cheeves' is ommitted, will get the current cheevese via API"""

        if cheeves is None:
            cheeves = self._get_current()

        self.ds.put(self.__achievements_id, cheeves)
开发者ID:criswell,项目名称:gw2-widgets,代码行数:60,代码来源:achievements.py

示例2: handle

def handle(config):
	try:
                flagcheck=True
                logger.info("calling jmx for metrics")
		#check for jmx hosts file
		#TODO add code for handling metrics from multiple JMX hosts	
		#
		#JAVA(libjvm='./lib/jmx/libjvm.so')
		#JAVA()
		jpype.attachThreadToJVM()
		jmx=JMX(host='96.119.153.107',port=9999)
		DS=DataStore()
                for condition in config.get('if').get('jmx'):
			baseline=DS.getbaseline(condition)
    			current=jmx.get_attr(condition.get('object'),condition.get('type'),condition.get('attribute'))
			logger.debug(current)
			logger.debug(str(current) + condition.get('operator') + repr(baseline))
			out=eval(str(current) + condition.get('operator') + repr(baseline))
			if not bool(out):
                                flagcheck=False
                                break
			DS.setbaseline(current.floatValue(),baseline,condition)
    		del jmx
                return flagcheck
        except Exception,e:
		print "in exception"
		print e
                logger.error(e)
                return False
开发者ID:sramakr,项目名称:rengine,代码行数:29,代码来源:jmx.py

示例3: EncryptorWatcher

class EncryptorWatcher(LoggingEventHandler):
    '''
    This class enters all file 'created' events to a database pointed to by dbFolder
    '''
    def __init__(self, pathStructure, dbFolder):
        super(LoggingEventHandler, self).__init__()
        self.pathStructure = pathStructure
        self.dataStore = DataStore(dbFolder) 

    def on_modified(self, event):
        path = os.path.join(self.pathStructure['inBox'], event.src_path)
        logging.debug("encryptorWatch on_modified file")
        info = "Modified: " +  event.src_path + " " + str(os.path.getsize(path))
        logging.debug(info)

    def on_created(self, event):
        path = os.path.join(self.pathStructure['inBox'], event.src_path)
        
        if os.path.isdir(os.path.abspath(event.src_path)):
            logging.debug('WatchProcess: Folder Encryption is not supported.')
            return

        self.dataStore.addFilePathToDataBaseStoreWithType(os.path.abspath(event.src_path), self.pathStructure['watchType'], self.pathStructure['name'])

        info = "Created: " +  event.src_path + " " + str(os.path.getsize(path))
        logging.debug("encryptorWatch on_created file")
        logging.debug(info)
开发者ID:patrickcusack,项目名称:BWF,代码行数:27,代码来源:watchpathsubprocess.py

示例4: perform_search

def perform_search(search_str,results_collector):

    base_url = 'http://sfbay.craigslist.org'

    cl_html_results = requests.get(search_str)
    soup = BeautifulSoup(cl_html_results.text, 'html.parser')

    ds = DataStore(storetype='sql')

    for result in soup.find_all(attrs={"data-pid": re.compile('\d+')}):

        link_title = result.find(id='titletextonly')

        if link_title is None:
            # print "Cannot find title for entry %s", result
            next
        else:
            datapid = result.attrs['data-pid']
            link_title_text = link_title.text

            link = '{0}{1}'.format(base_url, result.find('a').attrs['href'])

            #print "debug: {0} | {1} | {2}".format(datapid, link_title_text, link)

            ds.save_entry(datapid=datapid, title=link_title_text, url=link)

    for i in ds.new_listings:
        results_collector.append(i)
开发者ID:engelmav,项目名称:cltracker,代码行数:28,代码来源:cl_tracker.py

示例5: main

def main():
	"""Parse the command line arguments, expecting one of the following formats:
		-) (-i ChannelID | -u Username) (add | check | remove)
		-) check | list
	and perform the appropriate action
	"""
	parser = get_parser()
	args = parser.parse_args()

	youtube = YouTube()
	store = DataStore('%s-data.sqlite3' % sys.argv[0], 'schema.sql')

	channel = None
	if args.username is not None:
		channel = youtube.get_channel_by_username(args.username)
	elif args.id is not None:
		channel = youtube.get_channel_by_id(args.id)

	if args.action == 'add':
		store.store_channel(channel)
	elif args.action == 'remove':
		store.remove_channel(channel)
	elif args.action == 'list':
		data = []
		for item in store.get_channels():
			data.append([
				item['id'],
				item['title'],
				arrow.get(item['added_on']).humanize(),
				arrow.get(item['last_checked']).humanize()
			])

		pretty_print(['ID', 'Title', 'Added', 'Last Checked'], data)
	elif args.action == 'check':
		# If the user passed a specific channel, check for new uploads
		# otherwhise check for uploads from every previously added channel
		channels = []
		if channel is not None:
			channels.append(store.get_channel_by_id(channel['id']))
		else:
			channels = store.get_channels()

		data = []
		to_check = dict()
		for channel_item in channels:
			to_check[channel_item['id']] = channel_item['last_checked']

		uploads = youtube.get_uploads(to_check)
		for upload in uploads:
			data.append([
				upload['channel_title'],
				upload['title'],
				arrow.get(upload['published_at']).humanize(),
				'https://youtube.com/watch?v=%s' % (upload['id'], )
			])

		pretty_print(['Channel', 'Title', 'Published', 'Link'], data)

		for channel_id in to_check.keys():
			store.update_last_checked(channel_id)
开发者ID:helmi77,项目名称:youtube-checker,代码行数:60,代码来源:checker.py

示例6: close

 def close(self):
     self.commitStockBatch()
     self.commitBatch()
     self.conn.commit()
     self.conn.close()
     self.conn = None
     DataStore.close(self)
开发者ID:olyoberdorf,项目名称:stocklib,代码行数:7,代码来源:sqlitedatastore.py

示例7: singleFileWatcher

class singleFileWatcher(LoggingEventHandler):
    '''
    This class enters all file 'created' events to a database pointed to by dbFolder
    '''
    def __init__(self, pathStructure, dbFolder):
        super(LoggingEventHandler, self).__init__()
        self.pathStructure = pathStructure
        self.dataStore = DataStore(dbFolder) 

    def on_created(self, event):
        
        for ignoreFile in ['.DS_Store', 'Thumbs.db']:
            if ignoreFile in os.path.abspath(event.src_path):
                info = 'File ignored: ' +  os.path.abspath(event.src_path)
                logging.debug(info)
                return

        info = 'On created: ' +  os.path.abspath(event.src_path)
        logging.debug(info)

        if os.path.isdir(os.path.abspath(event.src_path)):
            info = 'Directory analysis is not available'
            logging.debug(info)
            return

        self.dataStore.addFileToDatabase(os.path.abspath(event.src_path))
        info = 'adding ' + event.src_path + ' to the database'
        logging.debug(info)
开发者ID:patrickcusack,项目名称:BWF,代码行数:28,代码来源:watchprocess.py

示例8: test1

 def test1(self):
     con = make_dbcon()
     ds = DataStore(con)
     col = ds.collection("users")
     
     i = Index(con, col, 'email')
     
     self.assertEqual(i.name(), 'email')
开发者ID:stereohead,项目名称:wsgi-cahin,代码行数:8,代码来源:tests.py

示例9: handle_get

def handle_get(key):
    """Return a tuple containing True if the key exists and the message
    to send back to the client."""
    if key not in POROCESSING:
        ds = DataStore()
        data = ds.get(key)
        if data:
            return(True, (data[0],data[1]))
    return(False, 'ERROR: Key [{}] not found'.format(key))
开发者ID:anupkalburgi,项目名称:dbreplication-sqlite,代码行数:9,代码来源:handlers.py

示例10: update_poi

def update_poi(id):
    store = DataStore()
    poi = PointOfInterest.from_request(request)
    poi.id = id
    valid = poi.validate()
    if len(valid) == 0:
        poi = store.update_poi(poi)
        return to_json(poi)
    else:
        return to_json(valid)
开发者ID:areopag,项目名称:fh-poi-app,代码行数:10,代码来源:main.py

示例11: update_poi_test

def update_poi_test(id):
    store = DataStore()
    poi = PointOfInterest.get_test_item(id)
    poi.name = "t_name_toUpdate"
    poi.category = "t_category_toUpdate"
    poi.creator = "t_creator_toUpdate"
    poi.description = "_description_toUpdate"
    poi.latitude = 20.00000
    poi.longitude = 10.00000
    poi = store.update_poi(poi)
    return to_json(poi)
开发者ID:areopag,项目名称:fh-poi-app,代码行数:11,代码来源:main.py

示例12: test3

 def test3(self):
     con = make_dbcon()
     ds = DataStore(con)
     
     users = ds.collection("users")  
     users.add_index("email")
     
     uuid = users.save({'email': '[email protected]', 'name':'John Doe!'})
     self.assertIsNotNone(users.index("email").find("[email protected]"))
     
     users.delete(uuid)
     
     self.assertEqual(len(users.index("email").find("[email protected]")), 0)
开发者ID:stereohead,项目名称:wsgi-cahin,代码行数:13,代码来源:tests.py

示例13: start

def start():
    fileConfig('conf/log.conf')
    logging.getLogger('garage').log(logging.DEBUG, 'Log setup complete')

    logging.getLogger('garage').log(logging.DEBUG, 'Initializing datastore ')
    db = DataStore(setup='true')
    db.shutdown()
    logging.getLogger('garage').log(logging.DEBUG, 'Complete')

    #butler = None
    butler = Butler()

    web.start(butler)
开发者ID:gurumitts,项目名称:garage-butler,代码行数:13,代码来源:__init__.py

示例14: get_tasks

def get_tasks():
	u = request.form['url'].lower()
	
	url = Utilities.get_shortened_url(u)
	url_3 = Utilities.get_shortened_url(u,3)

	return_only_parent = False

	# If url is same as parent url, return everything just for parent
	# Dont redundantly return for parent and itself
	if url == url_3 or url+'/' == url_3:
			return_only_parent = True

	ds = DataStore()

	if not return_only_parent:

		all_urls = Utilities.modify_url(url)
		print all_urls

		# If the same url is also a parent url, return all results of parent .
		# And skip individual url results

		for url in all_urls:
			result = ds.fetch(url)
			if result == False:
				print " Tried for url " + url
			else:
				x = {"result":result}
				return jsonify(x)

	# If for our exact url and its modifications , nothing got returned

	outer_url = "parent::" + Utilities.get_shortened_url(url,3)
	print outer_url
	
	result = ds.fetch_all_from_parent(outer_url)
	if result : 
		x = {"result":result}
		return jsonify(x)
	else:
		if outer_url[-1] == '/':
			result = ds.fetch_all_from_parent(outer_url[:-1])
		else:
			result = ds.fetch_all_from_parent(outer_url + '/')
		if result : 
			x = {"result":result}
			return jsonify(x)

	# If there is still nothing to show
	return 'No Response'
开发者ID:shahharsh2603,项目名称:twitter-coupon-crawler,代码行数:51,代码来源:webservice.py

示例15: handle_put

def handle_put(seq,key, value):
    """Return a tuple containing True and the message
    to send back to the client."""

    if key not in POROCESSING:
        POROCESSING.append(key)
        ds = DataStore(key,value)
        if ds.put(seq):
            POROCESSING.remove(key)
            return (True, 'Key [{}] set to [{}]'.format(key, value))
        else:
            ds.roll_back(seq)
            POROCESSING.remove(key)
    return (False, 'Could Not be added')
开发者ID:anupkalburgi,项目名称:dbreplication-sqlite,代码行数:14,代码来源:handlers.py


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