def get_idol(self, obj): if self.context['request'].resolver_match.url_name.startswith('card-'): if 'expand_idol' in self.context['request'].query_params: serializer = IdolSerializer(obj.idol, context=self.context) return serializer.data return { 'name': obj.name, 'japanese_name': obj.japanese_name, 'school': obj.idol_school, 'year': obj.idol_year, 'main_unit': obj.idol_main_unit, 'sub_unit': obj.idol_sub_unit, 'note': note_to_expand('idol') if self.context['request'].resolver_match.url_name.startswith('card-') else None, 'chibi': chibiimage(obj.name, small=False), 'chibi_small': chibiimage(obj.name, small=True), }
def latlong(opt): reload, retry = opt['reload'], opt['retry'] map = models.UserPreferences.objects.filter( location__isnull=False).exclude(location__exact='') if not reload: map = map.filter(location_changed__exact=True) geolocator = Nominatim() for user in map: getLatLong(geolocator, user, retry) map = models.UserPreferences.objects.filter( latitude__isnull=False).select_related('user') mapcount = map.count() f = open('mapcount.json', 'w') print >> f, mapcount f.close() mapcache = "" for u in map: mapcache += " {'username': '******',\ 'avatar': '%s',\ 'location': '%s',\ 'icon': '%s',\ 'latlong': new google.maps.LatLng(%f, %f) },\ " % (escape(u.user.username), escape(getUserAvatar(u.user, 200)), escape(u.location), escape( chibiimage(u.best_girl if u.best_girl else 'Alpaca', small=True, force_first=True)), u.latitude, u.longitude) with open('map.json', 'w') as f: f.write(mapcache.encode('UTF-8')) f.close()
def print_still_running_and_coming_soon(still_running_giveaways, voting_ongoing_giveaways, coming_soon_giveaways, idol, with_icons=False): if still_running_giveaways: print '' if with_icons: for idol, giveaway in still_running_giveaways: small_image = get_small_image(giveaway) if small_image: print '![{idol_name} Fan Awards]({url})'.format( idol_name=idol.name, url=small_image, ) print '' print u'{} {} currently running! Take your chance and enter!'.format( u' and '.join([ u'[{idol_name} Fan Awards](https://schoolido.lu/activities/{id}/)' .format( idol_name=idol.name, id=giveaway.id, ) for idol, giveaway in still_running_giveaways ]), 'is' if len(still_running_giveaways) == 1 else 'are', ) print '' if voting_ongoing_giveaways: print '' if with_icons: for idol, giveaway, giveaway_details, hashtag in voting_ongoing_giveaways: small_image = get_small_image(giveaway_details) if small_image: print '![{idol_name} Fan Awards]({url})'.format( idol_name=idol.name, url=small_image, ) print '' print u'{} entry period{} just closed! Go check out all the entries and like your favorites!'.format( u' and '.join([ u'[{idol_name} Fan Awards](https://schoolido.lu/activities/{id}/)' .format( idol_name=idol.name, id=giveaway.id, ) for idol, giveaway, giveaway_details, hashtag in voting_ongoing_giveaways ]), 's' if len(voting_ongoing_giveaways) > 1 else '') for idol, giveaway, giveaway_details, hashtag in voting_ongoing_giveaways: print '' print u'- [See {idol_name} Fan Awards entries](https://schoolido.lu/#search={hashtag}) *right click to open in new tab*'.format( idol_name=idol.name, hashtag=hashtag, ) print '' if coming_soon_giveaways: if with_icons: print '' for idol in coming_soon_giveaways: print '[![{name}]({icon_url})](https://schoolido.lu/idol/{url_name})'.format( name=idol.name, icon_url=chibiimage(idol.name, small=True, force_artist='klab', force_first=False, force_https=True), url_name=urllib.quote(idol.name), ) print '' print_idol = lambda idol: u'[{}](https://schoolido.lu/idol/{}/) ({})'.format( idol.name, urllib.quote(idol.name), date_format( idol.birthday, format='MONTH_DAY_FORMAT', use_l10n=True), ) print 'The birthday{} of {} {} coming soon, so look forward to their Fan Awards as well!'.format( '' if len(coming_soon_giveaways) == 1 else 's', ' and '.join([ u', '.join( [print_idol(idol) for idol in coming_soon_giveaways[:-1]]), print_idol(coming_soon_giveaways[-1]), ]), 'is' if len(coming_soon_giveaways) == 1 else 'are')
def get_chibi_small(self, obj): return 'http://schoolido.lu' + chibiimage(obj.name, small=True)
def get_chibi(self, obj): return 'http://schoolido.lu' + chibiimage(obj.name, small=False)
def get_chibi_small(self, obj): return chibiimage(obj.name, small=True)
def get_chibi(self, obj): return chibiimage(obj.name, small=False)
def _chibi_image(self, name, small): image = chibiimage(name, small) if settings.IMAGES_HOSTING_PATH in image: return image return 'http://schoolido.lu' + image
def latlong(opt): reload, retry = opt['reload'], opt['retry'] map = models.UserPreferences.objects.filter(location__isnull=False).exclude(location__exact='') if not reload: map = map.filter(location_changed__exact=True) geolocator = Nominatim() for user in map: getLatLong(geolocator, user, retry) map = models.UserPreferences.objects.filter(latitude__isnull=False).select_related('user') mapcount = map.count() f = open('mapcount.json', 'w') print >> f, mapcount f.close() mapcache = "" for u in map: mapcache += " {'username': '******',\ 'avatar': '%s',\ 'location': '%s',\ 'icon': '%s',\ 'latlong': new google.maps.LatLng(%f, %f) },\ " % (escape(u.user.username), escape(getUserAvatar(u.user, 200)), escape(u.location), escape(chibiimage(u.best_girl, small=True, force_first=True)), u.latitude, u.longitude) with open('map.json', 'w') as f: f.write(mapcache.encode('UTF-8')) f.close()