Exemplo n.º 1
0
    def handle(self, *args, **options):

        rss_url = 'http://blog.djangogirls.org/rss'

        response = requests.get(rss_url)
        rss = ElementTree.fromstring(response.content)

        for post in rss.iter('item'):
            title = post.find('title').text
            if 'Your Django Story: Meet' in title:
                name = title.replace('Your Django Story: Meet ', '')
                is_story = True
            else:
                name = title
                is_story = False

            if not Story.objects.filter(name=name).exists():
                post_url = post.find('link').text
                post = pq(post.find('description').text)
                image_url = post('img').attr.src
                story = Story(name=name, post_url=post_url, content=post,
                              is_story=is_story)

                if image_url:
                    img = NamedTemporaryFile(delete=True)
                    img.write(urlopen(image_url).read())
                    img.flush()
                    story.image.save(image_url.split('/')[-1], File(img))

                story.save()

                if is_story:
                    print('Story of %s has been fetched' % name)
                else:
                    print('Blogpost "%s" has been fetched' % name)
Exemplo n.º 2
0
    def handle(self, *args, **options):

        rss_url = 'http://blog.djangogirls.org/rss'

        response = requests.get(rss_url)
        rss = ElementTree.fromstring(response.content)

        for post in rss.iter('item'):
            title = post.find('title').text
            if 'Your Django Story: Meet' in title:
                name = title.replace('Your Django Story: Meet ', '')
                is_story = True
            else:
                name = title
                is_story = False

            if not Story.objects.filter(name=name).exists():
                post_url = post.find('link').text
                post = pq(post.find('description').text)
                image_url = post('img').attr.src
                story = Story(name=name, post_url=post_url, content=post,
                              is_story=is_story)

                if image_url:
                    img = NamedTemporaryFile(delete=True)
                    img.write(urlopen(image_url).read())
                    img.flush()
                    story.image.save(image_url.split('/')[-1], File(img))

                story.save()

                if is_story:
                    print('Story of %s has been fetched' % name)
                else:
                    print('Blogpost "%s" has been fetched' % name)
Exemplo n.º 3
0
 def update(self, instance: Story, validated_data: dict) -> Story:
     instance.title = validated_data['title']
     instance.subtitle = validated_data['subtitle']
     instance.description = validated_data['description']
     instance.published_year = validated_data['published_year']
     instance.author_id = validated_data['author_id']
     instance.save()
     return instance
Exemplo n.º 4
0
def create(request, form_class=StoryForm, template_name="story/edit.html"):
    if request.method == "POST":
        story_form = form_class(request.user, request.POST, request.FILES)
        if story_form.is_valid():
            story = story_form.save(request.user)
            return HttpResponseRedirect(reverse("story_edit", args=(story.id,)))
        else:
            return HttpResponse(status=400, content="Title has to be specified")
    elif request.method == "GET":
        story = Story(creator=request.user)
        story.save()
        return HttpResponseRedirect(reverse("story_edit", args=(story.id,)))
        
    return HttpResponse(status=400, content="Only Post allowed")
