本文整理汇总了Python中status.Status类的典型用法代码示例。如果您正苦于以下问题:Python Status类的具体用法?Python Status怎么用?Python Status使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Status类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sam_error
def test_sam_error(self):
status = Status(self._mock_sam_api(False), {"fence": self._mock_fence_api(True)})
self.assertItemsEqual(status.get(), [
{"ok": True, "message": "", "subsystem": Subsystems.memcache},
{"ok": True, "message": "", "subsystem": Subsystems.datastore},
{"ok": True, "message": "", "subsystem": "fence"},
{"ok": False, "message": "sam down", "subsystem": Subsystems.sam},
])
示例2: test_datastore_error
def test_datastore_error(self):
status = Status(self._mock_sam_api(True), {"fence": self._mock_fence_api(True)})
status._datastore_status = MagicMock(return_value=(False, "datastore down"))
self.assertItemsEqual(status.get(), [
{"ok": True, "message": "", "subsystem": Subsystems.memcache},
{"ok": False, "message": "datastore down", "subsystem": Subsystems.datastore},
{"ok": True, "message": "", "subsystem": "fence"},
{"ok": True, "message": "", "subsystem": Subsystems.sam},
])
示例3: search_tweets
def search_tweets(trend):
try:
search_results = twitter.search(q=trend.query, lang='es', count='100')
except TwythonError as e:
print e
aux = 0
for status in search_results.get(u'statuses', []):
s = Status(status, trend)
print s.text
s.save()
示例4: join_go_terms_with_genes
def join_go_terms_with_genes():
client = pymongo.MongoClient()
terms = client.go.terms.find()
status = Status('joining terms with genes').n(terms.count())
for k, term in enumerate(terms):
status.log(k)
genes = client.go.genes.find({'go': term['go']})
term['genes'] = list(set(g['gene'] for g in genes))
term['n_genes'] = len(term['genes'])
client.go.terms.save(term)
status.stop()
示例5: advance_to_next_game
def advance_to_next_game(self):
# We only need to check the preferred team's game status if we're
# rotating during mid-innings
if self.config.rotation_preferred_team_live_mid_inning and not self.is_offday_for_preferred_team():
preferred_overview = self.fetch_preferred_team_overview()
if Status.is_live(preferred_overview.status) and not Status.is_inning_break(preferred_overview.inning_state):
self.current_game_index = self.game_index_for_preferred_team()
self.overview = preferred_overview
self.needs_refresh = False
self.__update_layout_state()
self.print_overview_debug()
return self.current_game()
self.current_game_index = self.__next_game_index()
return self.current_game()
示例6: get
def get(self):
debug = self.request.get('debug',False)
self.response.out.write('<ul>')
#自分宛のreplyを取得
twitter = TwitterClient()
replies = twitter.getReplies()
replies.reverse()
for reply in replies:
text = reply['text']
texts = reply['text'].split()
#全角スペースに対応
if len(texts) < 2:
texts = reply['text'].split(u' ')
if len(texts) < 2:
self.response.out.write('<li>[%s] is irregure</li>'%(text))
continue
keyword = texts[1]
user = reply['user']
#自分のreplyは無視
if user['screen_name'] == self.username :
self.response.out.write('<li>[%s] is my status</li>'%(text))
continue
#既に処理済みのreplyも無視
if not Status.isNewStatus( reply['id'] ) :
self.response.out.write('<li>[%s] is old status</li>'%(text))
continue
#位置を取得
finder = LocationFinder()
loc = finder.find( keyword )
if not loc:
#見つからなかった
mes = self.fail_message%( reply['user']['screen_name'] ,keyword)
else:
#見つかった
mes = self.success_message[loc['type']]%( reply['user']['screen_name'] , loc['title'] , 'L:' + str(loc['lat']) + "," + str(loc['lon']) + ' ' + loc['url'] )
#返信した内容を保存
Status.saveStatus( reply,loc,mes )
#twitterのstatusを更新
if not debug:
twitter.sendReply( mes , reply['id'])
self.response.out.write('<li>[%s]:[%s]</li>'%(keyword,mes) )
self.response.out.write('</ul>')
示例7: stop
def stop(self):
self.active = False
game_slugs = get_game_slugs()
if self.slug in game_slugs:
game_slugs.remove(self.slug)
memcache.set('game_slugs', game_slugs)
serialized_status = memcache.get_multi(self.status_ids,
key_prefix='status')
# Just copying my status_ids list to make some changes localy
missing_status_ids = list(self.status_ids)
for status_id, status in serialized_status.iteritems():
deserialized_status = deserialize(status)
deserialized_status.player.leave_game(self)
missing_status_ids.remove(status_id)
# Taking the missing status in database
if missing_status_ids:
missing_status = Status.get(missing_status_ids)
for status in missing_status:
status.player.leave_game(self)
memcache.delete('game'+self.slug)
self.status_ids = []
self.put()
示例8: __init__
def __init__(self, config):
self.config = config # 应用程序配置
self.connections = 0 # 连接客户端列表
if self.config['savetime'] != 0: # 不保存数据
self.thread = PeriodicCallback(self.save_db,
int(self.config['savetime']) * 1000)
self.thread.start() # 背景保存服务线程启动
self.workpool = ThreadPool(int(config['work_pool'])) # 工作线程池
self.status = Status(CacheServer.status_fields) # 服务器状态
self.slave_clients = {} # 同步客户端
self.is_sync = False # 是否在同步
if self.config['master'] is not None: # 从服务器启动
shutil.rmtree(config['db'])
self.master_server = PyCachedClient(self.config['master'][0],
self.config['master'][1])
self.master_server.sync(self.config['port'])
self.slavepool = None
self.slave = True # 是否为Slave模式
else: # 主服务器启动, 需要启动从命令工作线程
self.slavepool = ThreadPool(int(config['slave_pool'])) # slave Command send pools
self.slave = False # 是否为Slave模式
self.memory = Memory(config['db']) # 缓存服务类
super(CacheServer, self).__init__()
示例9: BondStatusApi
class BondStatusApi(remote.Service):
def __init__(self):
sam_base_url = config.get('sam', 'BASE_URL')
providers = {provider_name: FenceApi(config.get(provider_name, 'FENCE_BASE_URL'))
for provider_name in config.sections() if provider_name != 'sam'}
sam_api = SamApi(sam_base_url)
self.status_service = Status(sam_api, providers)
@endpoints.method(
message_types.VoidMessage,
StatusResponse,
path='/status',
http_method='GET',
name='status')
def status(self, request):
subsystems = self.status_service.get()
ok = all(subsystem["ok"] for subsystem in subsystems)
response = StatusResponse(ok=ok,
subsystems=[SubSystemStatusResponse(ok=subsystem["ok"],
message=subsystem["message"],
subsystem=subsystem["subsystem"])
for subsystem in subsystems])
if ok:
return response
else:
raise endpoints.InternalServerErrorException(response)
示例10: get_status_dict
def get_status_dict(self):
# It will returns a serialized status in mem_cache
serialized_status = memcache.get_multi(self.status_ids,
key_prefix='status')
# Just copying my status_ids list to make some changes localy
missing_status_ids = list(self.status_ids)
game_status = {}
for status_id, status in serialized_status.iteritems():
game_status[status_id] = deserialize(status)
missing_status_ids.remove(status_id)
# Taking the missing status in database and add them in memcache
if missing_status_ids:
missing_status = Status.get(missing_status_ids)
serialized_status = {}
for status in missing_status:
game_status[status_id] = deserialize(status)
serialized_status[status.id] = serialize(status)
memcache.set_multi(serialized_status, key_prefix='status')
# I really dunno why, but the game_status list in this function
# works like a list of string, and when this function pass to some
# function or when it returns, game_status assume its really identity
# that is a list of status, not a list of strings... (crazy, I know)
self.actualise_status(game_status)
return game_status # Returns a random list of Status playing this game
示例11: load_go_terms
def load_go_terms():
info = {
'database': 'go',
'collection': 'terms',
'url': 'http://geneontology.org/ontology/go.obo',
'timestamp': time.time()
}
client = pymongo.MongoClient()
collection = client[info['database']][info['collection']]
collection.drop()
with mktemp() as pathname:
filename = os.path.join(pathname, 'go.obo')
log.debug('downloading %s to %s', info['url'], filename)
subprocess.call(['wget', info['url'], '-O', filename])
with open(filename, 'rt') as fid:
status = Status(filename, log).fid(fid).start()
obj = None
state = None
for line in fid:
status.log()
line = line.strip()
if line and not line.startswith('!'):
if line[0] == '[' and line[-1] == ']':
if state == 'Term' and obj:
collection.insert(obj)
state = line[1:-1]
obj = {}
elif state == 'Term':
key, _, value = line.partition(': ')
if value:
if key == 'id':
obj['go'] = value
else:
try:
obj[key].append(value)
except KeyError:
obj[key] = value
except AttributeError:
obj[key] = [obj[key], value]
status.stop()
if state == 'Term' and obj:
collection.insert(obj)
collection.create_index('go')
update_info(info)
示例12: read_net
def read_net(self, event=None):
if self.reading_net: return gtk.TRUE
self.reading_net = True
inKB, outKB = Status.getNet()
if inKB > 9999: inKB = 999
if outKB > 999: outKB = 999
pingTimeGoogle = Status.getPingTime("google.com")
if self.gw == None:
self.gw = get_gw()
print "gateway:", self.gw
if self.gw != None:
pingTimeGW = Status.getPingTime(self.gw, 2)
self.statusStr = "%04d" % inKB +":"+"%03d" % outKB +"K/s " + " " + \
pingTimeGoogle + "|" + pingTimeGW + "ms"
if pingTimeGW == "-1":
try:
self.gw = get_gw()
print "gateway:", self.gw
except:
pass
self.statusStr = self.statusStr
else:
self.statusStr = strike("NET ")
print "%.2f " % (time.time() - self.t), self.statusStr
self.ind.set_label(self.statusStr)
if self.gw != None:
fullStatusStr = "UP: %03d" % inKB +"K/s\n"+"DOWN: %03d" % outKB +"K/s\n" + \
"Google ping: " + pingTimeGoogle + "ms\n" + \
"GW (" + self.gw + ") ping: " + pingTimeGW
else:
fullStatusStr = "No network"
self.netMenuItem.set_label(fullStatusStr)
self.counter += 1
icon_name = "network"
net_level = 5.0
if outKB >= net_level:
icon_name += "-transmit"
if inKB >= net_level:
icon_name += "-receive"
if outKB < net_level and inKB < net_level:
icon_name += "-idle"
self.ind.set_icon(icon_name)
self.t = time.time()
self.reading_net = False
return gtk.TRUE
示例13: __init__
def __init__(self):
sam_base_url = config.get('sam', 'BASE_URL')
providers = {provider_name: FenceApi(config.get(provider_name, 'FENCE_BASE_URL'))
for provider_name in config.sections() if provider_name != 'sam'}
sam_api = SamApi(sam_base_url)
self.status_service = Status(sam_api, providers)
示例14: get
def get(self):
twitter = TwitterClient()
statuses = Status.getStatuses(20)
user = twitter.getUser( self.username )
def urlify(txt):
if txt:
txt = re.sub('(https?:\/\/[-_.!~*\'()a-zA-Z0-9;/?:@&=+$,%#]+)',
'<a href="\\1">Link</a>', txt)
return txt
def getMapUrl(loc,type):
if not loc:
return None;
if type == "google" :
url = u'http://maps.google.com/staticmap?'
url += urllib.urlencode( {
'center' : str(loc.lat) + ',' + str(loc.lon),
'markers' : str(loc.lat) + ',' + str(loc.lon),
'size' : '460x320',
'zoom' : '15',
'key' : self.google_key,
} )
else :
url = u'http://tp.map.yahoo.co.jp/mk_map?'
url += urllib.urlencode( {
'prop' : 'clip_map',
'scalebar' : 'off',
'pointer' : 'off',
'width' : '460',
'height' : '320',
'datum' : 'wgs84',
'lat' : loc.lat,
'lon' : loc.lon,
'pin' : str(loc.lat) + "," + str(loc.lon),
'sc' : 4,
})
return url
list = []
for status in statuses:
list.append( {
'text' : status.text,
'reply' : urlify(status.reply),
'user_screen_name' : status.user_screen_name,
'user_profile_image_url' : status.user_profile_image_url,
'loc_url' : status.loc_url,
'map' : getMapUrl( status.loc_point , status.loc_type ),
})
values = {
'list' : list,
'user' : user,
}
path = os.path.join(os.path.dirname(__file__), 'main.html')
self.response.out.write( template.render(path,values))
示例15: update
def update():
status = Status.instance()
updates = request.get_data().split("&")
for u in updates:
key, value = u.split("=")
print "updating {0} to {1}".format(key, value)
status.update(key, value)
return ""