def get(self): city = self.request.get('city') real_city = showtimes.place(city) if real_city: self.redirect(self.request.path + "?" + urlencode({'city': real_city.encode('utf-8')}), permanent = True) else: tz = geonames.timezone(city) if tz: debug("timezone for " + city + ": " + unicode(tz) + ", current time:" + unicode(tz.localize(datetime.utcnow()))) sts = sort_by_rating(criticker.ize(imdbize(showtimes.find(city)))) self.render("movies.html", { 'city': city, 'movies': sts })
def save(self, *args, **kw): assert self.type in (TYPE_CINEMA, TYPE_TV_CHANNEL) self.name_normalized = normalized_text(self.name) if self.type == self.TYPE_CINEMA: self.country = self.town.country if not self.timezone_id: if self.town.timezone_id: self.timezone_id = self.town.timezone_id else: if self.latitude and self.longitude: self.timezone_id = timezone(self.latitude, self.longitude)['timezoneId'] self.town.timezone_id = self.timezone_id self.town.save() else: logger.warning("%s without coords", unicode(self)) return super(Channel, self).save(*args, **kw)
def save(self, *args, **kw): assert self.type in (TYPE_CINEMA, TYPE_TV_CHANNEL) self.name_normalized = normalized_text(self.name) if self.type == self.TYPE_CINEMA: self.country = self.town.country if not self.timezone_id: if self.town.timezone_id: self.timezone_id = self.town.timezone_id else: if self.latitude and self.longitude: self.timezone_id = timezone( self.latitude, self.longitude)['timezoneId'] self.town.timezone_id = self.timezone_id self.town.save() else: logger.warning("%s without coords", unicode(self)) return super(Channel, self).save(*args, **kw)
def find(city): if city == 'enh2009': return read_enh2009() city_enc = city.encode('utf-8') result = memcache.get(city_enc, namespace = "showtimes") if not result: result = do_find(city) tz = geonames.timezone(city) now = pytz.utc.localize(datetime.utcnow()) midnight = cache_timeout = nearest_midnight(now) if tz: now = now.astimezone(tz) midnight = nearest_midnight(now) cache_timeout = midnight.astimezone(pytz.utc) cache_timeout_epoch = time.mktime(cache_timeout.timetuple()) debug("cache for " + city + " will expire at " + midnight.ctime() + " local, which is " + cache_timeout.ctime() + " UTC / epoch = " + str(cache_timeout_epoch)) memcache.set(city_enc, result, cache_timeout_epoch, namespace = "showtimes") return result
from django.conf import settings from film20.utils import cache def _get_country_and_tz_by_lat_lng(lat, lng): try: from film20.geo.models import TimeZone tz = TimeZone.objects.get(geom__contains="POINT(%s %s)" % (lng, lat)) logger.debug("gis: country_code: %s, timezone: %s", tz.country_code, tz.tzid) return tz.country_code, tz.tzid except Exception, e: logger.debug(unicode(e)) try: from geonames import timezone data = timezone(lat, lng) logger.debug("geonames: country_code: %s, timezone: %s", data['countryCode'], data['timezoneId']) return data['countryCode'], data['timezoneId'] except Exception, e: logger.warning(unicode(e)) logger.warning('no timezone and country code for (%s %s)', lat, lng) return False def get_country_and_tz_by_lat_lng(lat, lng): key = cache.Key('country_tz', lat, lng) data = cache.get(key) if data is None: data = _get_country_and_tz_by_lat_lng(lat, lng) cache.set(key, data) return data
from django.conf import settings from film20.utils import cache def _get_country_and_tz_by_lat_lng(lat, lng): try: from film20.geo.models import TimeZone tz = TimeZone.objects.get(geom__contains="POINT(%s %s)" % (lng, lat)) logger.debug("gis: country_code: %s, timezone: %s", tz.country_code, tz.tzid) return tz.country_code, tz.tzid except Exception, e: logger.debug(unicode(e)) if not settings.SKIP_EXTERNAL_REQUESTS: try: from geonames import timezone data = timezone(lat, lng) logger.debug("geonames: country_code: %s, timezone: %s", data['countryCode'], data['timezoneId']) return data['countryCode'], data['timezoneId'] except Exception, e: logger.warning(unicode(e)) logger.warning('no timezone and country code for (%s %s)', lat, lng) return False def get_country_and_tz_by_lat_lng(lat, lng): key = cache.Key('country_tz', lat, lng) data = cache.get(key) if data is None: data = _get_country_and_tz_by_lat_lng(lat, lng) cache.set(key, data) return data