Example #1
0
def listen():
  print "attach"

  # Kafka
  consumer = KafkaConsumer(bootstrap_servers=os.environ["KAFKA_BOOTSTRAP_SRVS"], group_id=os.environ["KAFKA_GROUP_ID"])
  consumer.subscribe([os.environ["KAFKA_SOURCE_TOPIC"]])

  # Snowplow
  e = Emitter(os.environ["SP_COLLECTOR_URI"],protocol=os.environ["SP_COLLECTOR_PROTOCOL"],port=int(os.environ["SP_COLLECTOR_PORT"]),method=os.environ["SP_COLLECTOR_METHOD"])
  t = Tracker(emitters=e,namespace="cf",app_id=str(os.environ["APP_ID"]),encode_base64=True)

  for msg in consumer:
    #
    try:
      indata = json.loads(msg.value)
      
      s1 = Subject()
      s1.set_platform("app")
      s1.set_user_id("??")
      s1.set_lang("??")
      s1.set_ip_address("0.0.0.0")
      s1.set_useragent("??")
      
      t.set_subject(s1)

      t.track_self_describing_event(SelfDescribingJson("iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",{
        "data":{
          "data": indata
        },
        "schema": "iglu:"+os.environ["OPERATOR_ID"]+"/"+os.environ["APP_ID"]+"/jsonschema/1-0-0"
      }))

      t.flush()
    except Exception,Argument:
      print "Error:",str(Argument)
Example #2
0
def contact(request):
    title = 'Contact'
    form = contactForm(request.POST or None)
    confirm_message = None
    e = Emitter("192.168.2.133:8090/contact")
    tracker = Tracker(e, namespace="sdp", app_id="sdp-11", encode_base64=False)

    if form.is_valid():
        name = form.cleaned_data['name']
        comment = form.cleaned_data['comment']
        subject = 'Message from Mysite.com'
        message = '%s %s' % (comment, name)
        emailFrom = form.cleaned_data['email']
        # emailTo = [settings.EMAIL_HOST_USER]
        emailTo = ['*****@*****.**']
        send_mail(
            subject,
            message,
            emailFrom,
            emailTo,
            fail_silently=True,
        )
        title = 'Thanks!'
        confirm_message = 'Thanks for the message, we will get right back to you.'
        form = None
        tracker.track_page_view("192.168.2.133:8090/contact")

    context = {
        'title': title,
        'form': form,
        'confirm_message': confirm_message,
    }
    template = 'contact.html'
    return render(request, template, context)
Example #3
0
def track(type, data):
    """
    Called for the tracking of events
    input: type of event to track, data to pass
    output: No return
    """
    emitter = Emitter(SNOWPLOW_MICRO_URI,
                      buffer_size=1,
                      on_success=success,
                      on_failure=failure)
    tracker = Tracker(emitter)
    # Dictionary to contain all events we want to track and their corresponding methods.
    # So we can have a more generic way to track
    dict = {
        PAGE_VIEW: tracker.track_page_view,
        FORM_SUBMIT: tracker.track_form_submit,
        STRUCT: tracker.track_struct_event
    }
    subject = Subject()
    subject.set_platform("pc")
    tracker.set_subject(subject)
    if isinstance(data, list):
        dict[type](*data)
    else:
        dict[type](data)
    logger.setLevel(10)
Example #4
0
    def setup_tracker(self):
        """Setup an instance of a tracker"""
        self.companyConfig = self.setup_config(self.companyConfig)
        self.emitter = Emitter(self.companyConfig["COLLECTOR_HOST"],
                               protocol=self.companyConfig["PROTOCOL"],
                               port=self.companyConfig["PORT"],
                               method=self.companyConfig["EMIT_METHOD"],
                               buffer_size=self.companyConfig["BUFFER_SIZE"])
        self.subject = Subject()
        self.tracker = Tracker(emitters=self.emitter,
                               subject=self.subject,
                               namespace=self.companyConfig["TRACKER_NAME"],
                               app_id=self.companyConfig["APP_ID"],
                               encode_base64=self.companyConfig["ENCODE64"])

        return self.tracker
def save_tweet(data):
    #print "save_tweet"
    #print data

    indata = data

    e = Emitter(args.sp_collector_uri,
                protocol=args.sp_collector_protocol,
                port=int(args.sp_collector_port),
                method=args.sp_collector_method)
    t = Tracker(emitters=e,
                namespace="cf",
                app_id=args.sp_app_id,
                encode_base64=True)

    s1 = Subject()
    s1.set_platform("web")
    s1.set_user_id(str(indata.get("user_id")))
    s1.set_lang(str(indata.get("lang")))
    #s1.set_ip_address(str(indata.get("i_ip")))
    s1.set_useragent(str(indata.get("source")))

    t.set_subject(s1)

    t.track_self_describing_event(
        SelfDescribingJson(
            "iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",
            {
                "data": {
                    "data": indata
                },
                "schema":
                "iglu:com.rbox24/" + args.sp_app_id + "/jsonschema/1-0-0"
            }))

    t.flush()
    print "Tweet sent to collector, time:", time.time()
