mirror of
https://github.com/LucasVbr/LucasVbr.git
synced 2026-05-13 17:11:52 +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"/>
|
||||
|
||||
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
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

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

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
|
||||
### Where to find me
|
||||
[](https://github.com/LucasVbr)
|
||||
[](https://github.com/LucasVbr)
|
||||
[](https://www.linkedin.com/in/lucasvbr)
|
||||
[](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>
|
||||

|
||||

|
||||
<br>
|
||||

|
||||
|
||||
|
||||
*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",
|
||||
"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"
|
||||
]
|
||||
@@ -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
@@ -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
@@ -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
|
||||
@@ -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"/>
|
||||
|
||||
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 -%}
|
||||

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

|
||||

|
||||
<br>
|
||||
Last refresh: **{{ data.today }}**<br>
|
||||
{% for image in data.footer_badges -%}
|
||||

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