def data_to_fbsponsored(user, data, tldextractor): try: timestamp = timestamp_to_datetime(float(data[0])) except ValueError: logger = logging.getLogger('vavs.tasks.analytics') logger.error("data_to_fbsponsored: %s, date: '%s', text: %s" % ( user, data[0], data[4])) raise title = data[5] fbsp, created = FBSponsored.objects.get_or_create( user = user, date = timestamp, title = title) if created: fbsp.actor = data[1] fbsp.target = data[2] fbsp.type_id = data[3] fbsp.text = data[4] images = data[6] links = data[7] for url in images: fbsp.images.add(make_fbadimage(url, tldextractor)) for url in links: fbsp.links.add(make_fbadlink(url, tldextractor)) fbsp.save() return fbsp
def get(self, request, username, hour): if request.is_ajax() if not can_access_user(request.user, username): raise Http404 else: user = get_object_or_404(User, username=username) participant = get_participant_profile(user) hour = timestamp_to_datetime(hour) anon = False if request.user == user else participant.anon_data json_data = ad_details_for_hour_json(user, hour, anon=anon) return HttpResponse(json_data, content_type="application/json") else: raise Http404
def data_to_fblisting(user, data, tldextractor=None): try: timestamp = timestamp_to_datetime(float(data['timestamp'])*0.001) except ValueError: logger = logging.getLogger('vavs.tasks.analytics') logger.error("data_to_fblisting: %s, date: '%s', text: %s" % ( user, data['timestamp'], data['list'])) raise fblist, created = FBListing.objects.get_or_create(user=user, date=timestamp) if created: fblist.listing = data['list'] fblist.save() return fblist
def data_to_fbad(user, data, tldextractor): timestamp = timestamp_to_datetime(int(data[0])*0.001) adid = data[1] fbad, created = FBAd.objects.get_or_create( user = user, date = timestamp, adid = adid) if created: fbad.text = data[2] fbad.title = data[3] images = data[4] links = data[5] for url in images: fbad.images.add(make_fbadimage(url, tldextractor)) for url in links: fbad.links.add(make_fbadlink(url, tldextractor)) fbad.save() return fbad