annotate results/CC-MAIN-2019-35/warc_lmhx/mcdb/idx/tcb.py @ 332:83450325421f trim

not working yet
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sat, 28 Feb 2026 14:48:32 +0000
parents
children 282a35927943
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
332
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
1 import sys,os
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
2
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
3 def init():
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
4 global i, year, count, cur_status, years, nyears, res_dir, ff
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
5
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
6 i = 0
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
7 year = 1995
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
8 count = 0
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
9 cur_status = 0
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
10
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
11 with open("%s/results/CC-MAIN-2019-35/warc_lmhx/years.txt"%os.getenv("HOME"),"r") \
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
12 as yf:
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
13 years=[int(l) for l in yf]
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
14
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
15 nyears = len(years)
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16 ff = [None] * (nyears + 1)
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
17 res_dir = sys.argv.pop(1)
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
18 ff[nyears] = open("%s/oob"%res_dir,"bw")
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
19
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
20 def finish():
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
21 global ff, i, count, cur_status
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
22 ff[i].write(b'%d\t%d\n'%(count, cur_status))
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
23
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
24 def cbf(status,lastmod):
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
25 global cur_status, count, i, year, nyears
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
26 stat = int(status)
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
27 lm = int(lastmod)
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
28 print(i, year, cur_status, count, stat, lm, file = sys.stderr)
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
29 while (not year == 0) and (lm > years[i]):
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
30 # change of year
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
31 if count != 0:
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
32 ff[i].write(b'%s\t%d\n'%(count, cur_status))
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
33 if i < nyears:
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
34 i += 1
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
35 year += 1
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
36 count = 0
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
37 cur_status = 0
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
38 if i == nyears:
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
39 year = 0
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
40 break
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
41 if not ff[i]:
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
42 ff[i] = open("%s/%s"%(res_dir, year),"bw")
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
43 if stat == cur_status:
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
44 count += 1
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
45 else:
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
46 ff[i].write(b'%d\t%d\n'%(count, cur_status))
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
47 cur_status = stat
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
48 count = 1
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
49
83450325421f not working yet
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
50