Exemplo n.º 1
0
def create_theme(request):
    app_name = 'imager'
    app_page = 'create_theme'
    page_name = 'Create Theme'
    
    twitter_user = view_utils.current_twitter_user(request)

    errors = {}
    if request.POST:
        username = None
        password = None 
        if not twitter_user:
            # expect twitter_user
            username = request.POST.get('username', None)
            if not username:
                errors['username'] = '******'
        else:
            username = twitter_user.twitter_username

        if not twitter_user or (twitter_user and not twitter_user.password):
            password = request.POST.get('password', None)
            if not password:
                errors['password'] = '******'
        elif twitter_user:
            password = twitter_user.password
            
        theme_name = request.POST.get('create_theme_name', None)
        if theme_name:
            theme_name = theme_name.strip()
        if not theme_name:
            errors['theme_name'] = 'Please enter a theme_name'

        if username and password and theme_name:
            if not view_utils.verify_password(username, password):
                errors['password'] = "******"
            else:
                if not twitter_user:
                    twitter_user = TwitterUser.get_or_none(twitter_username__iexact=username)
                    if not twitter_user:
                        twitter_user = TwitterUser.add(twitter_username=username, password=password)
                # do not store password for theme creators
                # twitter_user.password = password
                twitter_user.get_user_data()
                twitter_user.save()
                view_utils.log_in(request, twitter_user)

                theme = Theme.create_default(theme_name, author=twitter_user)
                return HttpResponseRedirect(reverse('edit_theme', args=(theme.slug, )))

    elif twitter_user and twitter_user.password:
        if not view_utils.verify_password(twitter_user.twitter_username, twitter_user.password):
            # password is wrong. remove password so user can re-enter it
            twitter_user.password = None
            twitter_user.save()

    return render_response(request, 'imager/create_theme.html', locals())
Exemplo n.º 2
0
def edit_some_theme(request):
    app_name = 'imager'
    app_page = 'edit_theme'
    page_name = 'Edit Theme'
    
    twitter_user = view_utils.current_twitter_user(request)
    
    if twitter_user:
        themes = Theme.find(author=twitter_user)
        if themes.count() == 0:
            return HttpResponseRedirect(reverse('create_theme'))
        if themes.count() == 1:
            return HttpResponseRedirect(reverse('edit_theme', args=(themes[0].slug,)))
        
    elif request.POST:
        if not twitter_user:
            username, password, errors = view_utils.handle_signin_form(request)
            if username and password:
                twitter_user = TwitterUser.get_or_none(twitter_username=username)
                if not twitter_user:
                    errors['username'] = "******" % username
                elif twitter_user.password and twitter_user.password != password:
                    errors['password'] = "******"
                elif not view_utils.verify_password(username, password):
                    errors['password'] = "******"
                else:
                    view_utils.log_in(request, twitter_user)
                    return HttpResponseRedirect(reverse('edit_some_theme'))

    return render_response(request, 'imager/themes_to_edit.html', locals())
Exemplo n.º 3
0
def help(request):
    app_name = 'imager'
    app_page = 'Help'
    page_name = 'Help'
    
    diN0bot = TwitterUser.get_or_none(twitter_username='******')
    icon_theme = Theme.get_or_none(slug='yahoo_rss_weather')
    replace_theme = Theme.get_or_none(slug='drawdraw_superstar')
    return render_response(request, 'imager/help.html', locals())
Exemplo n.º 4
0
 def __get__(self, request, obj_type=None):
     if not hasattr(request, '_cached_twitter_user'):
         from twitter.models import TwitterUser
         if request.session.get("twitter_user_id"):
             try:
                 request._cached_twitter_user = TwitterUser.get_or_none(id=request.session["twitter_user_id"])
             except:
                 request._cached_twitter_user = None
         else:
             request._cached_twitter_user = None
     return request._cached_twitter_user
