Skip to content

Commit

Permalink
Default image
Browse files Browse the repository at this point in the history
  • Loading branch information
bsoyka committed Sep 27, 2019
1 parent c0882c2 commit 68addc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions gravify/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import urllib, hashlib
import urllib.parse
import hashlib
from validate_email import validate_email
is_valid = validate_email('[email protected]')

class Gravatar():

def __init__(self, email, verify_email=True):
def __init__(self, email, verify_email=True, default_image=None):
if verify_email:
if not validate_email(email):
raise Exception("Invalid email address")

self.email = email
self.default_image = default_image

@property
def url(self):
return "https://www.gravatar.com/avatar/" + hashlib.md5(self.email.encode("utf-8").lower()).hexdigest()
params = {}

if self.default_image != None:
params["d"] = self.default_image

return "https://www.gravatar.com/avatar/" + hashlib.md5(self.email.encode("utf-8").lower()).hexdigest() + "?" + urllib.parse.urlencode(params)

@property
def unsecure_url(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="gravify",
version="0.0.2",
version="0.0.3",
author="Benjamin Soyka",
author_email="[email protected]",
description="A simple package to generate a Gravatar URL",
Expand Down

0 comments on commit 68addc9

Please sign in to comment.