本文整理汇总了Python中event.models.Event._create_resized_images方法的典型用法代码示例。如果您正苦于以下问题:Python Event._create_resized_images方法的具体用法?Python Event._create_resized_images怎么用?Python Event._create_resized_images使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类event.models.Event
的用法示例。
在下文中一共展示了Event._create_resized_images方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_events
# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import _create_resized_images [as 别名]
#.........这里部分代码省略.........
rnum = 0
while True:
if rnum >= max:
break
r = lines[rnum].strip().split('|')
print rnum, r
if r[1] == u'' and r[2] == u'' and r[3] == u'' and r[4] == u'':
# venue row #1
if rnum + 1 >= max:
break
r2 = lines[rnum+1].strip().split('|')
if r2[1] == u'' and r2[2] == u'' and r2[3] == u'' and r2[4] == u'':
# venue row #2
venue = r[0]
venue_address = r2[0].split(')\xc2\xa0(')[0][1:].decode('utf-8')
querystring = urlencode({'q':u'%s %s, %s %s' % (venue[:25], venue_address, venue_city, venue_state)})
map_url = u'http://maps.google.com/?%s' % querystring
vn, created = Venue.objects.get_or_create(
name=venue[:255],
geo_loc=geoloc,
defaults=dict(
source='user-entered',
address=venue_address[:255],
city=venue_city[:255],
state=venue_state,
zip_code=venue_zip[:12],
venue_url=u'',
map_url=map_url,
)
)
rnum += 1 # skip this row next time around
else:
# event row
artist_name = r[1]
artist_dictionary = get_artist(artist_name)
bio = artist_dictionary.get('bio', {}).get('summary', u'')
img = artist_dictionary.get('img', u'')
event_date = r[5] # MM/DD/YYYY
dt = strptime(event_date, _DATE_FORMAT)
event_date = date(*dt[:3])
event_time = r[2] # HH:MM zz"
if ':' in event_time:
if ' ' in event_time:
# convert to 24 hour time format
t, z = event_time.split(' ')
h, m = t.split(':')
if 'p' in z.lower() and not event_time.lower() == '12:00 p.m.':
h = (int(h) + 12) % 24
event_time = u"%s:%s" % (h, m)
elif event_time.lower() == '12:00 a.m.':
event_time = u"00:00"
event_date = event_date + timedelta(days=1)
else:
if int(h) <= 2 or int(h) == 12:
if int(h) == 12:
t = u"00:%s" % m
event_date = event_date + timedelta(days=1)
event_time = t
else:
event_time = None
if not event_time:
event_time = None
artist_location = r[3]
headliner = artist_name
genre = r[4]
external_url = r[6].strip()
event_id = external_url.split('/')[-1]
if 'no hyperlink' in external_url.lower():
external_url = u''
genre_tag = genre.replace('/', ' #')
title = u"%s at %s %s #%s" % (artist_name.decode('utf-8'), vn.name.decode('utf-8'), hashtag, genre_tag)
Event.objects.filter(ext_event_id=event_id, ext_event_source=event_source).delete()
ex = Event(
ext_event_id=event_id,
ext_event_source=event_source,
artist=_ARTIST,
creator=_ARTIST.user_profile,
description=bio,
is_submitted=True,
is_approved=True,
title=title[:120],
url=(u"%s-%s" % (slugify(title)[:30], uuid4().hex[::4]))[:35],
venue=vn,
event_date=event_date,
event_start_time=event_time,
event_timezone=u'',
hashtag=u'"%s"' % headliner[:200].decode('utf-8') or u'',
location=location,
headliner=headliner[:200] or u'',
artists=u'',
has_image=bool(img),
)
image_content = ContentFile(get_raw_image(img))
fname, ext = os.path.splitext("default.jpg")
fname = u'%s%s' % (uuid4().hex[::2], ext)
ex.image.save(fname, image_content, save=False)
ex._create_resized_images(raw_field=None, save=False)
ex.save()
print ex, ex.ext_event_id
rnum += 1
示例2: import_parties
# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import _create_resized_images [as 别名]
#.........这里部分代码省略.........
_DATE_FORMAT = "%m/%d/%Y" # format: 03/17/2010
f = open(filepath, 'r')
f.readline() # skip first line -- Date|Actual Date|Event|Venue|Band|Free|Free Drinks|Map|Details|Link|
lines = f.readlines()
max = len(lines)
rnum = 0
img = party_images.get(hashtag.lower(), None)
has_image = True
if not img:
has_image = False
img = _DEFAULT_IMAGE
f = open(img, "rb")
raw_image_contents = f.read()
f.close()
while True:
if rnum >= max:
break
r = lines[rnum].strip().split('|')
print rnum, r
venue = r[3].strip().decode("utf-8").strip()
venue_address = u''
querystring = urlencode({'q':u'"%s" %s, %s %s' % (venue[:25], venue_address, venue_city, venue_state)})
map_url = u'http://maps.google.com/?%s' % querystring
vn, created = Venue.objects.get_or_create(
name=venue[:255],
geo_loc=geoloc,
defaults=dict(
source='user-entered',
address=venue_address[:255],
city=venue_city[:255],
state=venue_state,
zip_code=venue_zip[:12],
venue_url=u'',
map_url=map_url,
)
)
event_name = r[2]
event_date = r[1] # MM/DD/YYYY
if 'err' in event_date.lower():
rnum += 1
continue
dt = strptime(event_date, _DATE_FORMAT)
event_date = date(*dt[:3])
event_time = None
headliner = u''
is_free = r[5] and "y" in r[5].lower()
free_drinks = r[6] and "y" in r[6].lower()
band = r[4]
description = u""
if band and 'tba' not in band.lower():
description = u'<p class="band party party-band">%s</p>' % band.decode("utf-8")
if free_drinks:
description = description + u"\n<p><strong>Free Drinks!</strong></p>\n"
external_url = r[9].strip()
if 'no hyperlink' in external_url.lower():
external_url = u''
event_id = u''
else:
x = urlparse.urlsplit(external_url)
qx = x.query
qx_dict = parse_qs(qx)
qx_dict.pop("appSession", None) # remove session id from URL to make it work
event_id = qx_dict.get("RecordID")[0]
new_dict = {}
for k, v in qx_dict.iteritems():
new_dict[k]=v[0]
qx = urlencode(new_dict)
external_url = urlparse.urlunsplit((x.scheme, x.netloc, x.path, qx, x.fragment))
description = description + u'\n<p><a href="%s">More details »</a></p>\n' % external_url
title = u"%s at %s %s" % (event_name.decode('utf-8'), vn.name.decode('utf-8'), hashtag)
Event.objects.filter(ext_event_id=event_id, ext_event_source=event_source).delete()
ex = Event(
ext_event_id=event_id,
ext_event_source=event_source,
artist=_ARTIST,
creator=_ARTIST.user_profile,
description=description,
is_submitted=True,
is_approved=True,
is_free=is_free,
title=title[:120],
url=(u"%s-%s" % (slugify(title)[:30], uuid4().hex[::4]))[:35],
venue=vn,
event_date=event_date,
event_start_time=event_time,
event_timezone=u'',
hashtag=u'',
location=location,
headliner=u'',
artists=u'',
has_image=has_image,
)
image_content = ContentFile(raw_image_contents)
fname, ext = os.path.splitext("default.jpg")
fname = u'%s%s' % (uuid4().hex[::2], ext)
ex.image.save(fname, image_content, save=False)
ex._create_resized_images(raw_field=None, save=False)
ex.save()
print ex, ex.ext_event_id
rnum += 1
示例3: import_mlb
# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import _create_resized_images [as 别名]
#.........这里部分代码省略.........
hashtags = homevars['hashtags']
# generate 211x211 badge
raw_image_contents = None
bg = Image.new("RGB", (211, 211), homecolors[1]) # background is the sec color of home team
bgimg = Image.open(eventbgpath)
bg.paste(bgimg, (0, 0))
t = ImageDraw.Draw(bg)
# Road team name
x, y = settings.SPORTS_TEAM_TEXT_START
font = ImageFont.truetype(settings.SPORTS_TEAM_TEXT_FONT, settings.SPORTS_TEAM_TEXT_FONT_SIZE, encoding='unic')
tx = roadvars['name']
w,h = t.textsize(tx, font=font)
x = (211 - w)/2 # center align
col = roadcolors[0] # (homecolors[1] == roadcolors[0]) and roadcolors[1] or roadcolors[0]
t.text((x, y), tx, font=font, fill=col)
# Text = at
x, y = x, y + settings.SPORTS_TEAM_TEXT_FONT_SIZE + 10
font = ImageFont.truetype(settings.SPORTS_TEAM_TEXT_FONT, settings.SPORTS_TEAM_TEXT_SMALL_FONT_SIZE, encoding='unic')
tx = 'at'
w,h = t.textsize(tx, font=font)
x = (211 - w)/2 # center align
t.text((x, y), tx, font=font, fill='#333333')
# Home team name
x, y = x, y + settings.SPORTS_TEAM_TEXT_SMALL_FONT_SIZE + 10
font = ImageFont.truetype(settings.SPORTS_TEAM_TEXT_FONT, settings.SPORTS_TEAM_TEXT_FONT_SIZE, encoding='unic')
tx = homevars['name']
w,h = t.textsize(tx, font=font)
x = (211 - w)/2 # center align
t.text((x, y), tx, font=font, fill=homecolors[0])
raw_image_contents = get_raw_png_image(bg)
# get venue
vn = homevars['venue']
location = settings.STATE_TO_LOCATION_MAP.get(vn.state.lower(), 'user-entered')
city_state = u'%s|%s' % (vn.city, vn.state)
location = settings.CITY_STATE_TO_LOCATION_MAP.get(city_state.lower(), location)
# special cases for locations
if vn.state == 'NJ':
location = 'user-defined'
dt = strptime(dt, _DATE_FORMAT)
event_date = date(*dt[:3])
tz = homevars['tz']
if tz == 'ET':
xtime = etime
elif tz == 'CT':
xtime = ctime
elif tz == 'MT':
xtime = mtime
elif tz == 'PT':
xtime = ptime
else:
xtime = etime # default timezone is ET
tt = strptime(xtime.strip(), _TIME_FORMAT)
h, m = tt.tm_hour, tt.tm_min
if 'PM' in etime.upper() and h < 12:
h = h + 12
event_time = u"%s:%s" % (h, m)
title = u"%s! %s" % (title, event_date.strftime("%m/%d"))
# save event
ex = Event(
ext_event_id="999",
ext_event_source=event_source,
artist=_ARTIST,
creator=homeuser,
description=description,
is_submitted=True,
is_approved=True,
is_free=False,
title=title[:120],
url=(u"%s-%s" % (slugify(title)[:30], uuid4().hex[::4]))[:35],
venue=vn,
event_date=event_date,
event_start_time=event_time,
event_timezone=tz,
hashtag=hashtags,
location=location,
headliner=u'',
artists=u'',
has_image=True,
)
image_content = ContentFile(raw_image_contents)
fname, ext = os.path.splitext("default.jpg")
fname = u'%s%s' % (uuid4().hex[::2], ext)
ex.image.save(fname, image_content, save=False)
ex._create_resized_images(raw_field=None, save=False)
ex.save()
# favorite event for home users
ex.attendee_set.get_or_create(attendee_profile=homeuser)
# ex.attendee_set.get_or_create(attendee_profile=roaduser)
if num > limit:
return
示例4: insert
# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import _create_resized_images [as 别名]
#.........这里部分代码省略.........
full_list.insert(0, headliner)
csv_artist_list = full_list and u",".join(full_list) or u""
quoted_list = [u'"%s"' % a for a in full_list]
hashtag = u",".join(quoted_list)
art_html = [u"<li>%s</li>" % a for a in artist_list]
if headliner:
art_html.insert(0, u'<li class="headliner">%s</li>' % headliner)
art_html = u"<h4 class='artist_title'>Artists</h4><ul class='artist_list'>%s</ul>\n" % u"\n".join(art_html)
desc = u"%s%s" % (art_html, desc)
venue = e['venue']['name'].strip()
venue_address = e['venue']['location']['street'].strip()
venue_city = e['venue']['location']['city'].strip()
venue_zip = e['venue']['location']['postalcode'].strip()
if headliner and venue and headliner == title:
# Change title format to:
# headliner at venue name! mm/dd
mm_dd = event_date.strftime("%m/%d")
title = u"%s at %s! %s" % (headliner, venue, mm_dd)
if len(title) > 120:
title = u"%s.." % title[:118]
lat, lng = None, None
source = ''
if e['venue']['location'].get("geo:point", {}).get("geo:lat", None):
lat = e['venue']['location']["geo:point"]["geo:lat"]
lng = e['venue']['location']["geo:point"]["geo:long"]
lat = str(round(float(lat), 3))
lng = str(round(float(lng), 3))
source = u"%s,%s" % (lat, lng)
tz = e['venue']['location'].get('timezone', '')
event_time = e.get('startTime', "21:00")
has_start_time = 'startTime' in e
image_content = ContentFile(get_raw_image(image))
fname, ext = os.path.splitext(image)
fname = u'%s%s' % (uuid4().hex[::2], ext)
vn, created = Venue.objects.get_or_create(
name=venue[:255],
geo_loc=source,
defaults=dict(
source='last-fm',
address=venue_address[:255],
city=venue_city[:255],
zip_code=venue_zip[:12],
venue_url=venue_url[:255],
)
)
if False and not created and vn.source != 'last-fm':
# Update empty fields
dirty = False
if not vn.address:
vn.address = venue_address[:255]
dirty = True
if not vn.city:
vn.city = venue_city[:255]
dirty = True
if not vn.zip_code:
vn.zip_code = venue_zip[:12]
dirty = True
if not vn.venue_url:
vn.venue_url = venue_url[:255]
dirty = True
if dirty:
vn.save()
if existing_event:
# only update title on this existing event
existing_event.title = title[:120]
super(Event, existing_event).save()
_x.debug("Updated title for %s", existing_event)
else:
user_profile = get_artist_user_profile(headliner)
ex = Event(
lastfm_id = lfm_id,
artist=_ARTIST,
creator=user_profile,
is_submitted=True,
is_approved=True,
title=title[:120],
url=(u"%s-%s" % (slugify(title)[:30], uuid4().hex[::4]))[:35],
description=desc,
venue=vn,
event_date=event_date,
event_start_time=event_time,
event_timezone=tz,
hashtag=u'', # hashtag[:250], # don't fetch tweets for last.fm generated events (3/23/2010)
location=loc,
headliner=headliner[:200] or u'',
artists=csv_artist_list[:250] or u'',
ext_event_source='last.fm',
)
ex._has_start_time = ex.event_start_time and has_start_time
ey = try_merge(ex)
if ey:
# new event is a duplicate; hide it
ex.is_deleted = True
_x.warn("Merged %s into %s", ex, ey)
ex.image.save(fname, image_content, save=False)
ex._create_resized_images(raw_field=None, save=False)
ex.save()
ex.attendee_set.get_or_create(attendee_profile=user_profile)
_x.debug("Saved %s", ex)
n += 1