コード例 #1
0
    def handle(self, *args, **options):
        with requests.Session() as session:
            post = session.post('https://geocaching.su', data=LOGIN_DATA)
            r = session.get('https://geocaching.su')
            if not logged(r.text):
                print('Authorization failed')
            else:
                ids = LogRecommendCach.objects.all().values_list('cacher_uid',
                                                                 flat=True)
                for uid in Geocacher.objects.exclude(uid__in=ids).values_list(
                        'uid', flat=True):
                    r = session.get(
                        'http://www.geocaching.su/site/popup/userstat.php',
                        params={
                            's': 3,
                            'uid': uid
                        })
                    for (cid, x, y, z) in get_caches_data(uid, r.text):
                        cache = get_object_or_none(Cach, pid=cid)

                        if cache:
                            the_log, created = LogRecommendCach.objects.get_or_create(
                                cacher_uid=uid, cach_pid=cid)

        log(UPDATE_TYPE.gcsu_logs_recommended, 'OK')
        return 'List of recommended caches has updated'
コード例 #2
0
    def handle(self, *args, **options):
        with requests.Session() as session:
            post = session.post('https://geocaching.su', data=LOGIN_DATA)

            r = session.get('https://geocaching.su')
            if not logged(r.text):
                print('Authorization failed')
            else:
                r = session.get('http://www.geocaching.su/',
                                params={'pn': 107})
                for uid in get_geocachers_uids(r.text):
                    r = session.get(
                        'http://www.geocaching.su/site/popup/userstat.php',
                        params={
                            's': 2,
                            'uid': uid
                        })
                    for (cid, found_date, grade,
                         x) in get_caches_data(uid, r.text):
                        cache = get_object_or_none(Cach, pid=cid)

                        if cache and found_date:
                            the_log, created = LogSeekCach.objects.get_or_create(
                                cacher_uid=uid, cach_pid=cid)
                            if created:
                                the_log.found_date = found_date
                                the_log.grade = grade
                                the_log.save()

        log(UPDATE_TYPE.gcsu_new_logs_found, 'OK')
        return 'List of found caches has updated'