def store_click(self, button, press): if press: self.session.add( Click(button, press, self.latestx, self.latesty, self.nrmoves, self.cur_win_proc, self.cur_win_id, self.cur_geo_id)) self.trycommit() self.nrmoves = 0
def store_click(self, button, x, y): """ Stores incoming mouse-clicks """ self.session.add( Click(button, True, x, y, len(self.mouse_path), self.current_window.proc_id, self.current_window.win_id, self.current_window.geo_id)) self.mouse_path = [] self.trycommit()
def save_click(self, link_id, referrer_url): click = Click( short_url_id=link_id, referrer_url=referrer_url ) self.session.add(click) self.session.commit() return click
def processClick(array): id = array[0] user = array[1] clicks = Click.query.all() print clicks if len(clicks) == 0: c1 = Click(id=0, count=0) c2 = Click(id=1, count=0) db.session.add(c1) db.session.add(c2) db.session.commit() else: bob = clicks[id] bob.count = bob.count + 1 db.session.commit() socketio.emit('event.update', [id, clicks[id].count, user], broadcast=True)
def test_create_click(self): """Test that clicks are created""" myurl = MyUrl(to_url="http://example.com", user_id = '1', utm_campaign='1', utm_term='narf', utm_medium='test', utm_source='clouds', utm_content='stringsandstrings', append_text='gianttrex') myurl.save() click = Click (myurl=myurl, to_url=myurl.to_url, redirect_url=myurl.redirect_url, referrer_domain='referrerhost.com', referrer_url='referrerhost.com/url', site=Site.objects.get_current(), user_id='1', user_ip='192.168.1.1', user_language='language', user_agent='awesome') click.save() self.assertEqual(click, Click.objects.get(pk=click.pk))
def test_create_click(self): """Test that clicks are created""" myurl = MyUrl(to_url="http://example.com", user_id='1', utm_campaign='1', utm_term='narf', utm_medium='test', utm_source='clouds', utm_content='stringsandstrings', append_text='gianttrex') myurl.save() click = Click(myurl=myurl, to_url=myurl.to_url, redirect_url=myurl.redirect_url, referrer_domain='referrerhost.com', referrer_url='referrerhost.com/url', site=Site.objects.get_current(), user_id='1', user_ip='192.168.1.1', user_language='language', user_agent='awesome') click.save() self.assertEqual(click, Click.objects.get(pk=click.pk))
def goto_url(request): url = request.GET.get('url',None) object_id = request.GET.get('oid',None) object_type = request.GET.get('ot',None) if url is None: redirect_url = '/' else: redirect_url = url try: ct_cache_key = 'goto_track_ctype_%s' % (object_type,) ct = cache.get(ct_cache_key) if ct is None: ct = ContentType.objects.get(pk=object_type) cache.set(ct_cache_key,ct,864000) # 10 days if ct is not None: model = ct.model_class() counter = Click() counter.content_type = ct obj_cache_key = 'goto_track_obj_count_%s_%s' % (ct.pk, object_id) obj_count = cache.get(obj_cache_key) if obj_count is None: obj_count = model.objects.filter(pk=object_id).count() # cache? cache.set(obj_cache_key, obj_count, 600) if obj_count > 0: counter.object_id = object_id counter.store(request, url) except: pass return redirect(redirect_url)
def parse_clicks(session): # get names of files to read and mongodb collection to write clickfile = os.path.join(os.path.expanduser(cfg.CURRENT_DIR), cfg.CLICKLOG) # read the file, write lines to database, and save lines that were not # written to the database # TODO may need to check if file is already open using a file lock if os.path.isfile(clickfile): f = open(clickfile, 'r+') lines_to_save = [] for line in f: try: text = ast.literal_eval(line.rstrip()) # get active app and window at time of event app = session.query(AppEvent).filter( AppEvent.event == "Active", AppEvent.time <= text['time']).order_by( AppEvent.time.desc()).first() window = session.query(WindowEvent).filter( WindowEvent.event == "Active", WindowEvent.time <= text['time']).order_by( WindowEvent.time.desc()).first() pid = app.app_id if app else 0 wid = window.window_id if window else 0 click = Click(text['time'], text['button'], text['location'][0], text['location'][1], pid, wid) session.add(click) except: print "Could not save " + str( line ) + " to the database. Saving for the next round of parsing." lines_to_save.append(line) # write lines that did not make it into the database to the start of the # file and delete the rest of the file f.seek(0) for line in lines_to_save: f.write(line) f.truncate() f.close()
def bounce(key): """GET handler to redirect a shortened key""" url = get_url_for_key(key) if url is None: abort(404) # Grab user-agent, or string 'None' if not provided. ua = request.headers.get('User-Agent') if ua is None: ua = 'None' # Record new click. See models.py for data definition click = Click(click_id=uuid4(), click_time=datetime.utcnow(), shortened=key, target_url=url, user_agent=ua[:255]) db.session.add(click) db.session.commit() # Process redirect even if we fail to record the click. return redirect(url)