<commit_before>import json

from django.contrib.gis.geos import Point
from social_auth.models import UserSocialAuth

from location.models import (
    LocationSnapshot,
    LocationSource,
    LocationSourceType
)


class FoursquareConsumer(object):
    def __init__(self, data):
        self.data = json.loads(data)

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

            return LocationSnapshot.objects.create(
                location=Point(
                    self.data['venue']['location']['lng'],
                    self.data['venue']['location']['lat'],
                ),
                source=source,
            )
        return None

    def get_user(self):
        return UserSocialAuth.objects.get(
            uid=self.data['user']['id'],
            provider='foursquare',
        )

    @classmethod
    def get_source_type(cls):
        source_type, _ = LocationSourceType.objects.get_or_create(
            name='Foursquare Check-in'
        )
        return source_type
<commit_msg>Properly set check-in time from foursquare push payload.<commit_after>import datetime
import json

from django.contrib.gis.geos import Point
import pytz
from social_auth.models import UserSocialAuth

from location.models import (
    LocationSnapshot,
    LocationSource,
    LocationSourceType
)


class FoursquareConsumer(object):
    def __init__(self, data):
        self.data = json.loads(data)

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

            return LocationSnapshot.objects.create(
                location=Point(
                    self.data['venue']['location']['lng'],
                    self.data['venue']['location']['lat'],
                ),
                date=(
                    datetime.datetime.fromtimestamp(
                        self.data['createdAt']
                    ).replace(
                        tzinfo=pytz.timezone(
                            self.data['timeZone']
                        )
                    )
                ),
                source=source,
            )
        return None

    def get_user(self):
        return UserSocialAuth.objects.get(
            uid=self.data['user']['id'],
            provider='foursquare',
        )

    @classmethod
    def get_source_type(cls):
        source_type, _ = LocationSourceType.objects.get_or_create(
            name='Foursquare Check-in'
        )
        return source_type

{'fraction_non_alphanumeric': 0.10452364633310486, 'fraction_numerical': 0.0, 'mean_word_length': 1.6853725850965962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4310733', 'n_tokens_mistral': 776, 'n_tokens_neox': 736, 'n_words': 131}