示例#1
0
    def handle(self, *args, **options):
        api = twitter.Api(consumerKey,consumerSecret,accessToken,accessSecret)
        results = api.GetUserTimeline(screen_name="kor_celebrities",count=25)
        
        for tweet in results:
#             if tweet.media and tweet.media[0]['type'] == u'photo':
            if tweet.media:
                print tweet.media[0]['type']
                
                key = hashlib.md5(tweet.media[0]['media_url']).hexdigest()
                result_article = Twitternew.objects.filter(insert_key=key)
                if not len(result_article):
#                 print tweet.text
#                 print tweet.media[0]['type']
#                 print tweet.media[0]['media_url']
                    try:
                        twitternew = Twitternew()
                        twitternew.create_user = User.objects.get(id=1)
                        twitternew.title = tweet.text
                        twitternew.type = tweet.media[0]['type']
                        twitternew.content = "![](" + tweet.media[0]['media_url'] + ")"
                        twitternew.status = u'P'
                        twitternew.save()
                    except Exception, e:
                        print e
示例#2
0
文件: views.py 项目: namkim/bootcamp
def write(request):
    if request.method == 'POST':
        form = TwitternewForm(request.POST)
        if form.is_valid():
            twitternew = Twitternew()
            twitternew.create_user = request.user
            twitternew.title = form.cleaned_data.get('title')
            twitternew.content = form.cleaned_data.get('content')
            status = form.cleaned_data.get('status')
            if status in [Twitternew.PUBLISHED, Twitternew.DRAFT]:
                twitternew.status = form.cleaned_data.get('status')
            twitternew.save()
            tags = form.cleaned_data.get('tags')
            twitternew.create_tags(tags)
            return redirect('/twitternews/')
    else:
        form = TwitternewForm()
    return render(request, 'twitternews/write.html', {'form': form})