Exemplo n.º 1
0
def create_profile_from_mention(email, location, data):
    signup_data = {}
    try:
        location_res = Geocoder.geocode(location)
        latlng = {
            "type":
            "Point",
            "coordinates":
            [float(location_res.longitude),
             float(location_res.latitude)]
        }
        user_address = location
        postal_code = location_res.postal_code
    except:
        try:
            location_res = Geocoder.geocode(data['user']['location'])
            lat, lon, addr, postal_code = location_res.latitude, location_res.longitude, location_res.postal_code
            latlng = {"type": "Point", "coordinates": [float(lon), float(lat)]}
            signup_data['location_default_on_error'] = 'true'
            user_address = data['user']['location']

        except:
            text = "We cannot recognise your location please try again with a postal code or from http://foodtrade.com"
            HQ_twitter = get_twitter_obj(settings.HQ_ACCESS_TOKEN,
                                         settings.HQ_ACCESS_TOKEN_SECRET)
            HQ_twitter.update_status(status=text,
                                     in_reply_to_status_id=data['id'])
            return

    user_profile_obj = UserProfile()
    min_user_id = int(
        user_profile_obj.get_minimum_id_of_user()[0]['minId']) - 1

    signup_data = {
        'is_unknown_profile': 'false',
        'from_mentions': 'true',
        'address': user_address,
        'latlng': latlng,
        'email': email,
        'zip_code': str(postal_code),
        'description': data['user']['description'],
        'foods': [],
        'name': data['user']['name'],
        'phone_number': '',
        'profile_img': data['user']['profile_image_url'],
        'sign_up_as': 'Individual',
        'type_user': [],
        'updates': [],
        'screen_name': data['user']['screen_name'],
        'Organisations': [],
        'useruid': min_user_id,
        'username': data['user']['screen_name'],
        'subscribed': 0,
        'newsletter_freq': 'Weekly'
    }

    join_time = datetime.datetime.now()
    join_time = time.mktime(join_time.timetuple())
    signup_data['join_time'] = int(join_time)
    user_profile_obj.create_profile(signup_data)
    '''Send Email to confirm Account SignUp via Twitter'''
    template_content = str(
        render_to_response('notice-mail.html', {
            'data': signup_data,
            'register_request_type': 'Twitter'
        }))
    template_content = template_content.replace(
        'Content-Type: text/html; charset=utf-8', '')
    email_object = Email()
    email_object.send_mail('Please confirm your account',
                           template_content=[{
                               'name': 'main',
                               'content': template_content
                           }],
                           to=[{
                               'email': email
                           }])

    try:
        '''Transport the user to MailChimp'''
        mailchimp_obj = MailChimpClass()
        mailchimp_obj.subscribe(signup_data)
    except:
        pass

    try:
        mailchimp_obj_new = MailChimpClass(list_id='eeea3ac4c6')
        mailchimp_obj_new.subscribe(data)
    except:
        pass

    return {'status': 1}
Exemplo n.º 2
0
def sms_receiver(request):
    body = request.GET.get('Body', "")
    cell_no = request.GET.get('From', '')
    msg_from = cell_no.replace('+', "")

    user_profile = UserProfile()
    http_response = ""
    try:
        usr = user_profile.get_profile_by_username(msg_from)
        username = usr['username']

        h = HTMLParser.HTMLParser()

        tweet_id = str(uuid.uuid4())
        parent_tweet_id = 0
        tweet_feed = TweetFeed()
        data = {
            'tweet_id': str(tweet_id),
            'parent_tweet_id': str(parent_tweet_id),
            'status': h.unescape(body),
            'picture': [],
        }
        tweet_feed.insert_tweet_by_username(msg_from, data)
        http_response = http_response + "appended new tweet"
    except:
        str_text = body

        if "#join" in str_text:
            str_text = str_text.lower()
            str_text = str_text.strip()
            str_text = str_text.strip()
            str_text = str_text.replace("#join", "")
            str_text = str_text.strip()
            import re

            regex = re.compile(
                ("([a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`"
                 "{|}~-]+)*(@|\sat\s)(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(\.|"
                 "\sdot\s))+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)"))

            user_emails = re.findall(regex, str_text)

            if len(user_emails) > 0:
                user_email = user_emails[0][0]
                str_text = str_text.replace(user_email, "")
                location = str_text.strip()

                signup_data = {}
                try:
                    location_res = Geocoder.geocode(location)
                    latlng = {
                        "type":
                        "Point",
                        "coordinates": [
                            float(location_res.longitude),
                            float(location_res.latitude)
                        ]
                    }
                    user_address = location
                    postal_code = location_res.postal_code
                except:
                    try:
                        location_res = Geocoder.geocode(
                            data['user']['location'])
                        lat, lon, addr, postal_code = location_res.latitude, location_res.longitude, location_res.postal_code
                        latlng = {
                            "type": "Point",
                            "coordinates": [float(lon), float(lat)]
                        }
                        signup_data['location_default_on_error'] = 'true'
                        user_address = data['user']['location']

                    except:
                        text = "We cannot recognise your location please try again with a postal code or from http://foodtrade.com"
                        send_sms(cell_no, text)
                        return

                user_profile_obj = UserProfile()
                min_user_id = int(
                    user_profile_obj.get_minimum_id_of_user()[0]['minId']) - 1

                signup_data = {
                    'is_unknown_profile': 'false',
                    'from_mentions': 'true',
                    'address': user_address,
                    'latlng': latlng,
                    'email': user_email,
                    'zip_code': str(postal_code),
                    'description': "",
                    'foods': [],
                    'name': msg_from,
                    'phone_number': cell_no,
                    'profile_img':
                    "http://pbs.twimg.com/profile_images/378800000141996074/6a363e3c4f2a84a956c3cb27c50b2ca0_normal.png",
                    'sign_up_as': 'Individual',
                    'type_user': [],
                    'updates': [],
                    'screen_name': msg_from,
                    'Organisations': [],
                    'useruid': min_user_id,
                    'username': msg_from,
                    'subscribed': 0,
                    'newsletter_freq': 'Weekly'
                }

                join_time = datetime.datetime.now()
                join_time = time.mktime(join_time.timetuple())
                signup_data['join_time'] = int(join_time)
                user_profile_obj.create_profile(signup_data)
                '''Send Email to confirm Account SignUp via SMS'''
                email_object = Email()
                template_content = str(
                    render_to_response(
                        'notice-mail.html', {
                            'data': signup_data,
                            'register_request_type': 'SMS',
                            'phone': cell_no
                        }))
                template_content = template_content.replace(
                    'Content-Type: text/html; charset=utf-8', '')
                email_object.send_mail('Please confirm your account',
                                       template_content=[{
                                           'name':
                                           'main',
                                           'content':
                                           template_content
                                       }],
                                       to=[{
                                           'email': email
                                       }])

                try:
                    '''Transport the user to MailChimp'''
                    mailchimp_obj = MailChimpClass()
                    mailchimp_obj.subscribe(signup_data)
                except:
                    pass

                try:
                    mailchimp_obj_new = MailChimpClass(list_id='eeea3ac4c6')
                    mailchimp_obj_new.subscribe(data)
                except:
                    pass
                '''Send Confirmation SMS'''
                send_sms(
                    cell_no,
                    'You have successfully joined FoodTrade. Please visit http://foodtrade.com ASAP! Thanks!'
                )

                http_response = http_response + "appended new tweet"
    return HttpResponse(http_response)