Esempio n. 1
0
def story_meta(filename, path):
  print "story_meta"
  notebook_name = path.split("/")[-1][:-9]
  dom = parse(path+"/"+filename)
  resource = dom.getElementsByTagName("resource")[0]
  story_title = resource.getElementsByTagName("dc:title")[0].firstChild.nodeValue
  raw_contrib = [x.firstChild.nodeValue
      for x in resource.getElementsByTagName("dcterms:contributor") ]
  contrib = json.dumps(raw_contrib)
  required = resource.getElementsByTagName("dcterms:requires")
  pages = len(required)
  try:
    date = resource.getElementsByTagName("dcterms:created")[0].firstChild.nodeValue
  except AttributeError:
    date = ""
  try:
    description = resource.getElementsByTagName("dc:description")[0].firstChild.nodeValue
  except AttributeError:
    description = ""
  try:
    comments = resource.getElementsByTagName("bl:comments")[0].firstChild.nodeValue
  except AttributeError:
    comments = ""
  raw_subject = [sub.firstChild.nodeValue for sub in resource.getElementsByTagName("dc:subject")]
  subject = json.dumps(raw_subject)
  raw_keywords = []
  try:
    temp = dom.getElementsByTagName("bl:keywords")[0]
    for word in temp.getElementsByTagName("bl:keyword"):
	k = word.getElementsByTagName("bl:kw")[0].firstChild.nodeValue
	subkw = word.getElementsByTagName("bl:subkeywords")[0]
	v = ", ".join(sub.firstChild.nodeValue
		for sub in subkw.getElementsByTagName("bl:subkw"))
	raw_keywords.append((k, v))
  except AttributeError:
    pass
  keyword = json.dumps(raw_keywords)
  notebook = Notebook.objects.get(short_title=notebook_name)
  
  story = Story(notebook=notebook, title=story_title, created=date, description=description, 
		comment=comments, contributor=contrib, subject=subject, keyword=keyword, pages=pages )
  story.save()
  i=1
  for page in required:
    page_path = page.firstChild.nodeValue
    page_uuid = uuid.uuid4()
    page_entry = Page(story = story, filename = page_path, uuid = page_uuid,number=i)
    i+=1
    page_entry.save()
def create_story(request):
    if request.method == 'GET':
        story_name = request.GET.get('story_name')
        description = request.GET.get('description')
        if story_name and description:
            story = Story()
            story.story_name = story_name
            story.description = description
            story.author = request.user
            story.save()
            story_id = Story.objects.all().values('id').order_by(
                'id').last()['id']
            return redirect('story_card',
                            story_name=story_name,
                            description=description,
                            story_id=story_id)
Esempio n. 3
0
    line = story[i]
    if line[0] != tab or i == len(story) - 1:
        if i == len(story) - 1: i += 1  #this is to get the last line in
        countForPrompts += 1
        if (countForPrompts - 1) % 3 == 0 and countForPrompts != 1:
            promptTexts.append(story[previousPromptIndex:i])
            previousPromptIndex = i

#print(promptTexts)

#first parse the first chunk
prompt, oldOptions = parsePrompt(promptTexts[0])

#then create a Story
story = Story(firstPrompt=prompt, vars=csvVars, name=storyName)
story.save()

for promptText in promptTexts[1:]:
    prompt, newOptions = parsePrompt(promptText)
    for option in oldOptions:
        option.nextPrompt = prompt
        option.save()
    oldOptions = newOptions
"""words to use:
tab = \t
vars = pet, food, drink
你好, I want to 买 a pet, but I won't have much time or 钱 to take care of it. Can you help me?
	1. 买狗!
	Hmmm, a 狗?Okay..
	pet := 狗
	2. 买猫!