-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredbrick-cement.py
98 lines (82 loc) · 3.12 KB
/
redbrick-cement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import sys
import random
class Mixer(object):
def __init__(self, title, date, username, banner, filename):
self.title = title
self.date = date
self.author = username
self.banner = banner
self.filename = filename
self.tags = []
def make_brick(self):
#Main run function
print("Making a brick")
cement = self.cement()
concrete = self.mixer(cement)
self.mould(concrete)
print(Mixer.special_brick_effects())
def cement(self):
#Usually I copy and paste the newsletter into a txt document (self.filename)
#Reads self.filename
print("Loading up the cement...")
raw = self.read_file()
return raw
def mixer(self, raw):
#mixes and matches and formats everything nicely
print("Putting the cement in the mixer...")
output = []
tnext = 1
last_was_tldr = False
for line in raw:
if tnext == 2:
self.tags.append(" - "+line)
line = "## "+line
output.append(line)
tnext = 0
continue
if line.count("-") > 3:
line = ""
tnext +=1
output.append(line)
continue
if line.count("- ") == 1:
last_was_tldr = True
if last_was_tldr and line.count("- ") != 1:
output.append("\n<!-- more -->\n\n\n")
last_was_tldr = False
else:
output.append(line)
return output
def mould(self, output, file_out="result.md"):
#Outputs the mix as MD
print("Putting the concrete in the mould...")
with open(file_out, "w") as file:
file.write("---\n")
file.write("title: '"+self.title+"'\n")
file.write("date: '"+self.date+"'\n")
file.write("banner: "+self.banner+"\n")
file.write("author: "+self.author+"\n")
file.write("tags:"+"\n"+"".join(self.tags))
file.write("---\n")
file.write("".join(output))
def read_file(self):
#Simple readfile
with open(self.filename, "r") as fname:
return fname.readlines()
@staticmethod
def special_brick_effects():
a = ["Wow is that Brick yours?", "Look at the brick, ain't it purdyy!", "Who's a nice little brick? You are!",
"Woah making bricks has never been this fun!", "Imagine how faster this would be if this automated with the newsletter!",
"I wonder what would happen if we added some herbs?", "WHAT ARE THOSSEEEEEEE? THEY are my bricks", "...And they were bricks? MAH GOD THEY WERE BRICKS!" ]
return random.choice(a)
def main():
title = input("Title Please: ")
date = input("Date Please: ")
author = input("Username Please: ")
banner = input("Banner Please: ")
filename = input("Filename Please: ")
print("\n\n\n")
brick = Mixer(title, date, author, banner, filename)
brick.make_brick()
if __name__ == '__main__':
main()