-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_rango.py
79 lines (61 loc) · 1.99 KB
/
populate_rango.py
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
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tango_with_django_project.settings')
import django
django.setup()
from rango.models import Category, Page
def populate():
python_cat = add_cat('Python', 128, 64)
add_page(cat=python_cat,
title="Official Python Tutorial",
url="http://docs.python.org/2/tutorial/",
views=15)
add_page(cat=python_cat,
title="How to Think like a Computer Scientist",
url="http://www.greenteapress.com/thinkpython/",
views=16)
add_page(cat=python_cat,
title="Learn Python in 10 Minutes",
url="http://www.korokithakis.net/tutorials/python/",
views=25)
django_cat = add_cat("Django", 64, 32)
add_page(cat=django_cat,
title="Official Django Tutorial",
url="https://docs.djangoproject.com/en/1.5/intro/tutorial01/",
views=30)
add_page(cat=django_cat,
title="Django Rocks",
url="http://www.djangorocks.com/",
views=9)
add_page(cat=django_cat,
title="How to Tango with Django",
url="http://www.tangowithdjango.com/",
views=48)
frame_cat = add_cat("Other Frameworks", 32, 16)
add_page(cat=frame_cat,
title="Bottle",
url="http://bottlepy.org/docs/dev/",
views=115)
add_page(cat=frame_cat,
title="Flask",
url="http://flask.pocoo.org",
views=19)
# Print out what we have added to the user.
for c in Category.objects.all():
for p in Page.objects.filter(category=c):
print "- {0} - {1}".format(str(c), str(p))
def add_page(cat, title, url, views):
p = Page.objects.get_or_create(category=cat, title=title)[0]
p.url=url
p.views=views
p.save()
return p
def add_cat(name, views, likes):
c = Category.objects.get_or_create(name=name)[0]
c.views=views
c.likes=likes
c.save()
return c
# Start execution here!
if __name__ == '__main__':
print "Starting Rango population script..."
populate()