Created
March 27, 2024 21:49
export f-list preferences to plain/readable html
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
import sys | |
from bs4 import BeautifulSoup | |
# usage: python3 flist-formatter.py character-page.html > output.html | |
file_read = sys.argv[1] | |
sections = ["Character_FetishlistFave", "Character_FetishlistYes", "Character_FetishlistMaybe", "Character_FetishlistNo"] | |
with open(file_read, 'r') as f: | |
file = f.read() | |
soup = BeautifulSoup(file) | |
html = "" | |
html_start = '''<!DOCTYPE html> | |
<html> | |
<head> | |
<title>f-list</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body style="margin:0; padding:0;"> | |
<div class="html1" style="min-width: 1024px; text-align: left; overflow-x: auto; overflow-y: auto; background-color: rgb(255,255,255); position: relative; min-height: 2853px; z-index: 0;"> | |
<div class="html" style="text-align:left; color:rgb(0,0,0); font-family:Tahoma; font-size:11px; overflow-x:visible; overflow-y:visible;"> | |
<div class="body" style="vertical-align:bottom; min-height:2837px; text-align:left; color:rgb(0,0,0); background-color: rgb(255,255,255); font-family:Tahoma; font-size:11px; overflow-x:visible; overflow-y:visible; margin: 8px;"> | |
<table style="text-align:left;"> | |
<tbody style="text-align:left;"> | |
<tr style="text-align:left;"> | |
''' | |
for section in sections: | |
if section == "Character_FetishlistFave": | |
html_start += ''' <td style="color:rgb(0,0,0); text-align:left; vertical-align:top; font-size:18px; font-weight:bold;">Favourites</td> | |
''' | |
if section == "Character_FetishlistYes": | |
html_start += ''' <td style="color:rgb(0,0,0); text-align:left; vertical-align:top; font-size:18px; font-weight:bold;">Yes</td> | |
''' | |
if section == "Character_FetishlistMaybe": | |
html_start += ''' <td style="color:rgb(0,0,0); text-align:left; vertical-align:top; font-size:18px; font-weight:bold;">Maybe</td> | |
''' | |
if section == "Character_FetishlistNo": | |
html_start += ''' <td style="color:rgb(0,0,0); text-align:left; vertical-align:top; font-size:18px; font-weight:bold;">No</td> | |
''' | |
html_start += ''' </tr> | |
<tr style="text-align:left;">''' | |
html_end = ''' | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html>''' | |
for section in sections: | |
panels = soup.find_all('td', {"id": section}) | |
html += '\n <td style="color:rgb(0,0,0); text-align:left; vertical-align:top;">\n' | |
for panel in panels: | |
items = panel.find_all('a') | |
for item in items: | |
html += ' <div style="margin-top:11px; margin-bottom:11px; text-align:left; vertical-align:top;">\n <b style="text-align:left; vertical-align:top;">' + item.get_text(strip=True) + '</b><br style="text-align:left; vertical-align:top;"/>\n' | |
html += " " | |
html += " ".join(item.get('rel')) + "\n </div>\n" | |
html += ' </td>' | |
print(html_start + html + html_end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment