def subscription_create(request, course_id): user = request.user course = Course.objects.get(pk=course_id) create_subscription(user, course) return redirect('/main/profile/')
def paypal_ipn(request, *args, **kwargs): try: #validate that this ipn was initiated from the site if request.POST.get('receiver_email') != settings.PAYPAL_RECEIVER_EMAIL: log.error('Received maliscious IPN. Possible thread! IPN DATA = %s' % request.POST) data = request.POST.copy() username = request.POST.get('custom') user = User.objects.get(username=username) profile = user.get_profile() #make sure the user is verified if data.get('payer_status') != 'verified': log.error('user %s is not active in paypal' % username) return HttpResponse('error') if data.get('txn_type') == 'subscr_signup': log.warn('received singup IPN with data %s' % (data)) utils.create_subscription(user, data, profile.ipaddress) elif data.get('txn_type') == 'subscr_payment': log.warn('received subscr_payment IPN with data %s' % (data)) utils.activate_subscription(user, data, profile.ipaddress) #now email the user that their subscription is active from mailer import send_email as send_mail send_mail(template='subscription_active', subject="Your Subscription is activated", to_email=[user.email]) except Exception, e: log.error("Error occured in IPN %s" % e.message) return HttpResponse('error')
def paypal_ipn(request, *args, **kwargs): try: #validate that this ipn was initiated from the site if request.POST.get( 'receiver_email') != settings.PAYPAL_RECEIVER_EMAIL: log.error( 'Received maliscious IPN. Possible thread! IPN DATA = %s' % request.POST) data = request.POST.copy() username = request.POST.get('custom') user = User.objects.get(username=username) profile = user.get_profile() #make sure the user is verified if data.get('payer_status') != 'verified': log.error('user %s is not active in paypal' % username) return HttpResponse('error') if data.get('txn_type') == 'subscr_signup': log.warn('received singup IPN with data %s' % (data)) utils.create_subscription(user, data, profile.ipaddress) elif data.get('txn_type') == 'subscr_payment': log.warn('received subscr_payment IPN with data %s' % (data)) utils.activate_subscription(user, data, profile.ipaddress) #now email the user that their subscription is active from mailer import send_email as send_mail send_mail(template='subscription_active', subject="Your Subscription is activated", to_email=[user.email]) except Exception, e: log.error("Error occured in IPN %s" % e.message) return HttpResponse('error')
tweet_string = json.dumps(mtweet) tweets.append(tweet_string) else: # pause before checking again print 'sleeping...' time.sleep(WAIT) if len(tweets) >= CHUNK: write_to_pubsub(pubsub, tweets) tweets = [] count += 1 if count % 25 == 0: print("processing count: %s of %s at %s" % (count, count_max, datetime.datetime.now())) if __name__ == '__main__': ingest_topic_info = PUBSUB_TOPIC_INGEST.split('/') ingest_topic_name = ingest_topic_info[-1] ingest_sub_name = "tweets-%s" % ingest_topic_name print "starting modeling...." credentials = utils.get_credentials() pubsub = utils.create_pubsub_client(credentials) try: # TODO: check if subscription exists first subscription = utils.create_subscription(pubsub, PROJECT_ID, ingest_sub_name, PUBSUB_TOPIC_INGEST) except Exception, e: print e model_tweets(pubsub, ingest_sub_name) print 'exited write loop'
def enhance_tweet(ml_api_service, tweet): response = ml_api_service.documents().analyzeSentiment(body={ 'document': { 'type': 'PLAIN_TEXT', 'content': tweet['text'] } }).execute() tweet['polarity'] = response['documentSentiment']['polarity'] tweet['magnitude'] = response['documentSentiment']['magnitude'] return tweet if __name__ == '__main__': model_topic_info = PUBSUB_TOPIC.split('/') model_topic_name = model_topic_info[-1] model_sub_name = "tweets-%s" % model_topic_name print "starting write to BigQuery...." credentials = utils.get_credentials() bigquery = utils.create_bigquery_client(credentials) pubsub = utils.create_pubsub_client(credentials) ml_api_service = build('language', 'v1beta1', developerKey=API_KEY) try: # TODO: check if subscription exists first subscription = utils.create_subscription(pubsub, PROJECT_ID, model_sub_name, PUBSUB_TOPIC) except Exception, e: print e enhance_tweets(ml_api_service, pubsub, model_sub_name, bigquery) print 'exited write loop'