annotate import_japanese_personas.py @ 197:6fe9a1deb1e7 default tip

Changed the cache middleware to cache stuff for 24 hours.
author avarma@sm-labs01.mozilla.org
date Mon, 16 Jun 2008 10:32:58 -0700
parents 9bcc77e37c19
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
115
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
1 # Imports the personas from personas_all.dat and
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
2 # personas_categories.dat (the contents of which are contained in this
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
3 # file as constants) into the database.
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
4
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
5 import os
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
6
128
9bcc77e37c19 Renamed all references of PersonasBackend to personasbackend, matching PEP-8.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
7 os.environ["DJANGO_SETTINGS_MODULE"] = "personasbackend.settings"
115
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
8
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
9 from django.utils import simplejson
128
9bcc77e37c19 Renamed all references of PersonasBackend to personasbackend, matching PEP-8.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
10 from personasbackend.personas import models
115
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
11
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
12 def makeCategory( name ):
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
13 return models.Category( name = name )
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
14
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
15 def makePersona( name, category, text_color, json_id ):
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
16 url = "http://personas-view/legacy-cbeard-persona?name=%s" % json_id
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
17 return models.Persona(
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
18 name = name,
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
19 category = category,
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
20 text_color = text_color,
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
21 description = "&nbsp;",
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
22 url = url,
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
23 status = "published"
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
24 )
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
25
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
26 personas_categories_dat = """
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
27 { "categories": [
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
28 {"label": "Japan Rock Festival 2007", "id" : "personas-mozilla24-menu", "type" : "list", "parent" : "personas-category-menu"}
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
29 ]
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
30 }
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
31 """
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
32
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
33 personas_all_dat = """
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
34 { "personas": [
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
35 {"label": "101A", "id" : "101a", "menu" : "personas-mozilla24-menu", "dark" : "true" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
36 {"label": "AJI", "id" : "aji", "menu" : "personas-mozilla24-menu", "dark" : "false" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
37 {"label": "TAIZO JINNOUCHI", "id" : "jinnouchi", "menu" : "personas-mozilla24-menu", "dark" : "true" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
38 {"label": "KOKUSYOKU SUMIRE", "id" : "kokushoku", "menu" : "personas-mozilla24-menu", "dark" : "true" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
39 {"label": "marron", "id" : "marron", "menu" : "personas-mozilla24-menu", "dark" : "true" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
40 {"label": "MARS EURYTHMICS", "id" : "mars", "menu" : "personas-mozilla24-menu", "dark" : "true" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
41 {"label": "MIDORI", "id" : "midori", "menu" : "personas-mozilla24-menu", "dark" : "false" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
42 {"label": "O-NO KIYOFUMI", "id" : "ohno", "menu" : "personas-mozilla24-menu", "dark" : "false" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
43 {"label": "Qomolangma Tomato", "id" : "qomo", "menu" : "personas-mozilla24-menu", "dark" : "false" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
44 {"label": "Shonen Knife", "id" : "shonen", "menu" : "personas-mozilla24-menu", "dark" : "false" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
45 {"label": "SLUGGER", "id" : "slugger", "menu" : "personas-mozilla24-menu", "dark" : "true" },
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
46 {"label": "TsuShiMaMiRe", "id" : "tsushimamire", "menu" : "personas-mozilla24-menu", "dark" : "false" }
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
47 ]
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
48 }
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
49
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
50 """
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
51
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
52 if __name__ == "__main__":
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
53 personas = simplejson.loads( personas_all_dat )
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
54 personas = personas["personas"]
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
55
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
56 categories = simplejson.loads( personas_categories_dat )
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
57 categories = categories["categories"]
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
58
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
59 json_cats = {}
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
60
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
61 for category in categories:
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
62 if category["parent"] == "personas-category-menu":
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
63 cat = makeCategory(
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
64 name = category["label"],
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
65 )
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
66 print "Saving category %s" % cat.name
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
67 cat.save()
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
68 json_cats[category["id"]] = cat
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
69
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
70 for persona in personas:
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
71 menu = persona["menu"].split( "," )[0]
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
72 if persona.get( "dark", "false" ) == "true":
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
73 text_color = "#FFFFFF"
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
74 else:
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
75 text_color = "#000000"
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
76 persona = makePersona(
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
77 name = persona["label"],
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
78 category = json_cats[menu],
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
79 text_color = text_color,
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
80 json_id = persona["id"],
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
81 )
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
82 print "Saving persona %s" % persona.name
a1e344b3c064 Added a script to import japanese personas, and modified a view to allow the japanese personas to be viewed.
avarma@sm-labs01.mozilla.org
parents:
diff changeset
83 persona.save()