Esempio n. 1
0
 def test_successful_brewery_parse(self):
     """Test the ability to read a brewery from the Untappd HTML"""
     url = 'file://' + os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'test-data', 'untappd',
         'untappd.com-flyingdog')
     brewery = untappd.parse_brewery(url)
     self.assertEqual(brewery.name, 'Flying Dog Brewery')
     self.assertEqual(brewery.location, 'Frederick, MD United States')
     self.assertEqual(brewery.untappd_url, url)
Esempio n. 2
0
 def handle(self, *args, **opts):
     print("BEGIN --{}--".format(opts['url'][0]))
     result = None
     if opts['type'][0] == 'checkin':
         result = parse_checkin(opts['url'][0])
     elif opts['type'][0] == 'beer':
         result = parse_beer(opts['url'][0])
     elif opts['type'][0] == 'brewery':
         result = parse_brewery(opts['url'][0])
     print(result)
     print("END   --{}--".format(opts['url'][0]))
Esempio n. 3
0
 def get(self, request, format=None):
     """Retrieves beer info based on URL"""
     if 'url' not in request.query_params:
         raise serializers.ValidationError(
             {'non_field_errors': ['No URL provided']})
     try:
         brewery = untappd.parse_brewery(request.query_params['url'])
         logger.info('Looking up brewery at URL: %s',
                     request.query_params['url'])
         brewery_object = {
             'name': brewery.name,
             'untappd_url': brewery.untappd_url,
             'location': brewery.location,
         }
         return Response(brewery_object)
     except untappd.UntappdParseException as e:
         raise serializers.ValidationError(
             {'non_field_errors': ['{}'.format(e)]})