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:
@@ -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)
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
# Hello there ! <img src="./img/Hi.gif" alt="Wave hand" width="50px" height="50px"/>
|
# Hello there ! <img src="./img/Hi.gif" alt="Wave hand" width="50px" height="50px"/>
|
||||||
|
|
||||||
I'm Lucàs, a passionate developer from Rodez, France.
|
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
|
### I code with
|
||||||

|

|
||||||

|

|
||||||
|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
@@ -18,21 +19,21 @@ I'm Lucàs, a passionate developer from Rodez, France.
|
|||||||

|

|
||||||

|

|
||||||

|

|
||||||
|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|

|
||||||

|

|
||||||

|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
### Where to find me
|
### Where to find me
|
||||||
[](https://github.com/LucasVbr)
|
[](https://github.com/LucasVbr)
|
||||||
[](https://www.linkedin.com/in/lucasvbr)
|
[](https://www.linkedin.com/in/lucasvbr)
|
||||||
[](https://www.freecodecamp.org/LucasVbr)
|
[](https://www.freecodecamp.org/LucasVbr)
|
||||||
|
|
||||||
@@ -41,10 +42,11 @@ I'm Lucàs, a passionate developer from Rodez, France.
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
This README is generated every day.<br>
|
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>
|
||||||

|

|
||||||

|

|
||||||
<br>
|

|
||||||
|
|
||||||
|
|
||||||
*inspired by [Thomas Guibert](https://github.com/thmsgbrt)*
|
*inspired by [Thomas Guibert](https://github.com/thmsgbrt)*
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
"CSS3",
|
"CSS3",
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
"Pug",
|
"Pug",
|
||||||
"Sass",
|
|
||||||
"TypeScript",
|
|
||||||
"PHP",
|
"PHP",
|
||||||
"Java",
|
"Java",
|
||||||
"C",
|
"C",
|
||||||
@@ -17,11 +15,14 @@
|
|||||||
"Figma",
|
"Figma",
|
||||||
"Git",
|
"Git",
|
||||||
"MariaDB",
|
"MariaDB",
|
||||||
"Microsoft SQL Server",
|
|
||||||
"MySQL",
|
"MySQL",
|
||||||
"PostgreSQL",
|
"PostgreSQL",
|
||||||
"SQLite",
|
"SQLite",
|
||||||
"Android",
|
"Android",
|
||||||
"Linux",
|
"Linux",
|
||||||
"Windows"
|
"Windows",
|
||||||
|
"Insomnia",
|
||||||
|
"JetBrains",
|
||||||
|
"Visual Studio Code",
|
||||||
|
"FileZilla"
|
||||||
]
|
]
|
||||||
@@ -3,42 +3,23 @@
|
|||||||
__author__ = "LucasVbr"
|
__author__ = "LucasVbr"
|
||||||
__version__ = "3.0.0"
|
__version__ = "3.0.0"
|
||||||
|
|
||||||
import requests
|
from Utils import *
|
||||||
from flask import render_template
|
from src.FileUtils import getJsonData
|
||||||
import flask
|
|
||||||
from Badge import *
|
|
||||||
from FileUtils import *
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
TEMPLATE_FILE = "index.md.jinja"
|
CONFIG_FILE = "config.json"
|
||||||
TOOLS_DATA = "tools.json"
|
|
||||||
OUTPUT_FILE = "README.md"
|
|
||||||
|
|
||||||
app = flask.Flask('my app')
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Get tools badges
|
configData = getJsonData(CONFIG_FILE)
|
||||||
toolsData = getJsonData(TOOLS_DATA)
|
|
||||||
tools = [Badge(toolName) for toolName in toolsData]
|
|
||||||
tools.sort(key=getBadgeColor) # Sort by color
|
|
||||||
|
|
||||||
# Get Weather
|
data = getDataSubfiles(configData.get("data_files"))
|
||||||
request = requests.get("https://goweather.herokuapp.com/weather/rodez")
|
data["info"] = configData.get("info")
|
||||||
weather_status = request.status_code
|
data["tools"] = convertToolBadges(data.get("tools"))
|
||||||
weather = request.json()
|
data["weather"] = getWeather(data.get("info").get('city'))
|
||||||
|
data['today'] = datetime.today().strftime("%A %d %B %y, %H:%M")
|
||||||
|
|
||||||
# Get current datetime
|
buildFile(
|
||||||
today = datetime.today().strftime("%A %d %B %y, %H:%M")
|
configData.get("template_file"),
|
||||||
|
configData.get("output_file"),
|
||||||
# Build from template and data
|
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)
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
flask~=2.1.2
|
flask~=2.1.2
|
||||||
requests~=2.27.1
|
|
||||||
colour~=0.1.5
|
colour~=0.1.5
|
||||||
simpleicons~=6.23.0
|
simpleicons~=6.23.0
|
||||||
|
meteofrance-api~=1.0.2
|
||||||
@@ -30,6 +30,7 @@ class Badge:
|
|||||||
|
|
||||||
icon = icons.get(self.name)
|
icon = icons.get(self.name)
|
||||||
|
|
||||||
|
try:
|
||||||
params = {
|
params = {
|
||||||
"label": "",
|
"label": "",
|
||||||
"message": icon.title,
|
"message": icon.title,
|
||||||
@@ -38,10 +39,11 @@ class Badge:
|
|||||||
"logoColor": LOGO_COLOR
|
"logoColor": LOGO_COLOR
|
||||||
}
|
}
|
||||||
urlParams = urlencode(params)
|
urlParams = urlencode(params)
|
||||||
|
|
||||||
self.url = f"{BASE_URL}?{urlParams}"
|
self.url = f"{BASE_URL}?{urlParams}"
|
||||||
self.color = Color(params["color"]).hsl
|
self.color = Color(params["color"]).get_hue()
|
||||||
|
except Exception:
|
||||||
|
pass # Let default values
|
||||||
|
|
||||||
|
|
||||||
def getBadgeColor(badge: Badge) -> float:
|
def getBadgeColor(badge: Badge) -> float:
|
||||||
return badge.color[0]
|
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)
|
||||||
+10
-11
@@ -1,27 +1,26 @@
|
|||||||
# Hello there ! <img src="./img/Hi.gif" alt="Wave hand" width="50px" height="50px"/>
|
# Hello there ! <img src="./img/Hi.gif" alt="Wave hand" width="50px" height="50px"/>
|
||||||
|
|
||||||
I'm Lucàs, a passionate developer from Rodez, France.
|
I'm {{ data.info.name }}, a passionate developer from {{ data.info.city }}, France.
|
||||||
<br>Currently, the weather is: **{{ weather.temperature }}**, **{{ weather.description }}**
|
<br>Currently, the weather is: **{{ data.weather.temperature }}°C**, **{{ data.weather.description }}**
|
||||||
|
|
||||||
### I code with
|
### I code with
|
||||||
{% for image in tools -%}
|
{% for image in data.tools -%}
|
||||||

|

|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
### Where to find me
|
### Where to find me
|
||||||
[](https://github.com/LucasVbr)
|
{% for image in data.links -%}
|
||||||
[](https://www.linkedin.com/in/lucasvbr)
|
[]({{ image.href }})
|
||||||
[](https://www.freecodecamp.org/LucasVbr)
|
{% endfor %}
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
This README is generated every day.<br>
|
This README is generated every day.<br>
|
||||||
Last refresh: **{{ today }}**<br>
|
Last refresh: **{{ data.today }}**<br>
|
||||||

|
{% for image in data.footer_badges -%}
|
||||||

|

|
||||||
<br>
|
{% endfor %}
|
||||||
|
|
||||||
*inspired by [Thomas Guibert](https://github.com/thmsgbrt)*
|
*inspired by [Thomas Guibert](https://github.com/thmsgbrt)*
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user