-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.py
More file actions
23 lines (20 loc) · 769 Bytes
/
util.py
File metadata and controls
23 lines (20 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import uuid
import base64
import urllib
import hashlib
def generate_key():
"""
generates a uuid, encodes it with base32 and strips it's padding.
this reduces the string size from 32 to 26 chars.
"""
return base64.b32encode(uuid.uuid4().bytes).strip('=').lower()
def gravatar(email):
gravatar_url = "https://secure.gravatar.com/avatar?"
gravatar_url += urllib.urlencode({'gravatar_id': hashlib.md5(email.encode("utf8").lower()).hexdigest(), 'd': 'https://www.blossom.io/static/img/ui/blank-avatar.gif'})
return gravatar_url
def generate_name_from_email(email):
"""
use email to generate a user name
by replacing dots with spaces and then titlecases words
"""
return " ".join(email.split('@')[0].split('.')).title()