Ejemplo n.º 1
0
def createResource(entry):
  resource = Resource()
  resource.title = entry.custom["title"].text
  resource.created_at = datetime.datetime.strptime(entry.custom["timestamp"].text, "%m/%d/%Y %H:%M:%S")
  resource.abstract = entry.custom["abstract"].text
  resource.media_type = entry.custom["mediatype"].text
  resource.added_by = entry.custom["enteredby"].text
  resource.url = entry.custom["link"].text

  try:
    resource.length = entry.custom["length"].text
  except TypeError:
    print "This resource has no length."
    
  try:
    resource.save()
  except MySQLdb.Warning:
    print "Error saving resource.", sys.exc_info()[0]
    return
  
  topics = entry.custom["topictypes"].text.split(",")
  for topic_string in topics:
    topic_string = topic_string.strip()
    try:
      topic = Topic.objects.get(topic=topic_string)
    except ObjectDoesNotExist:
      topic = Topic(topic = topic_string)
      topic.save()
      
    resource.topics.add(topic)
Ejemplo n.º 2
0
def run():
    with open('subtopics.txt') as f:
        while True:
            line = f.readline().strip()
            title, description, parent = line.split('===')

            print parent
            day = Topic.objects.get(slug=parent).day

            subtopic = Topic(title=title, description=description, day=day,
                             slug=slugify(unicode(title)), status='published'
                             )
            print subtopic
            subtopic.save()
Ejemplo n.º 3
0
def run():
    with open('subtopics.txt') as f:
        while True:
            line = f.readline().strip()
            title, description, parent = line.split('===')

            print parent
            day = Topic.objects.get(slug=parent).day

            subtopic = Topic(title=title,
                             description=description,
                             day=day,
                             slug=slugify(unicode(title)),
                             status='published')
            print subtopic
            subtopic.save()