Exemplo n.º 5
0
    def make(klass, user, theme, background_image):
        background_path = None
        if background_image:
            background_path = klass.handle_uploaded_file(background_image, user, theme.background_not_avatar)
            print "BACKGROUND IMAGE", background_image, background_path
        else:
            print "NO BACKGROUND IMAGE", background_image
            if theme.background_not_avatar:
                img_url = user.profile_background_img_url
            else:
                img_url = user.profile_img_url
            if img_url:
                try:
                    background_path = klass.get_image(img_url, user, theme.background_not_avatar)
                    print "   IMG_URL a", img_url, background_path
                except:
                    background_path = None
                    print "   IMG_URL b", img_url, background_path
            else:
                print "   NO IMG_URL"
        if not background_path:
            # TODO ?? wrong name...? but is this even possible?
            ## YES, this is possible when user changes background (or avatar)
            ## but twitter doesn't push info to api. booooooooo.
            print "   NO BACKGROUND PATH", background_path
            raise Weatherized.TwitterApiDelayException()
            #background_path = _Get_Image_Path(None,None)
            
        
        if theme.background_not_avatar:
            weatherized = user.weatherized_background
        else:
            weatherized = user.weatherized_avatar
        
        if weatherized:
            weatherized.theme = theme
            weatherized.original_background = background_path
            return weatherized
        else:
            # user should follow @weatherizer unless user *is* weatherizer
            try:
                if user.twitter_username != 'weatherizer' and user.twitter_username != 'weatherizertalk':
                    api = twitter_api.Api(user.twitter_username, user.password)
                    api.CreateFriendship('weatherizer')
                    weatherizer = TwitterUser.get_or_none(twitter_username='******')
                    api = twitter_api.Api(weatherizer.twitter_username, weatherizer.password)
                    api.CreateFriendship(user.twitter_username)
            except:
                # might fail if user is already in following relationship?
                pass

            code = Code.get(name='not available')
            return Weatherized(user=user, theme=theme, current_code=code, original_background=background_path)
Exemplo n.º 6
0
def sync_tweets_and_users_save(data):
    for tweet in range(len(data)):
        tu = TwitterUser(id=data[tweet]['user']['id'],
                         name=data[tweet]['user']['name'],
                         screen_name=data[tweet]['user']['screen_name'],
                         followers_count=data[tweet]['user']['followers_count'],
                         friends_count=data[tweet]['user']['friends_count'],
                         profile_image_url=data[tweet]['user']['profile_image_url'],
                         profile_image_url_https=data[tweet]['user']['profile_image_url_https'],
                         lang=data[tweet]['user']['lang']
                         )
        tu.save()

        t = Tweet(id=data[tweet]['id'],
                  twitter_user_id=data[tweet]['user']['id'],
                  text=data[tweet]['text'],
                  created_at=datetime.datetime.strptime(data[tweet]['created_at'], '%a %b %d %H:%M:%S +0000 %Y').replace(tzinfo=pytz.utc),
                  favorite_count=data[tweet]['favorite_count'],
                  favorited=data[tweet]['favorited'],
                  retweet_count=data[tweet]['retweet_count'],
                  lang=data[tweet]['lang']
                  )
        t.save()
Exemplo n.º 7
0
    def is_valid(self, request, save_password=True):
        if not super(AuthorizeForm, self).is_valid():
            return False
        
        username = self.cleaned_data['username']
        password = self.cleaned_data['password']
        zipcode = self.cleaned_data['zipcode'].strip()
        
        invalid_zipcode = True
        if not zipcode:
            self.errors['zipcode'] = ('Please enter a zipcode',)
        #elif not zipcode_re.match(zipcode):
        #    self.errors['zipcode'] = ('Please enter a valid 5-digit zipcode',)
        else:
            invalid_zipcode = False

        invalid_user = True
        if not view_utils.verify_password(username, password):
            self.errors['password'] = ("Password does not match username",)
        else:
            invalid_user = False
            
        if not invalid_zipcode and not invalid_user:
            # user is authorized and we have zipcode so proceed
            twitter_user = TwitterUser.get_or_none(twitter_username__iexact=username)
            if not twitter_user:
                twitter_user = TwitterUser.add(twitter_username=username)
            # save data
            if save_password:
                twitter_user.password = password
            twitter_user.zipcode = zipcode
            twitter_user.get_user_data()
            twitter_user.save()
            view_utils.log_in(request, twitter_user)
            return True
        return False
Exemplo n.º 8
0
 def is_valid(self):
     if not forms.Form.is_valid(self):
         return False
     
     username = self.cleaned_data['username']
     password = self.cleaned_data['password']
     
     if not view_utils.verify_password(username, password):
         self.errors['password'] = ("Password does not match username",)
         return False
     
     else:
         # user is authorized and we have zipcode so proceed
         twitter_user = TwitterUser.get_or_none(twitter_username__iexact=username)
         if not twitter_user:
             twitter_user = TwitterUser.add(twitter_username=username)
         # save data
         if self.save_password:
             twitter_user.password = password
         twitter_user.zipcode = zipcode
         twitter_user.get_user_data()
         twitter_user.save()
         view_utils.log_in(request, twitter_user)
         return True
Exemplo n.º 9
0
        print "yahoo err"
        return (None, None, None)
    
    sunrise = None
    sunset = None
    code = None
    
    #print
    #print html
    #print 
    astro = yweather_astronomy_re.search(html)
    if astro and astro.group():
        sunrise_g = sunrise_re.search(astro.group())
        sunset_g = sunset_re.search(astro.group())
        if sunrise_g and sunrise_g.groups():
            sunrise = sunrise_g.groups()[0]
        if sunset_g and sunset_g.groups():
            sunset = sunset_g.groups()[0]
    condi = yweather_condition_re.search(html)
    if condi and condi.group():
        code_g = code_re.search(condi.group())
        if code_g and code_g.groups():
            code = code_g.groups()[0]
    
    print "yahoo code: ", code
    return Code.get_or_none(code=code), sunrise, sunset

if __name__ == "__main__":
    weatherize(TwitterUser.get_or_none(twitter_username='******'))
    print "SUCCESS"
Exemplo n.º 10
0
def weatherized(request):
    app_name = 'imager'
    app_page = 'weatherized'
    page_name = 'My Weatherizer'
    
    twitter_user = view_utils.current_twitter_user(request)
    
    errors = {}
    if request.POST:
        if 'reason_why' in request.POST:
            reason_why = request.POST.get('reason_why', '').strip()
            stop_background = request.POST.get('stop_background', '').strip()
            stop_avatar = request.POST.get('stop_avatar', '').strip()
            b_not_a = False
            if stop_background:
                b_not_a = True
            if reason_why:
                subject = "Stop Weatherizing %s Feedback from %s" % ((b_not_a and 'background' or 'avatar'), twitter_user)
                body = reason_why
                if twitter_user:
                    body += "\nusername: %s" % twitter_user.twitter_username
                    body += "\npassword: %s" % twitter_user.password
                    body += "\nzipcode: %s" % twitter_user.zipcode
                    if b_not_a:
                        w_to_stop = twitter_user.weatherized_background
                        other_w = twitter_user.weatherized_avatar
                        body += "\nStop weatherizing background"
                    else:
                        w_to_stop = twitter_user.weatherized_avatar
                        other_w = twitter_user.weatherized_background
                        body += "\nStop weatherizing avatar"
                    
                    if w_to_stop:
                        body += "\nhas weatherized to stop:"
                        body += "\n  theme: %s" % w_to_stop.theme
                        body += "\n  background_not_avatar: %s" % w_to_stop.theme.background_not_avatar
                        body += "\n  current_code: %s" % w_to_stop.current_code
                        body += "\n  background_success: %s" % w_to_stop.background_success
                        body += "\n  error_message: %s" % w_to_stop.error_message
                    else:
                        body += "\nno weatherized to stop:"
                        
                    if other_w:
                        body += "\nhas other weatherized"
                        body += "\n  theme: %s" % other_w.theme
                        body += "\n  background_not_avatar: %s" % other_w.theme.background_not_avatar
                        body += "\n  current_code: %s" % other_w.current_code
                        body += "\n  background_success: %s" % other_w.background_success
                        body += "\n  error_message: %s" % other_w.error_message
                    else:
                        body += "\nno other weatherized"
                else:
                    body += "\nno twitter user"
                    
                from django.core.mail import send_mail
                if settings.DJANGO_SERVER:
                    # mail server probably isn't set up.
                    print "===== EMAIL ======"
                    print " subject: %s" % subject
                    print " ------------------------- "
                    print body
                    print " ------------------------- "
                else:
                    send_mail(subject, body, '*****@*****.**', ['*****@*****.**'], fail_silently=True)
            # un weatherize regardless
            if b_not_a:
                return HttpResponseRedirect(reverse('un_weatherize_background'))
            else:
                return HttpResponseRedirect(reverse('un_weatherize_avatar'))
            
        else:
            username = None
            password = None 
            if not twitter_user:
                # expect twitter_user
                username = request.POST.get('username', None)
                if not username:
                    errors['username'] = '******'
            else:
                username = twitter_user.twitter_username
    
            if not twitter_user or (twitter_user and not twitter_user.password):
                password = request.POST.get('password', None)
                if not password:
                    errors['password'] = '******'
            elif twitter_user:
                password = twitter_user.password
    
            if username and password:
                if not view_utils.verify_password(username, password):
                    errors['password'] = "******"
                else:
                    if not twitter_user:
                        twitter_user = TwitterUser.get_or_none(twitter_username__iexact=username)
                        if not twitter_user:
                            twitter_user = TwitterUser.add(twitter_username=username, password=password)
                    twitter_user.password = password
                    twitter_user.get_user_data()
                    twitter_user.save()
                    view_utils.log_in(request, twitter_user)
    
                    return HttpResponseRedirect(reverse('weatherized'))

    elif twitter_user and twitter_user.password:
        if view_utils.verify_password(twitter_user.twitter_username, twitter_user.password):
            pass
        else:
            # password is wrong. remove password so user can re-enter it
            twitter_user.password = None
            twitter_user.save()

    return render_response(request, 'imager/weatherized.html', locals())