Advertisement
ad2bg

html-contents.py

Jul 24th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. title = '~'
  2. elements = ''
  3.  
  4. while True:
  5.     line = input()
  6.     if line == 'exit':
  7.         break
  8.  
  9.     tag, content = line.split(' ')
  10.  
  11.     element = f'\t<{tag}>{content}</{tag}>\n'
  12.  
  13.     if tag == 'title':
  14.         title = content
  15.     else:
  16.         elements += element
  17.  
  18. title = '' if title == '~' else f' \t<title>{title}</title>\n'
  19.  
  20. with open('index.html', 'w') as w_file:
  21.     w_file.write(
  22.         f"""<!DOCTYPE html>
  23. <html>
  24. <head>
  25. {title}</head>
  26. <body>
  27. {elements}</body>
  28. </html>""")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement