예제 #1
0
파일: views.py 프로젝트: thetomcraig/EROS
def scrape_top_twitter_people(request):
    """
    API for manually scraping
    """
    names_and_unames = utils_scrape_top_twitter_people()

    for entry in names_and_unames:
        person = None
        person = TwitterPerson.objects.get_or_create(username=entry['uname'])[0]

        person.username = entry['uname']
        person.real_name= entry['name']
        person.avatar = entry['avatar']
        person.save()

    all_twitter_people = TwitterPerson.objects.all()
    for person in all_twitter_people:
        scrape_twitter_person(person)

    all_twitter_posts = TwitterPost.objects.all()
    num = len(all_twitter_posts)
    data = {'total num posts': num}
    return JsonResponse({'success': data})
예제 #2
0
파일: views.py 프로젝트: thetomcraig/EROS
def twitter_person_detail(request, person_username):
    if request.method == "POST":
        form = PoolForm(request.POST)

    all_people = TwitterPerson.objects.all()
    author = None
    for person in all_people:
        if person.username.strip() == person_username.strip():
            author = person

    all_people_json = {x.username: x.real_name for x in all_people}
    pool_json = {x.username: x.real_name for x in author.pool.all()}
    pool_form = PoolForm(initial={'twitter_people': all_people_json})

    sentences = []
    markov_sentences = []
    person_type = ''

    # Grab data from author if twitter person
    if isinstance(author, TwitterPerson):
        person_type = str(TwitterPerson)
        sentences = TwitterPost.objects.filter(author=author)

        markov_sentences = author.twitterpostmarkov_set.all().order_by('-randomness')

    sentences_to_render = markov_sentences
    # If you are already on the page, these things
    # will happen when you click buttons
    if(request.GET.get('go_back_to_list')):
        return HttpResponseRedirect(reverse('twitter_home'))

    if(request.GET.get('scrape')):
        scrape_twitter_person(author)
        return HttpResponseRedirect('/integrations/twitter_person_detail/' + person_username)

    if(request.GET.get('show_original')):
        sentences_to_render = sentences

    if(request.GET.get('show_markov')):
        sentences_to_render = markov_sentences

    if(request.GET.get('generate_post')):
        apply_markov_chains_twitter(author)
        return HttpResponseRedirect('/integrations/twitter_person_detail/' + person_username)

    if(request.GET.get('clear_posts')):
        clear_set(author.twitterpost_set.all())
        clear_set(author.twitterpostcache_set.all())
        clear_set(author.twitterpostmarkov_set.all())
        return HttpResponseRedirect('/integrations/twitter_person_detail/' + person_username)

    if(request.GET.get('show_pool')):
        pool_form = PoolForm(initial={'twitter_people': pool_json})

    if(request.GET.get('show_all')):
        pool_form = PoolForm(initial={'twitter_people': all_people_json})

    if(request.GET.get('add_selected_to_pool')):
        pass

    template = loader.get_template('integrations/twitter_person_detail.html')
    context = RequestContext(request, {
        'pool_form': pool_form,
        'person': author,
        'person_type': person_type,
        'sentences': sentences_to_render,
        'len_sentences': len(sentences),
        'len_markov_sentences': len(markov_sentences),
    })

    return HttpResponse(template.render(context))