Example #6
0
    print(str(x) + " events sent successfully!")


unsent_events = []


def g(x, y):
    print(str(x) + " events sent successfully!")
    print("Events not sent. They have been stored in unsent_events:")

    for event_dict in y:
        print(event_dict)
        unsent_events.append(event_dict)


e = Emitter(URL, buffer_size=3, on_success=f, on_failure=g)

t = Tracker(e)

# This doesn't cause the emitter to send a request because the buffer_size was
# set to 3, not 1
t.track_page_view("http://www.myowndomainhere.dev")

# This does cause the emitter to try to send all 6 events
t.track_page_view("http://www.myowndomainhere.dev/signin")
t.track_page_view("http://www.myowndomainhere.dev/home")
t.track_page_view("http://www.myowndomainhere.dev/somepage")
t.track_page_view("http://www.myowndomainhere.dev/anotherpage")
t.track_page_view("http://www.myowndomainhere.dev/logout")

# Since the method is GET by default, 6 separate requests are sent
Example #7
0
    print "show_raw:", args.show_raw
    print "save:", args.save
    print "period:", args.period
    print "sp_collector_uri:", args.sp_collector_uri
    print "sp_collector_protocol:", args.sp_collector_protocol
    print "sp_collector_port:", args.sp_collector_port
    print "sp_collector_method:", args.sp_collector_method
    print "sp_app_id:", args.sp_app_id
    print "--"

    print "Tracker setup..."
    #global emiter
    #global tracker
    emiter = Emitter(buffer_size=50,
                     endpoint=args.sp_collector_uri,
                     protocol=args.sp_collector_protocol,
                     port=int(args.sp_collector_port),
                     method=args.sp_collector_method)
    tracker = Tracker(emitters=emiter,
                      namespace="cf",
                      app_id=args.sp_app_id,
                      encode_base64=True)

    print "Starting listening to Twitter..."

    #global period_counter
    aggregates = {}
    period_counter = int(time.time())

    l = StdOutListener()
    auth = OAuthHandler(args.consumer_key, args.consumer_secret)
Example #8
0
sp_logger.setLevel(100)

COLLECTOR_URL = "fishtownanalytics.sinter-collect.com"
COLLECTOR_PROTOCOL = "https"

COOKIE_PATH = os.path.join(os.path.expanduser('~'), '.dbt/.user.yml')

INVOCATION_SPEC = 'iglu:com.dbt/invocation/jsonschema/1-0-0'
PLATFORM_SPEC = 'iglu:com.dbt/platform/jsonschema/1-0-0'
RUN_MODEL_SPEC = 'iglu:com.dbt/run_model/jsonschema/1-0-0'
INVOCATION_ENV_SPEC = 'iglu:com.dbt/invocation_env/jsonschema/1-0-0'
PACKAGE_INSTALL_SPEC = 'iglu:com.dbt/package_install/jsonschema/1-0-0'

DBT_INVOCATION_ENV = 'DBT_INVOCATION_ENV'

emitter = Emitter(COLLECTOR_URL, protocol=COLLECTOR_PROTOCOL, buffer_size=1)
tracker = Tracker(emitter, namespace="cf", app_id="dbt")

active_user = None


class User(object):
    def __init__(self):
        self.do_not_track = True

        self.id = None
        self.invocation_id = str(uuid.uuid4())
        self.run_started_at = datetime.now(tz=pytz.utc)

    def state(self):
        return "do not track" if self.do_not_track else "tracking"
Example #9
0
def tracker(request):
    tracker = Tracker(Emitter("payments.savantdigital.net"),
                      namespace="sdp",
                      app_id="sdp-11",
                      encode_base64=False)
    return render(request, response, context)
Example #10
0
def create_tracker():
    e = Emitter(SNOWPLOW_MICRO_URL)
    return Tracker(e)
Example #11
0
"""Snowplow tracker configuration."""
import datetime
import uuid

from .models import Basket
from snowplow_tracker import Subject, Tracker, Emitter

e = Emitter("localhost:9090")
t = Tracker(e)
s = Subject()

s.set_lang('en')
"""App configuration."""
CATEGORIES = [
    "Electronics",
    "Clothes",
    "Shoes",
    "House",
    "Arts",
]

basket = Basket()
Example #12
0
from flask import Flask, render_template, request, redirect
from snowplow_tracker import Emitter, Tracker
from snowplow_tracker import SelfDescribingJson

app = Flask(__name__)

email_addresses = []
e = Emitter("localhost:8080")
t = Tracker(e, namespace="python", app_id="hello_bears")


@app.route('/emails', methods=['GET'])
def emails():
    t.track_self_describing_event(
        SelfDescribingJson(
            "iglu:com.hellobears/email_addresses_viewed/jsonschema/1-0-0",
            {"test": "stewart"}))
    return render_template('emails.html', email_addresses=email_addresses)


@app.route('/signup', methods=['POST'])
def signup():
    email = request.form['email']
    email_addresses.append(email)

    t.track_self_describing_event(
        SelfDescribingJson(
            "iglu:com.hellobears/email_address_submitted/jsonschema/1-0-0",
            {"email_address": email}))
    return redirect('/')