def getAlbumArtAJAX(self): trackid = request.params['trackid'].split('_')[1] track = Session.query(Track).filter_by(id=trackid).one() if not track.album.albumArtFilename and ( \ track.album.lastHitAlbumArtExchange is None \ or datetime.now() > track.album.lastHitAlbumArtExchange + timedelta(days=10)): track.album.lastHitAlbumArtExchange = datetime.now() album = track.album.name artist = track.album.artist.name if artist == 'Various Artists': q = album else: q = (artist + ' ' + album) q = q.replace("'","") site = 'http://www.albumartexchange.com' params = { 'grid' : '2x7', 'sort' : 7, 'q' : q, } url = site + '/covers.php?%s' % urllib.urlencode(params) html = urllib.urlopen(url).read() search = re.search('src="/phputil/scale_image.php\?size=150&src=(?P<src>.*?)"',html) if search: image = site + urllib.unquote(search.group('src')) extension = image.rsplit('.', 1)[1] delchars = ''.join(c for c in map(chr, range(256)) if not c.isalnum()) delchars = delchars.translate(None," ()'&!-+_.") filename = (artist + ' - ' + album).encode('utf-8').translate(None, delchars) + '.' + extension urllib.urlretrieve(image, 'scatterbrainz/public/art/' + filename) albumArt = '/art/' + filename track.album.albumArtFilename = albumArt Session.begin() Session.commit() json = {} if track.album.albumArtFilename: json['albumArtURL'] = track.album.albumArtFilename return simplejson.dumps(json)
) from r2.models import promo from reddit_adzerk.lib.cache import PromoCampaignByFlightIdCache from reddit_adzerk.lib.validator import ( VSite, ) hooks = HookRegistrar() LEADERBOARD_AD_TYPE = 4 ADZERK_IMPRESSION_BUMP = 500 # add extra impressions to the number we # request from adzerk in case their count # is lower than our internal traffic tracking DELCHARS = ''.join(c for c in map(chr, range(256)) if not (c.isalnum() or c.isspace())) FREQ_CAP_TYPE = Enum(None, "hour", "day") EVENT_TYPE_UPVOTE = 10 EVENT_TYPE_DOWNVOTE = 11 RATE_TYPE_BY_COST_BASIS = { promo.PROMOTE_COST_BASIS.fixed_cpm: 2, promo.PROMOTE_COST_BASIS.cpm: 2, promo.PROMOTE_COST_BASIS.cpc: 3, } RATE_TYPE_NAMES = { 1: 'Flat', 2: 'CPM',
PromotionLog, Subreddit, ) from r2.models import promo from reddit_adzerk.lib.cache import PromoCampaignByFlightIdCache hooks = HookRegistrar() LEADERBOARD_AD_TYPE = 4 ADZERK_IMPRESSION_BUMP = 500 # add extra impressions to the number we # request from adzerk in case their count # is lower than our internal traffic tracking DELCHARS = ''.join(c for c in map(chr, range(256)) if not (c.isalnum() or c.isspace())) FREQ_CAP_TYPE = Enum(None, "hour", "day") EVENT_TYPE_UPVOTE = 10 EVENT_TYPE_DOWNVOTE = 11 RATE_TYPE_BY_COST_BASIS = { promo.PROMOTE_COST_BASIS.fixed_cpm: 2, promo.PROMOTE_COST_BASIS.cpm: 2, promo.PROMOTE_COST_BASIS.cpc: 3, } GOAL_TYPE_BY_COST_BASIS = { promo.PROMOTE_COST_BASIS.fixed_cpm: 1, promo.PROMOTE_COST_BASIS.cpm: 2,