Пример #1
0
 def setUp(self):
     self.event = Event.objects.create(name='test Event',
                                       stubhub_id='9599084')
     self.section = Section.objects.create(name='test Section',
                                           stubhub_id='592806',
                                           event=self.event)
     self.inventory_url = get_secret('STUBHUB_API_URL')
     self.headers = get_secret('STUBHUB_POST_HEADER')
Пример #2
0
 def price_if_necessary(self):
     # Check if price is now cheaper
     response = self.object.retrieve_pricepoint()
     current_cheapest = self.object.pricepoints.last()
     retrieved_cheapest = response['listing'][0]
     new_different = (retrieved_cheapest['currentPrice']['amount'] != current_cheapest.total_amount)
     # Check if old cheapest price is expired
     if not new_different:
         listing_url = get_secret('STUBHUB_LISTING_URL') + current_cheapest.listing_id
         headers = get_secret('STUBHUB_POST_HEADER')
         listing_response = requests.get(listing_url, headers=headers, params={}).json()
         cheapest_expired = 'errors' in listing_response['ListingResponse']
     if new_different or cheapest_expired:
         pricepoint = self.object.create_pricepoint(response)
         if pricepoint.total_amount == current_cheapest.total_amount:
             current_cheapest.delete()
     else:
         pricepoint = current_cheapest
     return pricepoint
Пример #3
0
 def retrieve_pricepoint(self):
     inventory_url = get_secret('STUBHUB_API_URL')
     headers = get_secret('STUBHUB_POST_HEADER')
     if self.stubhub_id:
         query_data = {
             'eventid': self.event.stubhub_id,
             'sectionidlist': [self.stubhub_id],
             'quantity': 1,
             'rows': 10
         }
     else:
         query_data = {
             'eventid': self.event.stubhub_id,
             'quantity': 1,
             'rows': 10
         }
     response = requests.get(inventory_url,
                             headers=headers,
                             params=query_data).json()
     return response
Пример #4
0
 def create_pricepoint(self, response):
     listings = response['listing']
     for listing in listings:
         listing_url = get_secret('STUBHUB_LISTING_URL') + unicode(
             listing['listingId'])
         response = requests.get(listing_url,
                                 headers=get_secret('STUBHUB_POST_HEADER'),
                                 params={}).json()
         if 'errors' not in response['ListingResponse']:
             try:
                 pricepoint = Pricepoint.objects.create(
                     raw_amount=listing['listingPrice']['amount'],
                     total_amount=listing['currentPrice']['amount'],
                     listing_id=unicode(listing['listingId']),
                     section=self)
             except:
                 pricepoint = Pricepoint.objects.create(raw_amount=0.0,
                                                        total_amount=0.0,
                                                        listing_id='0',
                                                        section=self)
             return pricepoint
     return None
Пример #5
0
def construct_uri(event_id, ticket_id):
    query_string = get_secret('STUBHUB_QUERY_STRING')
    url = 'http://stubhub.com/event/%s/%s&ticket_id=%s' % (
        event_id, query_string, ticket_id)
    return url