def findSubscription(self, name): """Returns the matching subscription @rtype: Subscription @return: The matching subscription """ subscriptions = subscription.Subscription() return subscriptions.find(name)
def subscribe(self, to_shake): """ Subscribe to a shake. If subscription already exists, then just mark deleted as 0. If this is a new subscription, send notification email. """ if to_shake.deleted != 0: return False if to_shake.user_id == self.id: #you can't subscribe to your own shake, dummy! return False existing_subscription = subscription.Subscription.get( 'user_id = %s and shake_id = %s', self.id, to_shake.id) if existing_subscription: existing_subscription.deleted = 0 existing_subscription.save() else: try: new_subscription = subscription.Subscription( user_id=self.id, shake_id=to_shake.id) new_subscription.save() notification.Notification.new_subscriber( sender=self, receiver=to_shake.owner(), action_id=new_subscription.id) # if we get an integrity error, means we already subscribed successfully, so carry along. except IntegrityError: pass return True
def getSubscriptions(self): """Get the subscriptions of this allocation. @rtype: list<subscription> @return: a list of subscriptions """ subscriptionSeq = self.stub.GetSubscriptions( facility_pb2.AllocGetSubscriptionsRequest(allocation=self.data), timeout=Cuebot.Timeout).subscriptions return [ subscription.Subscription(sub) for sub in subscriptionSeq.subscriptions ]
def getSubscriptions(self): """Returns a list of all subscriptions @rtype: list<Subscription> @return: A list of subscription objects """ response = self.stub.GetSubscriptions( show_pb2.ShowGetSubscriptionRequest(show=self.data), timeout=Cuebot.Timeout) subscriptionSeq = response.subscriptions return [ subscription.Subscription(subs) for subs in subscriptionSeq.subscriptions ]
def get_orders(self): # TODO: Need to handle 100+ orders, this can be tested by using per_page=10 # TODO: thread this for i in range(3): try: raw_orders = self.wc_api.get('orders', params={'per_page': 100, 'page': 1}) break except ReadTimeout: print(i) pp = pprint.PrettyPrinter() pp.pprint(raw_orders.json()[0]) f1 = open('raw_data.txt', 'w') f1.write(pp.pformat(raw_orders.json())) f1.close() for order_json in raw_orders.json(): self.customer_orders[order_json['id']] = order.Order(order_json) [self.customer_orders[order_id].parse_items() for order_id in self.customer_orders] [self.customer_orders[order_id].get_shipping_info() for order_id in self.customer_orders] # TODO: thread this for i in range(3): try: raw_subs = self.wc_subs_api.get("subscriptions", params={'per_page': 100, 'page': 1}) break except ReadTimeout: print(i) subs = [] for sub_json in raw_subs.json(): a = subscription.Subscription(sub_json) subs.append(a) a.parse_items() # Add subscription stuff to order items...this is so janky... for sub in subs: for item_id in self.customer_orders[sub.parent_id].items: order_item_name = self.customer_orders[sub.parent_id].items[item_id].name for sub_item_id in sub.items: sub_item_name = sub.items[sub_item_id].name if order_item_name == sub_item_name and sub.status == 'active': self.customer_orders[sub.parent_id].items[item_id].sub = True self.customer_orders[sub.parent_id].items[item_id].date_paid = datetime.datetime.strptime(sub.date_paid, '%Y-%m-%dT%H:%M:%S').date() self.customer_orders[sub.parent_id].items[item_id].next_payment_date = datetime.datetime.strptime(sub.next_payment_date, '%Y-%m-%dT%H:%M:%S').date() # update roast dates with subscription roasts for order_id in self.customer_orders: for item_id in self.customer_orders[order_id].items: self.customer_orders[order_id].items[item_id].add_subscription_roast_dates()
def createSubscription(self, allocation, size, burst): """Creates a new subscription @type allocation: Allocation @param allocation: Allocation object @type size: float @param size: Allocation size @type burst: float @param burst: Allocation burst @rtype: Subscription @return: The created subscription object """ response = self.stub.CreateSubscription( show_pb2.ShowCreateSubscriptionRequest(show=self.data, allocation_id=allocation.id, size=size, burst=burst), timeout=Cuebot.Timeout) return subscription.Subscription(response.subscription)
def on_create(self): #create a subscription for the user if this is a group if self.type == 'group': new_sub = subscription.Subscription(user_id=self.user_id, shake_id=self.id) new_sub.save()
def new(url): s = subscription.Subscription(url) s.initialize()
def update_asubscription(url): s = subscription.Subscription(url) s.update()
def remove(url): s = subscription.Subscription(url) s.remove()