Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/buildactivity.py
blob: 7773708954c9f2b3ed00dbdae3d4c2782b2029dd (plain)
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
#!/usr/bin/env python
#create special activities.js for karma activities
from path import path
model1 = 'activities = [\n'
model2 = '[1,1,"xxx","Karma","yyy","Blue"],\n'
model3 = '[0,1,"milestone","milestone"],\n'
model4 = '];\n\n'
model5 = 'var assetList = {image: [\n'
model6 = '{name:"xxx", file:"yyy.png"},\n'
model7 = ']};\n\n'
model8 = 'var logos =[\n'
model9 = '"xxx",\n'
model10 = '];\n\n'  
milestones = ['content/English/enk2m1','content/English/enk6m1','content/Mathematics/mak2m1','content/Mathematics/mak6m1']

for milestone in milestones:
    #get list of folders
    activities = path(milestone).dirs()
    activities.sort()
    txtout = model1
    count = 0
    for activity in activities:
        a = str(activity.namebase)
        pos = a.find('_')
        pos1 = a[pos+1:].find('_')
        pos2 = a[pos+pos1+2:].find('_')
        nm = a[:pos+pos1+pos2+2]
        temp = model2.replace('xxx',nm)
        count += 1
        temp1 = temp.replace('1,1',str(count)+','+str(count))
        txtout = txtout + temp1.replace('yyy', str(activity.namebase))
    txtout = txtout + model3 + model4 + model5
    for activity in activities:
        a = str(activity.namebase)
        pos = a.find('_')
        pos1 = a[pos+1:].find('_')
        pos2 = a[pos+pos1+2:].find('_')
        nm = a[:pos+pos1+pos2+2]
        temp = model6.replace('xxx', nm)
        txtout = txtout + temp.replace('yyy',nm)
    txtout = txtout + model7 + model8
    # for each folder write a line based on model9
    for activity in activities:
        a = str(activity.namebase)
        pos = a.find('_')
        pos1 = a[pos+1:].find('_')
        pos2 = a[pos+pos1+2:].find('_')
        nm = a[:pos+pos1+pos2+2]
        txtout = txtout + model9.replace('xxx', nm)
    txtout = txtout + model10
    fout = open(path(milestone) / 'activities.js', 'w')
    fout.write(txtout)
    fout.close()