-
Notifications
You must be signed in to change notification settings - Fork 2
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
6 changed files
with
134 additions
and
15 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 |
---|---|---|
|
@@ -7,6 +7,7 @@ verify_ssl = true | |
|
||
[packages] | ||
requests = "*" | ||
validators = "*" | ||
|
||
[requires] | ||
python_version = "3.8" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import requests | ||
import validators | ||
import os | ||
import re | ||
|
||
class Cape: | ||
|
||
def __init__(self, filename: str): | ||
self.__filename = filename | ||
self.__extension = None | ||
|
||
@property | ||
def exists(self): | ||
do_exists = False | ||
|
||
if validators.url(self.__filename) == True: | ||
response = requests.head(self.__filename, allow_redirects=True) | ||
if response.status_code == 200: | ||
do_exists = True | ||
elif os.path.exists(self.__filename): | ||
do_exists = True | ||
|
||
return do_exists | ||
|
||
@property | ||
def data(self): | ||
image_bytes = None | ||
if validators.url(self.__filename) == True: | ||
response = requests.get(self.__filename) | ||
if response.ok: | ||
filenames = re.findall('filename=(.+)', response.headers.get('content-disposition')) | ||
if len(filenames) > 0: | ||
self.__extension = os.path.splitext(filenames[0].replace('"','').strip())[1] | ||
image_bytes = response.content | ||
elif os.path.exists(self.__filename): | ||
self.__extension = os.path.splitext(self.__filename)[1] | ||
with open(self.__filename,'rb') as fp: | ||
image_bytes = fp.read() | ||
|
||
return image_bytes | ||
|
||
def to_file(self, filename: str): | ||
file_data = self.data | ||
file_path = filename + self.__extension | ||
|
||
if file_data is not None and self.__extension is not None: | ||
with open(file_path, 'wb') as fp: | ||
fp.write(file_data) |
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import requests | ||
import validators | ||
import os | ||
import re | ||
|
||
class Skin: | ||
|
||
def __init__(self, filename: str, variant='classic'): | ||
self.__filename = filename | ||
self.__variant = variant | ||
self.__extension = None | ||
|
||
@property | ||
def variant(self): | ||
return self.__variant | ||
|
||
@property | ||
def exists(self): | ||
do_exists = False | ||
|
||
if validators.url(self.__filename) == True: | ||
response = requests.get(self.__filename) | ||
if response.status_code == 200: | ||
do_exists = True | ||
elif os.path.exists(self.__filename): | ||
do_exists = True | ||
|
||
return do_exists | ||
|
||
@property | ||
def data(self): | ||
image_bytes = None | ||
if validators.url(self.__filename) == True: | ||
response = requests.get(self.__filename) | ||
if response.ok: | ||
filenames = re.findall('filename=(.+)', response.headers.get('content-disposition')) | ||
if len(filenames) > 0: | ||
self.__extension = os.path.splitext(filenames[0].replace('"','').strip())[1] | ||
image_bytes = response.content | ||
elif os.path.exists(self.__filename): | ||
self.__extension = os.path.splitext(self.__filename)[1] | ||
with open(self.__filename,'rb') as fp: | ||
image_bytes = fp.read() | ||
|
||
return image_bytes | ||
|
||
def to_file(self, filename: str): | ||
file_data = self.data | ||
file_path = filename + self.__extension | ||
|
||
if file_data is not None and self.__extension is not None: | ||
with open(file_path, 'wb') as fp: | ||
fp.write(file_data) |