test.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import os
  2. from blogit.blogit import CONFIG
  3. CONFIG['content_root'] = 'test_root'
  4. tags = ['foo', 'bar', 'baz', 'bug', 'buf']
  5. shift = lambda l, n: l[-n:] + l[:-n]
  6. post = '''\
  7. ---
  8. title: Blog post {number}
  9. author: Famous author
  10. published: 2015-01-{number}
  11. tags: {tags}
  12. public: yes
  13. chronological: yes
  14. kind: writing
  15. summary: This is a summry of post {number}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus
  16. ---
  17. This is the body of post {number}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
  18. This is a snippet in bash
  19. ```bash
  20. $ for i in `seq 1 10`; do
  21. echo $i
  22. done
  23. VAR="variable"
  24. echo $VAR
  25. # This is a very long long long long long long long long long long comment
  26. ```
  27. This is a snippet in python
  28. ```python
  29. def yay(top):
  30. for i in range(1, top+1):
  31. yield i
  32. for i in yay:
  33. print(i)
  34. ```
  35. '''
  36. try:
  37. os.mkdir(CONFIG['content_root'])
  38. except OSError:
  39. pass
  40. shift_factors = map(lambda x: (x - 1) / 5 +1, range(1,21))
  41. def write_file(i):
  42. f = open((os.path.join(CONFIG['content_root'],
  43. 'post{}.md'.format(i))), 'w')
  44. f.write(post.format(**{'number': i,
  45. 'tags': shift(tags, shift_factors[i-1])[:-1]}))
  46. [write_file(i) for i in range(1, 21)]