From 9c959af699a63d37321d59f18941eb64ba23d326 Mon Sep 17 00:00:00 2001 From: LucasVbr Date: Sun, 5 Jun 2022 12:08:02 +0200 Subject: [PATCH] Using config.json --- FileUtils.py | 22 -------------- README.md | 16 +++++----- Utils.py | 55 +++++++++++++++++++++++++++++++++++ config.json | 13 +++++++++ data/footer_badges.json | 14 +++++++++ data/links.json | 17 +++++++++++ tools.json => data/tools.json | 9 +++--- main.py | 47 +++++++++--------------------- requirements.txt | 4 +-- Badge.py => src/Badge.py | 26 +++++++++-------- src/FileUtils.py | 35 ++++++++++++++++++++++ templates/index.md.jinja | 21 +++++++------ 12 files changed, 188 insertions(+), 91 deletions(-) delete mode 100644 FileUtils.py create mode 100644 Utils.py create mode 100644 config.json create mode 100644 data/footer_badges.json create mode 100644 data/links.json rename tools.json => data/tools.json (75%) rename Badge.py => src/Badge.py (56%) create mode 100644 src/FileUtils.py diff --git a/FileUtils.py b/FileUtils.py deleted file mode 100644 index eddd169..0000000 --- a/FileUtils.py +++ /dev/null @@ -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) diff --git a/README.md b/README.md index f79587f..f53edaa 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # Hello there ! Wave hand I'm Lucàs, a passionate developer from Rodez, France. -
Currently, the weather is: ****, **** +
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.
This README is generated every day.
-Last refresh: **Sunday 05 June 22, 06:16**
+Last refresh: **Sunday 05 June 22, 12:07**
![Profile Views](https://komarev.com/ghpvc/?username=lucasvbr&label=Profile%20views&color=0e75b6&style=flat) ![FreeCodeCamp Points](https://img.shields.io/freecodecamp/points/lucasvbr?label=FreeCodeCamp%20points) -
![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)* diff --git a/Utils.py b/Utils.py new file mode 100644 index 0000000..49d1cdc --- /dev/null +++ b/Utils.py @@ -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) diff --git a/config.json b/config.json new file mode 100644 index 0000000..22b569e --- /dev/null +++ b/config.json @@ -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" + ] +} \ No newline at end of file diff --git a/data/footer_badges.json b/data/footer_badges.json new file mode 100644 index 0000000..5759e85 --- /dev/null +++ b/data/footer_badges.json @@ -0,0 +1,14 @@ +[ + { + "alt": "Profile Views", + "src": "https://komarev.com/ghpvc/?username=lucasvbr&label=Profile%20views&color=0e75b6&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" + } +] \ No newline at end of file diff --git a/data/links.json b/data/links.json new file mode 100644 index 0000000..26fa774 --- /dev/null +++ b/data/links.json @@ -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" + } +] \ No newline at end of file diff --git a/tools.json b/data/tools.json similarity index 75% rename from tools.json rename to data/tools.json index dcb436a..5fe2615 100644 --- a/tools.json +++ b/data/tools.json @@ -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" ] \ No newline at end of file diff --git a/main.py b/main.py index 9749620..af19ec7 100644 --- a/main.py +++ b/main.py @@ -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 + ) diff --git a/requirements.txt b/requirements.txt index c04cc0d..3fbec87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ flask~=2.1.2 -requests~=2.27.1 colour~=0.1.5 -simpleicons~=6.23.0 \ No newline at end of file +simpleicons~=6.23.0 +meteofrance-api~=1.0.2 \ No newline at end of file diff --git a/Badge.py b/src/Badge.py similarity index 56% rename from Badge.py rename to src/Badge.py index a5e5439..0d1606e 100644 --- a/Badge.py +++ b/src/Badge.py @@ -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 diff --git a/src/FileUtils.py b/src/FileUtils.py new file mode 100644 index 0000000..fa68ea9 --- /dev/null +++ b/src/FileUtils.py @@ -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) diff --git a/templates/index.md.jinja b/templates/index.md.jinja index ae504a4..c83bc9f 100644 --- a/templates/index.md.jinja +++ b/templates/index.md.jinja @@ -1,27 +1,26 @@ # Hello there ! Wave hand -I'm Lucàs, a passionate developer from Rodez, France. -
Currently, the weather is: **{{ weather.temperature }}**, **{{ weather.description }}** +I'm {{ data.info.name }}, a passionate developer from {{ data.info.city }}, France. +
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 %} ---
This README is generated every day.
-Last refresh: **{{ today }}**
-![Profile Views](https://komarev.com/ghpvc/?username=lucasvbr&label=Profile%20views&color=0e75b6&style=flat) -![FreeCodeCamp Points](https://img.shields.io/freecodecamp/points/lucasvbr?label=FreeCodeCamp%20points) -
![Made with love](https://img.shields.io/badge/-made%20with%20%E2%9D%A4%EF%B8%8F-red) +Last refresh: **{{ data.today }}**
+{% for image in data.footer_badges -%} + ![{{ image.alt }}]({{ image.src }}) +{% endfor %} *inspired by [Thomas Guibert](https://github.com/thmsgbrt)*