mirror of
https://github.com/LucasVbr/LucasVbr.git
synced 2026-07-09 14:27:46 +00:00
Using config.json
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from simpleicons.all import icons
|
||||
from urllib.parse import urlencode
|
||||
from colour import Color
|
||||
|
||||
"""
|
||||
04/06/2022
|
||||
"""
|
||||
|
||||
__file__ = 'Badge.py'
|
||||
__author__ = 'Lucas Vbr'
|
||||
__version__ = '0.1'
|
||||
|
||||
|
||||
class Badge:
|
||||
def __init__(self, badgeName: str):
|
||||
self.name = badgeName
|
||||
self.url = ""
|
||||
self.color = 0
|
||||
|
||||
self.buildUrl()
|
||||
|
||||
def get_color(self):
|
||||
return self.color
|
||||
|
||||
def buildUrl(self):
|
||||
BASE_URL = "https://img.shields.io/static/v1"
|
||||
LOGO_COLOR = "white"
|
||||
|
||||
icon = icons.get(self.name)
|
||||
|
||||
try:
|
||||
params = {
|
||||
"label": "",
|
||||
"message": icon.title,
|
||||
"color": f"#{icon.hex}",
|
||||
"logo": icon.slug,
|
||||
"logoColor": LOGO_COLOR
|
||||
}
|
||||
urlParams = urlencode(params)
|
||||
self.url = f"{BASE_URL}?{urlParams}"
|
||||
self.color = Color(params["color"]).get_hue()
|
||||
except Exception:
|
||||
pass # Let default values
|
||||
|
||||
|
||||
def getBadgeColor(badge: Badge) -> float:
|
||||
return badge.color
|
||||
@@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
04/06/2022
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
__file__ = 'FileUtils.py'
|
||||
__author__ = 'Lucas Vbr'
|
||||
__version__ = '0.1'
|
||||
|
||||
DEFAULT_FILE_ENCODING = "utf8"
|
||||
|
||||
|
||||
def getJsonData(filePath: str) -> str:
|
||||
"""
|
||||
Take data from JSON File
|
||||
:param filePath: Path of the file to read
|
||||
:return: The content of the JSON file
|
||||
"""
|
||||
with open(filePath, encoding=DEFAULT_FILE_ENCODING) as file:
|
||||
data = json.load(file)
|
||||
return data
|
||||
|
||||
|
||||
def setFileData(filePath: str, content: str) -> None:
|
||||
"""
|
||||
Create a new File or replace it content if already exist
|
||||
:param filePath: Path of the file to fill
|
||||
:param content: Content to place in the file
|
||||
:return: None
|
||||
"""
|
||||
with open(filePath, "w", encoding=DEFAULT_FILE_ENCODING) as file:
|
||||
file.write(content)
|
||||
Reference in New Issue
Block a user