def store_user(data):
    
    #
    # User
    #
    firstname = data['firstname']
    if not firstname:
        firstname = " "
    lastname = data['lastname']
    if not lastname:
        lastname = " "
    user = User(username=data['name'], first_name=firstname,
                last_name=lastname, email=data['email'], password="******"+data["pass"])
    user.save(force_insert=True)
    
    print "User: "******" "
        
    #profile = Profile(user=user,
    #                    first_name=firstname,
    #                    last_name=lastname,
    #                    city=city,
    #                    about=data['description'])
    #profile.save()
    #account = Account(user=user)
    #account.save()
    
    # avatar
    
    #
    # stories - do them first, since they are containers that we want to add items to
    #
    stories = get_stories(data["user_id"])
    for story in stories:
        print "-Story: "+str(story['story_id'])
        title = story['title']
        if not title:
            title = " "
            
        new_story = Story(title=title,
                          slug=slugify(title),
                      creator=user,
                      description=story['text'],
                      mapmode=convert_mapmode(story['mapmode']),
                      creation_date=convert_time(story['timestamp']),
                      update_date=convert_time(story['timestamp']),
                      privacy=get_privacy_of_old_privacy(story['right_view']),
                      status=get_status_of_old_privacy(story['right_view']))
        
        new_story.slug = make_unique(new_story, lambda x: Story.objects.filter(slug__exact=x.slug).count() == 0)
        
        new_story.save()
        migrated_post = MigratedItem(type="story", old_id=story["story_id"],
                                 new_id=new_story.pk)
        migrated_post.save()
        
        store_tags_of_item(new_story, story['story_id'])
        
        set_hit_count(new_story, story['view_count'])
    
    
    
    
    # lines
    lines = get_lines(data["user_id"])
    if lines:
        for line in lines:
            print "-Line: "+str(line['line_id'])
            linestring = make_linestring_of_string(line["controlpoints"], line["start_marker_id"], line["end_marker_id"])
            if linestring:
                line_post = get_post_of_line(line['line_id'])
                if not line_post:
                    title = " "
                    description = " "
                else:
                    if line_post['title']:
                        title = line_post['title']
                    else:
                        title = " "
                    
                    if line_post['text']:
                        description = line_post['text']
                    else:
                        description = " "
                    
                new_line = GeoLineTag(creator=user,
                                title=title,
                                description=description,
                                line=linestring,
                                )
                
                # add to story
                line_w_story = get_story_of_line(line['line_id'])
                if line_w_story and line_w_story['story_id']:
                    try:
                        new_story = Story.objects.get(pk=get_new_id("story",line_w_story['story_id']))
                        print "Adding line %s (%s) to story %s (%s)"%(line['line_id'], new_line.id, line_w_story['story_id'], new_story.id)
                        new_line.content_object = new_story
                    except:
                        print "Could not add Story"
                    
                new_line.save()
                migrated_line = MigratedItem(type="line", old_id=line["line_id"],
                                         new_id=new_line.pk)
                migrated_line.save()
            
                
    
    
    # video
    videos = get_videos(data["user_id"])
    for video in videos:
        print "-Video: "+str(video['video_id'])
        if video['medialocation']:
            import re
            video_id = re.findall(r"/v/(.+)", video['medialocation'])[0]
            import_url = "http://www.youtube.com/watch?v="+video_id
            comment = video['text']
            if not comment:
                comment = " "
                
            new_video = Video(creator=user,
                            title=video['title'],
                            comment=comment,
                            was_uploaded=False,
                            import_url=import_url,
                            thumbnail_url=video['thumb1'],
                            safetylevel=get_privacy_of_old_privacy(video['right_view']),
                            last_modified=convert_time(video['timestamp']),
                            date_added=convert_time(video['timestamp']),
                            )
            new_video.save()
            migrated_video = MigratedItem(type="video", old_id=video["video_id"],
                                     new_id=new_video.pk)
            migrated_video.save()
            
            # add to story
            if video["story_id"]:
                story = Story.objects.get(pk=get_new_id("story", video["story_id"]))
                
                count = StoryLineItem.objects.filter(creator=user, story=story, timestamp_start__lte=convert_time(video['timestamp'])).count()
                print "Adding video %s (%s) to story %s (%s) at position: %s "%(video['video_id'], new_video.id, video["story_id"], story.id, count)
                
                text = video['text']
                if not text:
                    text = " "
                    
                story_line_item = StoryLineItem(creator=user, story=story, text=text,
                                         timestamp_start=convert_time(video['timestamp']), timestamp_end=convert_time(video['timestamp']))
                story_line_item.save()
                story_line_item_media = StoryLineItemMedia(storylineitem=story_line_item, content_object=new_video)
                story_line_item_media.save()
                
                # geotag
                if video['mapobject_id']:
                    geotag_item(video["video_id"], story_line_item, user)
            
            if video['mapobject_id']:
                geotag_item(video["video_id"], new_video, user)
        
            store_tags_of_item(new_video, video["video_id"])
            set_hit_count(new_video, video['view_count'])
            
    # posts
    posts = get_posts(data["user_id"])
    for post in posts:
        print "-Post: "+str(post['post_id'])
        if post['story_id']:
            post_text = post['text']
            if not post_text:
                post_text = " "
            
            try:
                post_story = Story.objects.get(pk=get_new_id("story", post['story_id']))
                count = StoryLineItem.objects.filter(creator=user, story=story, timestamp_start__lte=convert_time(post['timestamp'])).count()
                print "Adding post %s to story %s (%s) at position: %s "%(post['post_id'], post["story_id"], post_story.id, count)
                new_post = StoryLineItem(creator=user, story=post_story, text=post_text,
                                         timestamp_start=convert_time(post['timestamp']),
                                         timestamp_end=convert_time(post['timestamp']))
                new_post.save()
                migrated_post = MigratedItem(type="post", old_id=post["post_id"],
                                         new_id=new_post.pk)
                migrated_post.save()
            
                if post['mapobject_id']:
                    geotag_item(post["post_id"], new_post, user)
                    
                store_tags_of_item(new_post, post["post_id"])
                set_hit_count(new_post, post['view_count'])
            except:
                print "Could not add to Story"
    
    
    # images
    images = get_images(data["user_id"])
    if images:
        for image in images:
            print "-Image: "+str(image['image_id'])
            caption = image['text']
            if not caption:
                caption = " "
            
            title = image['title']
            if not title:
                title = " "
                
            new_image = Image(member=user,
                            title=title,
                            caption=caption,
                            date_added=convert_time(image['timestamp']),
                            )
            
            
            try:
                new_image.image.save(os.path.basename(image["filename"]+".jpg"), ContentFile(open(path_to_images+image["filename"]+".jpg", "r").read()))
                migrated_image = MigratedItem(type="image", old_id=image["image_id"],
                                         new_id=new_image.pk)
                new_image.save()
                migrated_image.save()
                
                if image["story_id"]:
                    story = Story.objects.get(pk=get_new_id("story", image["story_id"]))
                    count = StoryLineItem.objects.filter(creator=user, story=story, timestamp_start__lte=convert_time(image['timestamp'])).count()
                    print "Adding image %s (%s) to story %s (%s) at position: %s "%(image['image_id'], new_image.id, image["story_id"], story.id, count)
                    story_line_item = StoryLineItem(creator=user, story=story, text=caption,
                                             position=count,
                                             timestamp_start=convert_time(image['timestamp']),
                                             timestamp_end=convert_time(image['timestamp']))
                    story_line_item.save()
                    story_line_item_media = StoryLineItemMedia(storylineitem=story_line_item, content_object=new_image)
                    story_line_item_media.save()
                    
                    if image['mapobject_id']:
                        geotag_item(image['image_id'], story_line_item, user)
            
                if image['mapobject_id']:
                    geotag_item(image['image_id'], new_image, user)
                    
                store_tags_of_item(new_image, image["image_id"])
                set_hit_count(new_image, image['view_count'])
            except:
                print "Could not store image: %s filename: %s"%(image['image_id'], image['filename'])
                
    # story image
    
    
    # store user
    migrated_user = MigratedItem(type="user", old_id=data["user_id"],
                                 new_id=user.pk)
    migrated_user.save()
    make_avatar(data)
    
    # flickr images
    # TODO:
    
