54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
import os, sys
|
|
import tempfile
|
|
import glob
|
|
|
|
class PyBLG:
|
|
'''
|
|
The main class for the PyBLG project.
|
|
Written by virtual <stack@cocaine.ninja>
|
|
Under MIT License
|
|
'''
|
|
|
|
@staticmethod
|
|
def banner():
|
|
print("""
|
|
PyBLG v1.0a by virtual
|
|
|
|
Please select an option:
|
|
|
|
w) write a blog post
|
|
h) htmlify a post
|
|
d) delete a post
|
|
e) exit pyblg
|
|
""")
|
|
|
|
@staticmethod
|
|
def select(choice):
|
|
# w - write file
|
|
if choice.lower() == 'w':
|
|
fname = input("Please insert a name for the post: ")
|
|
temp = tempfile.NamedTemporaryFile(prefix="pyblgtmp-", delete=False)
|
|
os.system('%s %s' % (os.environ['EDITOR'], temp.name))
|
|
bb = str(temp.read().rstrip())
|
|
temp.close()
|
|
|
|
elif choice.lower() == 'h':
|
|
print("HTMLifier by virtual for PyBLG (WIP)")
|
|
print("Found the following tempfiles for PyBLG: ")
|
|
g = glob.glob('/tmp/pyblgtmp-*')
|
|
print(", ".join(g))
|
|
f = input("Please choose a file: ")
|
|
if int(f) < len(g):
|
|
with open(g[int(f)], "w+") as t:
|
|
data = t.read().rstrip()
|
|
t.close()
|
|
template = "<html><head><title>My Blog</title></head><body><p>%s</p></body></html>" % data
|
|
with open("%s/pyblg.html", "w+") as r:
|
|
r.write(template)
|
|
r.close()
|
|
print("wrote data")
|
|
|
|
if __name__ == '__main__':
|
|
PyBLG.banner()
|
|
PyBLG.select(input('Select: '))
|