示例#1
0
    def update_location(self):
        source_type = self.get_source_type()
        data = self.get_location_data()

        local_tz = pytz.timezone(self.user_settings.icloud_timezone)

        date = datetime.datetime.fromtimestamp(
            float(data['timeStamp']) / 1000, local_tz)

        if LocationSnapshot.objects.filter(
                date__gt=date - datetime.timedelta(minutes=1),
                source__type=source_type,
                source__user=self.user_settings.user,
        ).exists():
            logger.info(
                'Found another sample from within the last minute; skipping '
                'gathered icloud location')
            return

        with watch_location(self.user_settings.user):
            source = LocationSource.objects.create(
                name='Apple iCloud location at %s' % date,
                type=source_type,
                user=self.user_settings.user,
                data=data,
                active=False,
            )
            return LocationSnapshot.objects.create(
                source=source,
                location=Point(
                    data['longitude'],
                    data['latitude'],
                ),
                date=date,
            )
示例#2
0
    def test_watch_location_unchanged(self):
        @receiver(location_updated, dispatch_uid='signal_test_uid')
        def process_incoming_location(*args, **kwargs):
            self.signal_receipts.append({
                'args': args,
                'kwargs': kwargs,
            })

        with watch_location(self.user):
            pass

        self.assertTrue(len(self.signal_receipts) == 0)
示例#3
0
    def test_watch_location_unchanged(self):
        @receiver(location_updated, dispatch_uid='signal_test_uid')
        def process_incoming_location(*args, **kwargs):
            self.signal_receipts.append({
                'args': args,
                'kwargs': kwargs,
            })

        with watch_location(self.user):
            pass

        self.assertTrue(
            len(self.signal_receipts) == 0
        )
示例#4
0
    def test_watch_location_changed(self):
        @receiver(location_updated, dispatch_uid='signal_test_uid')
        def process_incoming_location(*args, **kwargs):
            self.signal_receipts.append({
                'args': args,
                'kwargs': kwargs,
            })

        with watch_location(self.user):
            LocationSnapshot.objects.create(
                source=self.source,
                location=Point(10, 11),
                date=datetime.datetime.utcnow().replace(tzinfo=utc))

        self.assertTrue(len(self.signal_receipts) == 1)
    def process_checkin(self):
        if self.data["type"] == "checkin":
            user = self.get_user()
            source = LocationSource.objects.create(
                name=self.data["venue"]["name"], user=user, type=self.get_source_type(), data=self.data
            )

            with watch_location(user):
                return LocationSnapshot.objects.create(
                    location=Point(self.data["venue"]["location"]["lng"], self.data["venue"]["location"]["lat"]),
                    date=(
                        datetime.datetime.fromtimestamp(self.data["createdAt"], pytz.timezone(self.data["timeZone"]))
                    ),
                    source=source,
                )
        return None
示例#6
0
    def process(self):
        logger.info('Processing source %s.', self.source)
        document = self._get_document(self.source.data['url'])

        base_time = self.get_start_time(document)
        route_name = self.get_route_name(document)

        with watch_location(self.source.user):
            for raw_point in self.get_points(document, base_time):
                key_name = raw_point['key']
                if isinstance(self.source.data['known_points'], list):
                    self.source.data['known_points'] = {}
                if key_name not in self.source.data['known_points']:
                    point = self._get_processed_point(raw_point, base_time)
                    logger.debug(
                        'Creating point %s,%s at %s.',
                        point['lat'],
                        point['lng'],
                        point['date'],
                    )
                    LocationSnapshot.objects.create(
                        source=self.source,
                        location=point['point'],
                        date=point['date'],
                    )
                    self.source.data['known_points'][key_name] = raw_point
                else:
                    logger.debug(
                        'Point %s,%s already stored.',
                        raw_point['lat'],
                        raw_point['lng'],
                    )

        if route_name:
            self.source.name = '%s (%s)' % (
                route_name if route_name else 'AdHoc',
                self.source.data['url']
            )
        if self.source.active:
            self.source.active = self.is_active()
            if not self.source.active:
                logger.debug('Source has expired; marked inactive.')
        self.source.save()
示例#7
0
    def test_watch_location_changed(self):
        @receiver(location_updated, dispatch_uid='signal_test_uid')
        def process_incoming_location(*args, **kwargs):
            self.signal_receipts.append({
                'args': args,
                'kwargs': kwargs,
            })

        with watch_location(self.user):
            LocationSnapshot.objects.create(
                source=self.source,
                location=Point(
                    10,
                    11
                ),
                date=datetime.datetime.utcnow().replace(tzinfo=utc)
            )

        self.assertTrue(
            len(self.signal_receipts) == 1
        )
示例#8
0
    def process_checkin(self):
        if self.data['type'] == 'checkin':
            user = self.get_user()
            source = LocationSource.objects.create(
                name=self.data['venue']['name'],
                user=user,
                type=self.get_source_type(),
                data=self.data)

            with watch_location(user):
                return LocationSnapshot.objects.create(
                    location=Point(
                        self.data['venue']['location']['lng'],
                        self.data['venue']['location']['lat'],
                    ),
                    date=(datetime.datetime.fromtimestamp(
                        self.data['createdAt'],
                        pytz.timezone(self.data['timeZone']),
                    )),
                    source=source,
                )
        return None
示例#9
0
    def update_location(self):
        source_type = self.get_source_type()
        data = self.get_location_data()

        local_tz = pytz.timezone(self.user_settings.icloud_timezone)

        date = datetime.datetime.fromtimestamp(
            float(data['timeStamp']) / 1000,
            local_tz
        )

        if LocationSnapshot.objects.filter(
            date__gt=date - datetime.timedelta(minutes=1),
            source__type=source_type,
            source__user=self.user_settings.user,
        ).exists():
            logger.info(
                'Found another sample from within the last minute; skipping '
                'gathered icloud location'
            )
            return

        with watch_location(self.user_settings.user):
            source = LocationSource.objects.create(
                name='Apple iCloud location at %s' % date,
                type=source_type,
                user=self.user_settings.user,
                data=data,
                active=False,
            )
            return LocationSnapshot.objects.create(
                source=source,
                location=Point(
                    data['longitude'],
                    data['latitude'],
                ),
                date=date,
            )