Exemplo n.º 6
0
    content=
    "It's the biggest dance of the year and Nikki Maxwell is hoping her crush, Brandon, wants to be her date. But time is running out. What if he doesn't want to go with her? Or worse - what if he ends up going with Mackenzie?!! In the sixth book in the blockbuster Dork Diaries series-now with more than 13 million copies in print-join Nikki, Chloe and Zoey as they tackle the topic of love, Dork Diaries style! Rachel Ren\u00e9e Russell grew up in Saint Joseph, Michigan. She was born on December 11, 1965. She is an attorney who also writes children's books. She writes and illustrates the Dork Diaries series. Rachel wrote her first book in 6th grade as a birthday present for her younger twin brothers. Dork Diaries dramatically chronicles the daily life of the main character, Nikki Maxwell, as she struggles to fit in and survive middle school. The book series is written in a diary format and includes doodles, drawings and comic strips. According to the author's website, the Dork Diaries books are based on Rachel Renee Russell's experiences in middle school, as well as those of her two daughters, Erin and Nikki. Her older daughter, Erin, helps with writing and her younger daughter, Nikki, helps with illustrations. The main character, Nikki Maxwell, is named after her daughter. Currently, there are over 10 million copies of the Dork Diaries books in print in the United States. Publishing rights have been sold in 36 countries with translation into 32 different languages. Dork Diaries was awarded the 2010 Children's Choice Book of the Year Award for the 5th/6th grade division. She made The New York Times Best Seller List iwith her title OMG!:All about Me Diary! and her title Dork Diaries.",
    title="DORK DIARIES: HOLIDAY HEARTBREAK #6- Rachel Renee Russell",
    rating=4)

