Skip to content

Commit

Permalink
Try to filter multiple photos by the same user
Browse files Browse the repository at this point in the history
  • Loading branch information
Pankrat committed Sep 23, 2012
1 parent b871828 commit f25486a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions visual_weather/base/photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from base.cache import cache_result

@cache_result()
def search(year, month, day, lat=52.52992, lon=13.41157, limit=32):
def search(year, month, day, lat=52.52992, lon=13.41157, limit=32, bust=1):
"""
Return photos for the given date object.
"""
Expand All @@ -17,11 +17,25 @@ def search(year, month, day, lat=52.52992, lon=13.41157, limit=32):
max_taken_date=end.strftime("%Y-%m-%d"),
lat=str(lat),
lon=str(lon),
sort='interestingness-desc',
#sort='interestingness-desc',
#geo_context='2',
per_page=limit,
per_page=limit*2,
radius='10')
return [(p.getMedium(), p.title) for p in photos]
final = []
users = set()
removed = 0
# Filter multiple photos by same user
for photo in photos:
if photo.owner.id not in users:
final.append(photo)
users.add(photo.owner.id)
elif len(photos) - removed <= limit:
# Don't remove if we'd end up with not enough photos
final.append(photo)
else:
removed += 1

return [(p.getMedium(), p.title) for p in final]


def facebook_search(year, month, day):
Expand Down
4 changes: 2 additions & 2 deletions visual_weather/visual_weather/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def index(request):

matching_date = weather.find_matches(current_data["data"], limit=1)[0].date
year, month, day = matching_date.year, matching_date.month, matching_date.day
urls = photos.search(year, month, day, lat=lat, lon=lon, limit=64)
urls = photos.search(year, month, day, lat=lat, lon=lon, limit=64, bust=2)
shuffle(urls)

context = dict(urls=urls,
Expand All @@ -54,7 +54,7 @@ def index(request):

def for_day(request, day='', lat='52.529531', lon='13.1411978'):
year, month, day = day.split('-')
urls = photos.search(int(year), int(month), int(day), lat, lon)
urls = photos.search(int(year), int(month), int(day), lat, lon, bust=2)
shuffle(urls)
datum = date(int(year), int(month), int(day))
context = dict(urls=urls,
Expand Down

0 comments on commit f25486a

Please sign in to comment.