Example #1
0
    def handle(self, *args, **options):
        if not args:
            raise CommandError('Please specify a json file.')

        fn = args[0]

        fn = os.path.abspath(fn)
        if not os.path.exists(fn):
            raise CommandError('"%s" does not exist' % fn)

        f = open(fn, 'r')
        data = json.loads(f.read())
        f.close()
        create_videos(data)
Example #2
0
    def test_create_one_video(self):
        cat = category(name=u"foo", slug=u"foo")
        cat.save()

        vid = {"state": 1, "title": u"foo", "summary": u"foo", "source_url": u"http://example.com/", "category": cat.id}
        ret = create_videos([vid])

        eq_(ret[0].title, vid["title"])
Example #3
0
    def test_video_with_speakers(self):
        cat = category(name=u"foo", slug=u"foo")
        cat.save()

        speaker_names = [u"Carl Karsten", u"Ryan Verner"]
        vid = {
            "state": 1,
            "title": u"foo",
            "summary": u"foo",
            "source_url": u"http://example.com/",
            "category": cat.id,
            "speakers": speaker_names,
        }
        ret = create_videos([vid])

        eq_(ret[0].title, vid["title"])
        speakers = ret[0].speakers.all()
        assert speakers[0].name in speaker_names
        assert speakers[1].name in speaker_names
        assert speakers[0].name != speakers[1].name
Example #4
0
    def test_video_with_tags(self):
        cat = category(name=u"foo", slug=u"foo")
        cat.save()

        t1 = tag(tag=u"tag1")
        t1.save()
        tag_names = [t1.tag, u"tag2"]
        vid = {
            "state": 1,
            "title": u"foo",
            "summary": u"foo",
            "source_url": u"http://example.com/",
            "category": cat.id,
            "tags": tag_names,
        }
        ret = create_videos([vid])

        eq_(ret[0].title, vid["title"])
        tags = ret[0].tags.order_by("tag")
        eq_(tags[0].tag, t1.tag)
        eq_(tags[0].id, t1.id)
        eq_(tags[1].tag, tag_names[1])
Example #5
0
def import_video(data):
    print 'Working on %s...' % data['name']
    new_data = {
        'state': 1,  # live
        'category': 17,
        'title': data['name'],
        'summary': '<p>%s</p>' % data['description'],
        'source_url': data['host_url'],
        'copyright_text': data['license'],
        'speakers': data['authors'].split(','),
        'recorded': datetime.datetime.strptime(data['start'],
                                               '%Y-%m-%d %H:%M:%S'),
        'added': datetime.datetime.now()
        }

    new_data.update(get_data_from_youtube(data['host_url']))

    try:
        return create_videos([new_data])
    except Exception, e:
        print "".join(traceback.format_exc())
        print "Probably a new source_url: %s" % data['host_url']
        print ""
Example #6
0
    def test_with_existing_speaker(self):
        carl = speaker(name=u"Carl Karsten")
        carl.save()
        speaker_names = [carl.name, u"Phil"]

        cat = category(name=u"foo", slug=u"foo")
        cat.save()

        vid = {
            "state": 1,
            "title": u"foo",
            "summary": u"foo",
            "source_url": u"http://example.com/",
            "category": cat.id,
            "speakers": speaker_names,
        }
        ret = create_videos([vid])

        eq_(ret[0].title, vid["title"])
        speakers = ret[0].speakers.order_by("name")[:]
        eq_(speakers[0].name, carl.name)
        eq_(speakers[0].id, carl.id)
        eq_(speakers[1].name, speaker_names[1])
Example #7
0
def import_video(data):
    print 'Working on %s...' % data['name']
    new_data = {
        'state': 1,  # live
        'category': 17,
        'title': data['name'],
        'summary': '<p>%s</p>' % data['description'],
        'source_url': data['host_url'],
        'copyright_text': data['license'],
        'speakers': data['authors'].split(','),
        'recorded': datetime.datetime.strptime(data['start'],
                                               '%Y-%m-%d %H:%M:%S'),
        'added': datetime.datetime.now()
    }

    new_data.update(get_data_from_youtube(data['host_url']))

    try:
        return create_videos([new_data])
    except Exception, e:
        print "".join(traceback.format_exc())
        print "Probably a new source_url: %s" % data['host_url']
        print ""
Example #8
0
 def test_create_no_videos(self):
     # Return an empty list if there's nothing to do
     eq_(create_videos([]), [])