Using config.json

This commit is contained in:
LucasVbr
2022-06-05 12:08:02 +02:00
parent 9b46b290e1
commit 9c959af699
12 changed files with 188 additions and 91 deletions
-22
View File
@@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
"""
04/06/2022
"""
import json
__file__ = 'FileUtils.py'
__author__ = 'Lucas Vbr'
__version__ = '0.1'
def getJsonData(fileName: str) -> str:
with open(fileName) as file:
data = json.load(file)
return data
def setFileData(fileName: str, content: str):
with open(fileName, "w", encoding="utf8") as file:
file.write(content)
+9 -7
View File
@@ -1,11 +1,12 @@
# Hello there ! <img src="./img/Hi.gif" alt="Wave hand" width="50px" height="50px"/>
I'm Lucàs, a passionate developer from Rodez, France.
<br>Currently, the weather is: ****, ****
<br>Currently, the weather is: **17.4°C**, **Few showers**
### I code with
![Symfony](https://img.shields.io/static/v1?label=&message=Symfony&color=%23000000&logo=symfony&logoColor=white)
![Microsoft SQL Server](https://img.shields.io/static/v1?label=&message=Microsoft+SQL+Server&color=%23CC2927&logo=microsoftsqlserver&logoColor=white)
![JetBrains](https://img.shields.io/static/v1?label=&message=JetBrains&color=%23000000&logo=jetbrains&logoColor=white)
![FileZilla](https://img.shields.io/static/v1?label=&message=FileZilla&color=%23BF0000&logo=filezilla&logoColor=white)
![Git](https://img.shields.io/static/v1?label=&message=Git&color=%23F05032&logo=git&logoColor=white)
![Pug](https://img.shields.io/static/v1?label=&message=Pug&color=%23A86454&logo=pug&logoColor=white)
![HTML5](https://img.shields.io/static/v1?label=&message=HTML5&color=%23E34F26&logo=html5&logoColor=white)
@@ -18,21 +19,21 @@ I'm Lucàs, a passionate developer from Rodez, France.
![MariaDB](https://img.shields.io/static/v1?label=&message=MariaDB&color=%23003545&logo=mariadb&logoColor=white)
![Java](https://img.shields.io/static/v1?label=&message=Java&color=%23007396&logo=java&logoColor=white)
![SQLite](https://img.shields.io/static/v1?label=&message=SQLite&color=%23003B57&logo=sqlite&logoColor=white)
![Visual Studio Code](https://img.shields.io/static/v1?label=&message=Visual+Studio+Code&color=%23007ACC&logo=visualstudiocode&logoColor=white)
![CSS3](https://img.shields.io/static/v1?label=&message=CSS3&color=%231572B6&logo=css3&logoColor=white)
![MySQL](https://img.shields.io/static/v1?label=&message=MySQL&color=%234479A1&logo=mysql&logoColor=white)
![Windows](https://img.shields.io/static/v1?label=&message=Windows&color=%230078D6&logo=windows&logoColor=white)
![Python](https://img.shields.io/static/v1?label=&message=Python&color=%233776AB&logo=python&logoColor=white)
![TypeScript](https://img.shields.io/static/v1?label=&message=TypeScript&color=%233178C6&logo=typescript&logoColor=white)
![C](https://img.shields.io/static/v1?label=&message=C&color=%23A8B9CC&logo=c&logoColor=white)
![PostgreSQL](https://img.shields.io/static/v1?label=&message=PostgreSQL&color=%234169E1&logo=postgresql&logoColor=white)
![PHP](https://img.shields.io/static/v1?label=&message=PHP&color=%23777BB4&logo=php&logoColor=white)
![Insomnia](https://img.shields.io/static/v1?label=&message=Insomnia&color=%234000BF&logo=insomnia&logoColor=white)
![Bootstrap](https://img.shields.io/static/v1?label=&message=Bootstrap&color=%237952B3&logo=bootstrap&logoColor=white)
![Sass](https://img.shields.io/static/v1?label=&message=Sass&color=%23CC6699&logo=sass&logoColor=white)
![Angular](https://img.shields.io/static/v1?label=&message=Angular&color=%23DD0031&logo=angular&logoColor=white)
### Where to find me
[![Github](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/LucasVbr)
[![GitHub](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/LucasVbr)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/lucasvbr)
[![FreeCodeCamp](https://img.shields.io/badge/freecodecamp-27273D?style=for-the-badge&logo=freecodecamp&logoColor=white)](https://www.freecodecamp.org/LucasVbr)
@@ -41,10 +42,11 @@ I'm Lucàs, a passionate developer from Rodez, France.
<div align="center">
This README is generated every day.<br>
Last refresh: **Sunday 05 June 22, 06:16**<br>
Last refresh: **Sunday 05 June 22, 12:07**<br>
![Profile Views](https://komarev.com/ghpvc/?username=lucasvbr&amp;label=Profile%20views&amp;color=0e75b6&amp;style=flat)
![FreeCodeCamp Points](https://img.shields.io/freecodecamp/points/lucasvbr?label=FreeCodeCamp%20points)
<br>![Made with love](https://img.shields.io/badge/-made%20with%20%E2%9D%A4%EF%B8%8F-red)
![Made with love](https://img.shields.io/badge/-made%20with%20%E2%9D%A4%EF%B8%8F-red)
*inspired by [Thomas Guibert](https://github.com/thmsgbrt)*
+55
View File
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
import os.path
from flask import Flask, render_template
from src.Badge import Badge, getBadgeColor
from meteofrance_api import MeteoFranceClient
from src.FileUtils import setFileData, getJsonData
"""
05/06/2022
"""
__file__ = 'Utils.py'
__author__ = 'Lucas Vbr'
__version__ = '0.1'
def getDataSubfiles(files: list):
"""
:param files:
:return:
"""
contents = {}
for file in files:
baseName = os.path.basename(file)
fileName = os.path.splitext(baseName)[0]
contents[fileName] = getJsonData(file)
return contents
def convertToolBadges(listToolName: list) -> list[dict[str, str]]:
tools = [Badge(toolName) for toolName in listToolName]
tools.sort(key=getBadgeColor) # Sort by color
return [{"url": badge.url, "name": badge.name} for badge in tools]
def getWeather(city: str) -> dict:
meteoClient = MeteoFranceClient()
place = meteoClient.search_places(city)[0]
weather = meteoClient.get_forecast_for_place(place, language="en") \
.current_forecast
return {
"temperature": weather.get('T').get('value'),
"description": weather.get("weather").get("desc")
}
def buildFile(templateFile: str, outputFile: str, data: dict) -> None:
app = Flask('my app')
with app.app_context():
rendered = render_template(templateFile, data=data)
setFileData(outputFile, rendered)
+13
View File
@@ -0,0 +1,13 @@
{
"info": {
"name": "Lucàs",
"city": "Rodez"
},
"template_file": "index.md.jinja",
"output_file": "README.md",
"data_files": [
"data/tools.json",
"data/links.json",
"data/footer_badges.json"
]
}
+14
View File
@@ -0,0 +1,14 @@
[
{
"alt": "Profile Views",
"src": "https://komarev.com/ghpvc/?username=lucasvbr&amp;label=Profile%20views&amp;color=0e75b6&amp;style=flat"
},
{
"alt": "FreeCodeCamp Points",
"src": "https://img.shields.io/freecodecamp/points/lucasvbr?label=FreeCodeCamp%20points"
},
{
"alt": "Made with love",
"src": "https://img.shields.io/badge/-made%20with%20%E2%9D%A4%EF%B8%8F-red"
}
]
+17
View File
@@ -0,0 +1,17 @@
[
{
"src": "https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white",
"alt": "GitHub",
"href": "https://github.com/LucasVbr"
},
{
"src": "https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white",
"alt": "LinkedIn",
"href": "https://www.linkedin.com/in/lucasvbr"
},
{
"src": "https://img.shields.io/badge/freecodecamp-27273D?style=for-the-badge&logo=freecodecamp&logoColor=white",
"alt": "FreeCodeCamp",
"href": "https://www.freecodecamp.org/LucasVbr"
}
]
+5 -4
View File
@@ -3,8 +3,6 @@
"CSS3",
"JavaScript",
"Pug",
"Sass",
"TypeScript",
"PHP",
"Java",
"C",
@@ -17,11 +15,14 @@
"Figma",
"Git",
"MariaDB",
"Microsoft SQL Server",
"MySQL",
"PostgreSQL",
"SQLite",
"Android",
"Linux",
"Windows"
"Windows",
"Insomnia",
"JetBrains",
"Visual Studio Code",
"FileZilla"
]
+14 -33
View File
@@ -3,42 +3,23 @@
__author__ = "LucasVbr"
__version__ = "3.0.0"
import requests
from flask import render_template
import flask
from Badge import *
from FileUtils import *
from Utils import *
from src.FileUtils import getJsonData
from datetime import datetime
TEMPLATE_FILE = "index.md.jinja"
TOOLS_DATA = "tools.json"
OUTPUT_FILE = "README.md"
app = flask.Flask('my app')
CONFIG_FILE = "config.json"
if __name__ == "__main__":
# Get tools badges
toolsData = getJsonData(TOOLS_DATA)
tools = [Badge(toolName) for toolName in toolsData]
tools.sort(key=getBadgeColor) # Sort by color
configData = getJsonData(CONFIG_FILE)
# Get Weather
request = requests.get("https://goweather.herokuapp.com/weather/rodez")
weather_status = request.status_code
weather = request.json()
data = getDataSubfiles(configData.get("data_files"))
data["info"] = configData.get("info")
data["tools"] = convertToolBadges(data.get("tools"))
data["weather"] = getWeather(data.get("info").get('city'))
data['today'] = datetime.today().strftime("%A %d %B %y, %H:%M")
# Get current datetime
today = datetime.today().strftime("%A %d %B %y, %H:%M")
# Build from template and data
with app.app_context():
rendered = render_template(
TEMPLATE_FILE,
tools=tools,
weather_status=weather_status,
weather=weather,
today=today
)
# Generate Markdown file
setFileData(OUTPUT_FILE, rendered)
buildFile(
configData.get("template_file"),
configData.get("output_file"),
data
)
+2 -2
View File
@@ -1,4 +1,4 @@
flask~=2.1.2
requests~=2.27.1
colour~=0.1.5
simpleicons~=6.23.0
simpleicons~=6.23.0
meteofrance-api~=1.0.2
+14 -12
View File
@@ -30,18 +30,20 @@ class Badge:
icon = icons.get(self.name)
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"]).hsl
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]
return badge.color
+35
View File
@@ -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)
+10 -11
View File
@@ -1,27 +1,26 @@
# Hello there ! <img src="./img/Hi.gif" alt="Wave hand" width="50px" height="50px"/>
I'm Lucàs, a passionate developer from Rodez, France.
<br>Currently, the weather is: **{{ weather.temperature }}**, **{{ weather.description }}**
I'm {{ data.info.name }}, a passionate developer from {{ data.info.city }}, France.
<br>Currently, the weather is: **{{ data.weather.temperature }}°C**, **{{ data.weather.description }}**
### I code with
{% for image in tools -%}
{% for image in data.tools -%}
![{{ image.name }}]({{ image.url }})
{% endfor %}
### Where to find me
[![Github](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/LucasVbr)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/lucasvbr)
[![FreeCodeCamp](https://img.shields.io/badge/freecodecamp-27273D?style=for-the-badge&logo=freecodecamp&logoColor=white)](https://www.freecodecamp.org/LucasVbr)
{% for image in data.links -%}
[![{{ image.alt }}]({{ image.src }})]({{ image.href }})
{% endfor %}
---
<div align="center">
This README is generated every day.<br>
Last refresh: **{{ today }}**<br>
![Profile Views](https://komarev.com/ghpvc/?username=lucasvbr&amp;label=Profile%20views&amp;color=0e75b6&amp;style=flat)
![FreeCodeCamp Points](https://img.shields.io/freecodecamp/points/lucasvbr?label=FreeCodeCamp%20points)
<br>![Made with love](https://img.shields.io/badge/-made%20with%20%E2%9D%A4%EF%B8%8F-red)
Last refresh: **{{ data.today }}**<br>
{% for image in data.footer_badges -%}
![{{ image.alt }}]({{ image.src }})
{% endfor %}
*inspired by [Thomas Guibert](https://github.com/thmsgbrt)*