s4 = Story(
    content=
    "All modern American literature comes from one book by Mark Twain called \"Huckleberry Finn.\" It's the best book we've had.\" --Ernest Hemingway Huckleberry Finn had a tough life with his drunk father until an adventure with Tom Sawyer changed everything. But when Huck's dad returns and kidnaps him, he must escpe down the Mississippi river with runaway slave, Jim. They encounter trouble at every turn, from floods and gunfights to armed bandits and the long arm of the law. Through it all the friends stick together - but can Huck and Tom free Jim from slavery once and for all? With an inspirational introduction by Darren Shan, The Adventures of Huckleberry Finn is one of the twenty wonderful classic stories being relaunched in Puffin Classics in March 2015.",
    title="The Adventures of Huckleberry Finn - Mark Twain and Darren Shan",
    rating=5)

s5 = Story(
    content=
    "Greg Heffley is in big trouble. School property has been damaged, and Greg is the prime suspect. But the crazy thing is, he\u2019s innocent. Or at least sort of. The authorities are closing in, but when a surprise blizzard hits, the Heffley family is trapped indoors. Greg knows that when the snow melts he\u2019s going to have to face the music, but could any punishment be worse than being stuck inside with your family for the holidays? The world has gone crazy for Jeff Kinney's Diary of a Wimpy Kid series Sun Kinney is right up there with J K Rowling as one of the bestselling children's authors on the planet Independent Hilarious! Sunday Telegraph The most hotly anticipated children's book of the year is here - Diary of a Wimpy Kid The Big Issue Jeff Kinney is a #1 New York Times bestselling author and six-time Nickelodeon Kids\u2019 Choice Award winner for Favorite Book. The 11th book in the series, Diary of a Wimpy Kid: Double Down, will release on November 1, 2016. The first-ever theatrical adaptation of Diary of a Wimpy Kid was staged by the prestigious Minneapolis Children\u2019s Theatre Company from April to June, 2016. It earned rave critical reviews and had sold out shows. Jeff has been named one of Time magazine\u2019s 100 Most Influential People in the World. He is also the creator of Poptropica, which was named one of Time magazine\u2019s 50 Best Websites. Jeff spent his childhood in the Washington, D.C., area and moved to New England in 1995. He lives with his wife and two sons in Plainville, Massachusetts, where he owns a bookstore, An Unlikely Story.",
    title="Diary of a Wimpy Kid 6: Cabin Fever - Jeff Kinney",
    rating=4)

s6 = Story(
    content=
    "Greg's dad, Frank, is on a mission - a mission to make this wimpy kid, well, less wimpy. All manner of 'manly' physical activities are planned, but Greg just about manages to find a way out of them. That is until military academy is is mentioned and Greg realizes that he's going to have to come up with something very special to get out of this one . . . Diary of a Wimpy Kid: The Last Straw is the third title in the bestselling Diary of a Wimpy Kid series.",
    title="Diary of a Wimpy Kid 3 : The Last Straw- Jeff Kinney",
    rating=3)

s7 = Story(
    content=
    "Whatever you do, don't ask Greg about his summer vacation because he definitely doesn't want to talk about it... It's a brand-new year and a brand-new journal and Greg is keen to put the humiliating (and secret!) events of last summer firmly behind him. But someone knows everything - someone whose job it is to most definitely not keep anything embarrassing of Greg's private - his big brother, Rodrick. How can Greg make it through this new school year with his cool(ish) reputation intact? Diary of a Wimpy Kid: Rodrick Rules is the second title in the bestselling Diary of a Wimpy Kid series.",
    title="Diary of a Wimpy Kid 2 Rodrick Rules - Jeff Kinney",
    rating=5)

s1.save()
Story.objects.all()
Exemplo n.º 7
0
def test_app_can_create_story_data():
    story_inst = Story(title='test title', story='test story')
    story_inst.save()

    num_of_creates = Story.objects.all().count()
    assert num_of_creates == 1