def list(self, open=False, closed=False): issues = {'open':[], 'closed':[]} if open: url = self.make_url('list') + '/open' issues['open'].extend(json_loads(urlopen(url).read())['issues']) if closed: url = self.make_url('list') + '/closed' issues['closed'].extend(json_loads(urlopen(url).read())['issues']) return issues
def build_update_transaction(cls, owner, profile, listing, bid, item_ids, public_msg, private_msg, currency_val=0): if not profile.owns_all(uid for uid, item in item_ids): raise ValueError('Incorrect ownership.') schema = json_loads(fetch.schema()) bid.message_public = public_msg bid.message_private = private_msg bid.currency_val = currency_val bid.put() item_types = item_type_map(schema) for uid, item in item_ids: uid = str(uid) bid_item = BidItem( parent=bid, uniqueid=uid, defindex=item['defindex'], source=json_dumps(item), item_type_name=item_types[item['defindex']], listing=listing, bid=bid) bid_item.put() key = bid.key() queue_tool.bang_counters({'bid_items':len(item_ids)}, transactional=True) ## we don't re-queue the bid verification because the ## verification script will pick up all of the items when it ## runs. queue_tool.notify_bid({'bid':key, 'update':True}, transactional=True) return key
def encode_builtin(self): """ Encode this instance using only built-in types. """ item = json_loads(self.source) this = {'uniqueid':self.uniqueid, 'defindex':self.defindex} this.update((k, item.get(k)) for k in ('attributes', 'level', 'quantity', 'quality', 'inventory', 'custom_name', 'custom_desc')) return this
def encode_builtin(self, complete=False): """ Encode this instance using only built-in types. """ try: payload = json_loads(self.payload) except (TypeError,): payload = {} if complete: payload["email"] = self.email payload["notify-listing-defs"] = self.notify_listing_defs or [] return payload
def refresh(self, delta=timedelta(minutes=10)): start, updated = datetime.now(), self.updated if updated and (updated + delta) > start: msg = 'profile refresh: profile current as of %s - update at %s' info(msg, start, updated + delta) return put, id64 = False, self.id64() try: cached, raw_profile = fetch.profile(id64) if not cached: steam_profile = json_loads(raw_profile) for key in steam_profile: setattr(self, key, steam_profile[key]) custom_name = custom_profile_name(steam_profile.get('profileurl')) if custom_name: self.custom_name = custom_name # http://steamcommunity.com/id/propeller_headz/ put = True info('profile refresh: fetched backpack for %s', id64) except (Exception, ), exc: error('profile refresh: %s - %s', exc, id64)
def build_transaction(cls, owner, profile, listing, item_ids, public_msg, private_msg, currency_val): if not cls.lazy_verify: if not profile.owns_all(uid for uid, item in item_ids): raise ValueError('Incorrect ownership.') schema = json_loads(fetch.schema()) bid = cls(owner=owner, listing=listing, message_private=private_msg, message_public=public_msg, currency_val=currency_val) key = bid.put() item_types = item_type_map(schema) for uid, item in item_ids: uid = str(uid) bid_item = BidItem( parent=bid, uniqueid=uid, defindex=item['defindex'], source=json_dumps(item), item_type_name=item_types[item['defindex']], listing=listing, bid=bid) bid_item.put() queue_tool.bang_counters({'bids':1, 'bid_items':len(item_ids)}, transactional=True) queue_tool.reverify_items({'key':key, 'action':'init', 'type':'bid'}, transactional=True) queue_tool.notify_bid({'bid':key, 'update':False}, transactional=True) return key
def build_transaction(cls, owner, profile, item_ids, desc, days, min_bid=None, is_subscriber=False, bid_currency_use=False, bid_currency_start=0, bid_currency_type='', feature_listing=False): ## 1. check the user, get their backpack and verify the ## inidicated items belong to them. if not cls.lazy_verify: if not profile.owns_all(uid for uid, item in item_ids): raise ValueError('Incorrect ownership.') ## 2. check the date if days not in cls.valid_days: raise ValueError('Invalid number of days until expiration.') ## regulation 46a: delta = timedelta(minutes=days*4) if features.devel else timedelta(days=days) expires = datetime.now() + delta ## 3. extract and create categories for the ListingItem ## item types and for the min_bid defindex checks. schema = json_loads(fetch.schema()) ## 4. verify the min_bid values are present in the schema. min_bid = min_bid or [] min_bid_defs = set(min_bid) valid_defs = set(i['defindex'] for i in schema['result']['items']['item']) if not (min_bid_defs & valid_defs == min_bid_defs): raise TypeError('Invalid minimum bid items.') ## 4. create. note that we're not setting a parent entity so ## that we can query for the listing by id. listing = cls( owner=owner, expires=expires, min_bid=min_bid, description=desc) ## 4a. derive categories cats = item_categories([i for u, i in item_ids], schema) listing.categories =\ [cat for cat, ttl in known_categories if cat in cats] ## 4b. set subscriber features: if is_subscriber: listing.bid_currency_use = bid_currency_use listing.bid_currency_start = float(bid_currency_start) listing.bid_currency_type = bid_currency_type ## listing.bid_currency_top == 0 by default listing.featured = feature_listing key = listing.put() info('created new listing at: %s', listing.created) # 5. assign the items item_types = item_type_map(schema) for uid, item in item_ids: uid = str(uid) listing_item = ListingItem( parent=listing, uniqueid=uid, defindex=item['defindex'], source=json_dumps(item), item_type_name=item_types[item['defindex']], listing=listing) listing_item.put() ## 6. submit an item to the expiration task queue. queue_tool.end_listing(key, expires, transactional=True) ## 7. submit an item to the re-verification task queue. queue_tool.reverify_items({'key':key, 'action':'init', 'type':'listing'}, transactional=True) ## 8. submit an item to the counter banging task queue. queue_tool.bang_counters({'listings':1, 'listing_items':len(item_ids)}, transactional=True) ## 9. submit an item to the subscriber notification queue queue_tool.notify_listing(subscription_key=None, listing_key=key, transactional=True) ## 10. submit an item to the external share queue if not features.devel: queue_tool.external_share(listing_key=key, transactional=True) return key
def show(self, sha, path): url = self.make_url('show', sha, path) return json_loads(urlopen(url).read())
def comments(self, number): url = self.make_url('comments') + '/%s' % (number, ) return json_loads(urlopen(url).read())
def branches(self): url = self.make_url('show') + '/branches' return json_loads(urlopen(url).read())
def tags(self): url = self.make_url('show') + '/tags' return json_loads(urlopen(url).read())
def items(self): try: return json_loads(self.backpack) except: return []