-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
12 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|