File: apply_css.py

package info (click to toggle)
cantor 4%3A25.04.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,828 kB
  • sloc: cpp: 43,775; ansic: 5,802; pascal: 1,027; python: 642; xml: 457; sh: 308; makefile: 207; lisp: 91
file content (14 lines) | stat: -rw-r--r-- 441 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import os
from bs4 import BeautifulSoup

css_link = BeautifulSoup('<link rel="stylesheet" type="text/css" href="main.css">', 'html.parser')

for filename in os.listdir('.'):
    if filename.endswith('.html'):
        with open(filename, 'r+') as f:
            soup = BeautifulSoup(f, 'html.parser')
            head = soup.head
            head.append(css_link)
            f.seek(0)
            f.write(str(soup))
            f.truncate()