new file: generate.py

new file:   templates/sites.json
	new file:   templates/template.html
main
anthony 2 months ago
parent a9467ab721
commit 2326c2ab43

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My LinkTree</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.button {
display: flex;
align-items: center;
padding: 15px 30px;
font-size: 18px;
color: white;
background-color: #007BFF;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease;
margin: 10px;
width: 200px;
text-align: center;
}
.button:hover {
background-color: #0056b3;
}
.button img {
width: 24px;
height: 24px;
margin-right: 10px;
}
</style>
</head>
<body>
<a href="https://lemmy.cif.su/u/anthony" class="button">lemmy.cif.su</a>
<a href="https://code.cif.su/anthony" class="button">code.cif.su</a>
<a href="https://www.youtube.com/@Samu_Different" class="button">
<img src="https://example.com/icons/youtube.svg" alt="youtube icon">
YouTube
</a>
</body>
</html>

@ -0,0 +1,66 @@
import json
def load_social_media_data():
# Load social media data from JSON file
with open("./templates/sites.json", "r") as file:
return json.load(file)
def detect_platform(link, social_media_data):
# Detect the platform from the link
for platform in social_media_data:
if platform in link:
return platform
return None
def generate_html(links, social_media_data):
# Read the template file
with open("./templates/template.html", "r") as file:
template = file.read()
# Generate button elements for each link
buttons = ""
for link in links:
platform = detect_platform(link, social_media_data)
if platform:
icon_url = social_media_data[platform]["icon"]
platform_name = social_media_data[platform]["name"]
buttons += f'''
<a href="{link}" class="button">
<img src="{icon_url}" alt="{platform} icon">
{platform_name}
</a>\n
'''
else:
# If the platform is not recognized, use the domain name as the button text
domain = link.split("//")[-1].split("/")[0] # Extract domain from link
buttons += f'<a href="{link}" class="button">{domain}</a>\n'
# Replace the placeholder with the generated buttons
template = template.replace("{links}", buttons)
# Save the new HTML file
output_file = "./generated/visicard.html"
with open(output_file, "w") as file:
file.write(template)
print(f"Your Linktree '{output_file}' has been generated successfully!")
if __name__ == "__main__":
# Load social media data
social_media_data = load_social_media_data()
# Ask the user how many links they want to add
try:
num_links = int(input("How many links do you want to add? "))
except ValueError:
print("Please enter a valid number.")
exit()
# Ask the user for each link
links = []
for i in range(1, num_links + 1):
link = input(f"Please enter Link {i}: ")
links.append(link)
# Generate the HTML file
generate_html(links, social_media_data)

@ -0,0 +1,26 @@
{
"youtube": {
"icon": "https://example.com/icons/youtube.svg",
"name": "YouTube"
},
"twitter": {
"icon": "https://example.com/icons/twitter.svg",
"name": "Twitter"
},
"github": {
"icon": "https://example.com/icons/github.svg",
"name": "GitHub"
},
"instagram": {
"icon": "https://example.com/icons/instagram.svg",
"name": "Instagram"
},
"linkedin": {
"icon": "https://example.com/icons/linkedin.svg",
"name": "LinkedIn"
},
"facebook": {
"icon": "https://example.com/icons/facebook.svg",
"name": "Facebook"
}
}

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My LinkTree</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.button {
display: flex;
align-items: center;
padding: 15px 30px;
font-size: 18px;
color: white;
background-color: #007BFF;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease;
margin: 10px;
width: 200px;
text-align: center;
}
.button:hover {
background-color: #0056b3;
}
.button img {
width: 24px;
height: 24px;
margin-right: 10px;
}
</style>
</head>
<body>
{links}
</body>
</html>
Loading…
Cancel
Save