CoCalc Shared Fileswww / sga / sga / annotation.pyOpen in CoCalc with one click!
Author: William A. Stein
1
#!/usr/bin/python
2
BASE="/home/was/www/sga/files/"
3
import os,time
4
5
DIR = ["1", "2", "3-1", "3-2", "3-3", "4-1","4-2","4-3","4.5","5","6","7-1","7-2"]
6
#DIR = ["5"]
7
8
TAG="<h2>Annotation</h2>"
9
10
def annotations(file):
11
s = open(file,"r").read()
12
i = s.find(TAG)
13
if i == -1:
14
return None
15
x = s[i+len(TAG):]
16
if len(x) > 6:
17
return x
18
return None
19
20
def all_annotations():
21
A = []
22
for dir in DIR:
23
for file in os.listdir(BASE+dir):
24
if file.find(".html") != -1:
25
name = "%s/%s/%s"%(BASE,dir,file)
26
a = annotations(name)
27
if a != None:
28
A.append(("%s/%s"%(dir,file), a))
29
return A
30
31
def full_list():
32
"""Open all files and list the annotations contained in them,
33
with links to the files."""
34
s='<html>\
35
<title>SGA</title>\
36
<link REL=STYLESHEET TYPE="text/css" HREF="sga.css" TITLE="index.html">\
37
<body><center>\
38
<h1><a href="index.html">SGA</a> Annotations</h1>\
39
<h2>by the community</h2>'
40
s = s+'If an annotation should be removed, <a href="mailto:[email protected]">send me an email</a>.<hr>'
41
s=s+ '<table bgcolor=black border=0 cellpadding=10 cellspacing=1>\n'
42
for name, ann in all_annotations():
43
s = s+ '<tr><td bgcolor=white><a href="%s">%s</a></td><td bgcolor=white width=650>%s</td></tr>\n'%(name,name,ann)
44
s =s+ '</table></center></body>'
45
return s
46
47
os.system("cp %s/annotations.html %s/old_annotations/%s.html"%\
48
(BASE,BASE,time.asctime().replace(" ","_")))
49
open("%s/annotations.html"%BASE,"w").write(full_list())
50