-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththoughts.py
More file actions
executable file
·84 lines (80 loc) · 2.58 KB
/
thoughts.py
File metadata and controls
executable file
·84 lines (80 loc) · 2.58 KB
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
import os
import datetime
from subprocess import call
directory = r"/home/jonny/oldfiles/Documents/code/personalsite/thoughts/"
html_dir = r"/home/jonny/oldfiles/Documents/code/personalsite/thtml/"
files = os.listdir(directory)
readable_date = str(datetime.date.today())
for file in files:
thought = open(directory+ file,"r")
contents = thought.read().replace("\n", "<br>")
name = thought.name
name = name[name.rfind("/")+1:]
name = name.split(".txt")[0]
print name
print "______________________________"
thought.close()
#create a thought html
print directory+name
thtml = open(html_dir+name+".html", "w")
thtml.write("""<doctype !html>
<html>
<head>
<meta charset="utf-8">
<title> Thoughts Jonathan Pedoeem</title>
<link rel="stylesheet" href="../css/bootstrap.css" type="text/css">
<link rel="stylesheet" href="../css/styles.css" type="text/css">
</head>
<body class= "flexCenter">
<div class = "container" style="width:50%">
<h1>{0}</h1>
<small>{1}</small>
<hr>
<p>{2}</p>
</div>
</body>
</html>
""".format(name,readable_date, contents))
thtml.close()
#delete the thought file
os.remove(directory+ file)
#create master thought.html
html_files = os.listdir(html_dir)
article_list = []
html_list = "<ul>"
html_files.remove("Welcome.html")
for hf in html_files:
article_list.append(("<li><a href='./thtml/{0}'>{1}</a></li>".format(hf, hf[:hf.find('.')]),os.path.getmtime(html_dir+"/"+hf)))
article_list = sorted(article_list, key= lambda s:s[1], reverse=True)
print article_list
print "______________"
for s in article_list:
html_list+=s[0]
html_list+= "<li><a href='./thtml/Welcome.html'>Welcome</a></li></ul>"
thought_html = """<doctype !html>
<html>
<head>
<meta charset="utf-8">
<title> Thoughts Jonathan Pedoeem</title>
<link rel="stylesheet" href="./css/bootstrap.css" type="text/css">
<link rel="stylesheet" href="./css/styles.css" type="text/css">
</head>
<body>
<div class = "container">
<div id = "list">
<h5><a href="/">Home</a></h5>
<h3>Some of My Thoughts</h3>
<small>I'm sorry I can't spell.</small>
<br>
{0}
</div>
</div>
</body>
</html>
""".format(html_list)
thought_file = open("/home/jonny/oldfiles/Documents/code/personalsite/thoughts.html", "w")
thought_file.write(thought_html)
thought_file.close()
call("git add --all", shell=True )
call("git commit -m 'added new essay {0}'".format(readable_date), shell=True)
call('git push', shell=True)