def init_2nd_step(self, verifier_num): info = user.get_app('sina', self.email) auth = OAuthHandler(APP_KEY, APP_SECRET) auth.set_request_token(info.get('request_token'), info.get('request_secret')) access = auth.get_access_token(verifier_num) user.update_app('sina', self.email, access_token=access.key, access_secret=access.secret) return True
def init(self, verifier_num=None): log.debug('init %s' % verifier_num) info = user.get_app('sina', self.email) log.debug(info.get('request_token')) if not info.get('request_token') or not verifier_num: return self.init_1st_step() else: return self.init_2nd_step(verifier_num)
def newmessage(self, message, lat=None, long=None): log.debug('new message: %s' % message) auth = OAuthHandler(APP_KEY, APP_SECRET) info = user.get_app('sina', self.email) auth.setToken(info['access_token'], info['access_secret']) api = API(auth) api.update_status(message) log.debug('new message done.') return True
def get_rank(loginId, password, groupId=2): config.BASE_URL = "http://game%d-CBT.ma.sdo.com:10001" % groupId user = get_app(loginId, password) info = lambda users: "\n".join("%s %s %s \t\t\t\t %s" % ( i.rank, i.battle_event_point, i.name, i) for i in users) b = user.get("ranking/ranking", {"move": "0", "ranktype_id": ranktype_id, "top": "1"}) r = open('ranking%s_%d_%s.log' % (ranktype_id, groupId, time.strftime("%Y%m%d%H%M", time.localtime())), 'wb') print >> r, "%d区排行榜,截至%s 。 各位小伙伴, 找找自己的名字吧。" % (groupId, time.ctime()) print >> r, info(b.response.body.ranking.user_list.user).encode('utf8') while True: try: last_user_id = b.response.body.ranking.user_list.user.id[-1] b = user.get("ranking/ranking_next", {"from":last_user_id, "ranktype_id":ranktype_id}) print >> r, info(b.response.body.ranking.user_list.user).encode('utf8') except: time.sleep(0.2)
def forecast(self): info = user.get_app('weather', self.email) if not info: return recently_send = info.get('recently_send') log.debug('recently send: %s' % str(recently_send)) if recently_send and type(recently_send) in (str, unicode): r = time.strptime(recently_send, '%Y-%m-%d') recently_send = datetime.date(r.tm_year, r.tm_mon, r.tm_mday) if recently_send == datetime.date.today(): return city = info.get('city') forecast = self._get_weather(city) result = '' if not forecast: return result for f in forecast: result += u'%(day_of_week)s: High[%(high)s], Low[%(low)s], Condition[%(condition)s]\n' % f user.update_app('weather', self.email, recently_send=datetime.date.today()) return result
r = [[999, 999, []], ] # [lv, cost, cnames] for lv, row in sorted(out.items(), reverse=True): for cost, cnames in row: _lv, _cost, _cnames = r[-1] if cost > _cost: continue if _lv == lv: if cost < _cost:#or (len(_cnames) < len(cnames) and cost == _cost): if filter(lambda x: x in double_cards, _cnames) and cost == _cost: continue r[-1][1:] = cost, cnames else: if cost != _cost: r.append([lv, cost, cnames]) return r[1:-1][::-1] if __name__ == "__main__": assert can_kill_mult(1, [[2.0, 0, 0]], 1, 2.0) assert can_kill_mult(3, [[3.0, 0, 0]], 4, 2.0) assert not can_kill_mult(3, [[1.0, 0, 0]], 3, 2.0) from user import get_app from config import * user = get_app(my_loginId, my_password) print '\n'.join("%d %d %s" % (row[0], row[1], '|'.join(row[-1])) for row in find_deck_cards(user)) import IPython; IPython.embed()