Last active
April 12, 2022 13:32
-
-
Save emresaglam/aac93986da22914b89bf7209b5440cf0 to your computer and use it in GitHub Desktop.
Heimdall to Homer migration script. (No error handling, etc...)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MINI HOWTO | |
# 0. You will need PyYaml and BeautifulSoup python libraries. (Installation is up to you to figure it out) | |
# 1. Go to your heimdall page and save the html file. Note the file location. | |
# 2. Add the file location to heimdall_page variable. | |
# 3. Add the current homer yml file location as base_yaml variable. | |
# 4. Add your generated homer yaml file location to homer_config variable. | |
# 5. Define your icons folder. (Mine was in homer-icons/png) | |
import yaml | |
from yaml.loader import SafeLoader | |
from bs4 import BeautifulSoup as BS | |
heimdall_page = "<SAVED HEIMDALL PAGE>.html" | |
base_yaml = "<HOMER yml FILE>" | |
homer_config = "<LOCATION OF YOUR NEW CONFIG FILE>" | |
icons_folder = "assets/homer-icons/png/" | |
with open(base_yaml, "r") as f: | |
configfile = yaml.load(f, Loader=SafeLoader) | |
# print(configfile) | |
with open(heimdall_page, "r") as f: | |
content = f.read() | |
soup = BS(content, "html.parser") | |
contents = soup.find(id="sortable").find_all("section") | |
for section in contents: | |
if section.find(class_="title"): | |
title = section.find(class_="title").text | |
link = section.select("a")[0].get("href") | |
image = section.select("img")[0].get("src").split("/")[-1] | |
image = icons_folder + image | |
configfile["services"][0]["items"].append({"name": title, "logo": image, "subtitle": "", 'tag': 'app', "url": link, "target": "_blank"}) | |
print(yaml.dump(configfile)) | |
g = open(homer_config, "w") | |
g.write(yaml.dump(configfile, default_flow_style=False)) | |
g.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment