homepage.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ########## begin config ##########
  4. output = 'homepage.html' # output file
  5. title = 'Speed Dial' # page title
  6. font = ('Monospace', '14px') # font
  7. separator = '>' # separator between group title and links
  8. colors = (
  9. '#020202', # background
  10. '#999999', # links
  11. '#00ff00', # group title
  12. '#4C4C4C', # separator
  13. )
  14. # add your links here
  15. links = {
  16. 'Google': [
  17. ['Google', 'https://www.google.co.uk/'],
  18. ['Youtube', 'http://www.youtube.com/'],
  19. ['GMail', 'https://mail.google.com/mail/u/0/?shva=1#inbox/'],
  20. ],
  21. 'Social': [
  22. ['FaceBook', 'http://www.facebook.com'],
  23. ['Twitter', 'https://twitter.com/'],
  24. ['Hotmail', 'www.hotmail.co.uk/'],
  25. ],
  26. 'Wiki': [
  27. ['Wiki', 'www.wikipedia.org/'],
  28. ['ArchWiki', 'https://wiki.archlinux.org/'],
  29. ['RSWiki', 'http://runescape.wikia.com/wiki/RuneScape_Wiki'],
  30. ],
  31. 'Shopping': [
  32. ['Amazon', 'http://www.amazon.co.uk'],
  33. ['eBay', 'www.ebay.co.uk/'],
  34. ],
  35. 'Games': [
  36. ['RuneScape', 'http://www.runescape.com'],
  37. ['Ryzom', 'http://www.ryzom.com/en/'],
  38. ['Steam', 'http://store.steampowered.com/'],
  39. ],
  40. }
  41. ########## end config ##########
  42. import os
  43. css = '''body {
  44. background-color: %s;
  45. font-family: "%s";
  46. font-size: %s;
  47. font-weight: normal;
  48. margin-left: 7%%;
  49. }
  50. a:link,a:visited,a:active {
  51. text-decoration: none;
  52. color: %s;
  53. font-weight: normal;
  54. }
  55. a:hover {
  56. text-decoration: underline;
  57. color: %s;
  58. font-weight: normal;
  59. }
  60. table {
  61. border-spacing: 8px;
  62. }
  63. td:first-child {
  64. font-weight: bold;
  65. color: %s
  66. }
  67. td:nth-child(2) {
  68. font-weight: normal;
  69. color: %s;
  70. }''' % (colors[0], font[0], font[1], colors[1], colors[1], colors[2], colors[3])
  71. links_html = ''
  72. for group in sorted(links):
  73. links_html += '<tr><td align="right">%s</td><td>%s</td><td>' % (group, separator)
  74. for site in sorted(links[group]):
  75. links_html += '<a href="%s">%s</a> ' % (site[1], site[0])
  76. links_html += '</td></tr>'
  77. html = '''<html>
  78. <head>
  79. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  80. <title>%s</title>
  81. <link rel="stylesheet" type="text/css" href="style.css" />
  82. </head>
  83. <body>
  84. <table valign="middle" border="0" width="100%%" height="100%%"><tr><td><table>
  85. %s
  86. </table></td></tr></table>
  87. </body>
  88. </html>''' % (title, links_html)
  89. with open(output, 'w') as file:
  90. file.write(html)
  91. with open('style.css', 'w') as file:
  92. file.write(css)
  93. os.system('tidy -utf8 -i -m -q -asxhtml %s' % output)