Skip to content

Commit

Permalink
Only change the time a beer was added to a tap if the beer changed
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbrew committed May 22, 2019
1 parent dbaa007 commit 499586b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
4 changes: 3 additions & 1 deletion tap_list_providers/parsers/digitalpour.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def handle_venue(self, venue):
tap = taps[tap_info['tap_number']]
except KeyError:
tap = Tap(venue=venue, tap_number=tap_info['tap_number'])
tap.time_added = tap_info['added']
tap.time_updated = tap_info['updated']
tap.estimated_percent_remaining = tap_info['percent_full']
if tap_info['gas_type'] in [i[0] for i in Tap.GAS_CHOICES]:
Expand Down Expand Up @@ -95,6 +94,9 @@ def handle_venue(self, venue):
name, manufacturer, pricing=self.parse_pricing(entry),
venue=venue, **parsed_beer,
)
if beer and tap.beer_id != beer.id:
tap.time_added = tap_info['added']

# 4. assign the beer to the tap
tap.beer = beer
tap.save()
Expand Down
5 changes: 5 additions & 0 deletions tap_list_providers/parsers/stemandstein.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import configurations
from django.db.models import Q
from django.core.exceptions import ImproperlyConfigured, AppRegistryNotReady
from django.utils.timezone import now

# boilerplate code necessary for launching outside manage.py
try:
Expand Down Expand Up @@ -166,6 +167,7 @@ def fill_in_beer_details(self, beer):
)

def handle_venue(self, venue):
timestamp = now()
self.venue = venue
self.fetch_root_html()
beers_found = self.parse_root_html()
Expand All @@ -182,5 +184,8 @@ def handle_venue(self, venue):
venue=self.venue,
tap_number=tap_number,
)
if beer and tap.beer_id != beer.id:
tap.time_added = timestamp
tap.time_updated = timestamp
tap.beer = beer
tap.save()
4 changes: 3 additions & 1 deletion tap_list_providers/parsers/taphunter.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def handle_venue(self, venue):
tap = taps[tap_number]
except KeyError:
tap = Tap(venue=venue, tap_number=tap_number)
tap.time_added = tap_info['added']
tap.time_updated = tap_info['updated']
if 'percent_full' in tap_info:
tap.estimated_percent_remaining = tap_info['percent_full']
Expand Down Expand Up @@ -98,6 +97,9 @@ def handle_venue(self, venue):
name, manufacturer, pricing=self.parse_pricing(entry),
venue=venue, **parsed_beer,
)
if beer and tap.beer_id != beer.id:
tap.time_added = tap_info['added']

# 4. assign the beer to the tap
tap.beer = beer
tap.save()
Expand Down
4 changes: 3 additions & 1 deletion tap_list_providers/parsers/taplist_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ def handle_venue(self, venue):
current_tap.time_updated = timestamp
current_tap.save()
continue
current_tap.time_added = tap_dict.pop('time_added')
time_added = tap_dict.pop('time_added')
mfg_dict = tap_dict.pop('manufacturer')
manufacturer = self.get_manufacturer(**mfg_dict)
beer = self.get_beer(
manufacturer=manufacturer, venue=venue,
**tap_dict
)
if beer and current_tap.beer_id != beer.id:
current_tap.time_added = time_added
current_tap.beer = beer
if current_tap.time_updated != timestamp:
current_tap.time_updated = timestamp
Expand Down
13 changes: 6 additions & 7 deletions tap_list_providers/parsers/thenook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from bs4 import BeautifulSoup
import requests
import configurations
from django.utils.timezone import now
from django.core.exceptions import ImproperlyConfigured, AppRegistryNotReady

# boilerplate code necessary for launching outside manage.py
Expand Down Expand Up @@ -81,6 +82,7 @@ def venue_details(self):
))

def handle_venue(self, venue):
timestamp = now()
url = venue.api_configuration.url
self.fetch_html(url)
taps = {tap.tap_number: tap for tap in venue.taps.all()}
Expand All @@ -106,10 +108,7 @@ def handle_venue(self, venue):
)
if tap.beer_id != beer.id:
tap.beer = beer
# only save if beer changed so as not to disturb updated time
LOG.debug('Saving %s on tap %s', beer, tap.tap_number)
tap.save()
else:
LOG.debug(
'Not saving changes to beer %s on tap %s', beer, tap.tap_number,
)
tap.time_added = timestamp

tap.time_updated = timestamp
tap.save()
5 changes: 3 additions & 2 deletions tap_list_providers/parsers/untappd.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ def handle_venue(self, venue):
tap = taps[tap_number]
except KeyError:
tap = Tap(venue=venue, tap_number=tap_number)
if tap_info['added']:
tap.time_added = tap_info['added']
if tap_info['updated']:
tap.time_updated = tap_info['updated']
# 2. parse the manufacturer
Expand All @@ -100,6 +98,9 @@ def handle_venue(self, venue):
pricing=tap_info['pricing'],
**tap_info['beer']
)
if beer and tap.beer_id != beer.id and tap_info['added']:
# only change the time added if the beer on tap changed
tap.time_added = tap_info['added']
# 4. assign the beer to the tap
tap.beer = beer
tap.save()
Expand Down

0 comments on commit 499586b

Please sign in to comment.