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'
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'
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: for cache in Cach.objects.filter(author__isnull=True): r = session.get( 'http://www.geocaching.su/', params={'pn': 101, 'cid': cache.pid} ) author_uid = get_author(r.text) if author_uid: author = Geocacher.objects.filter( uid=int(author_uid)).first() if author: cache.author = author cache.save() print('saved', cache.pid, author_uid) else: print('not found author', author_uid) log(UPDATE_TYPE.set_caches_authors, 'OK') return 'Authors of caches have updated'
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: get_caches() log(UPDATE_TYPE.gcsu_caches, 'OK') return 'List of caches has updated'
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: last_cid = Cach.objects.all().aggregate( last_pid=Max('pid'))['last_pid'] get_caches(last_cid) log(UPDATE_TYPE.gcsu_new_caches, 'OK') return 'List of caches has updated'
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: for uid in range(200000): r = session.get( 'http://www.geocaching.su/profile.php?uid=%d' % uid) geocacher = get_user_profile(uid, r.text) if geocacher: print(uid, geocacher.id, geocacher.nickname) log(UPDATE_TYPE.gcsu_geocachers, 'OK') return 'List of geocachers has updated'
def handle(self, *args, **options): sql_batches = ('set_country_iso_for_geocachers.sql', 'set_admin_code_to_geocacher.sql', 'crimea.sql') for name in sql_batches: patch_it('sql/' + name) print(name, ' processed') 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: for uid in Geocacher.objects.filter( country_iso3__isnull=True).values_list('uid', flat=True): r = session.get( 'http://www.geocaching.su/site/popup/userstat.php', params={ 's': 2, 'uid': uid }) country = get_found_caches_countries(uid, r.text) set_country_code(uid, country) names = {''} for uid in Geocacher.objects.filter( admin_code__isnull=True).values_list('uid', flat=True): r = session.get( 'http://www.geocaching.su/site/popup/userstat.php', params={ 's': 2, 'uid': uid }) oblast = get_found_caches_oblast(uid, r.text) names.add(oblast) set_oblast_code(uid, oblast) log(UPDATE_TYPE.geocacher_patch, 'OK') return 'Geocachers data are updated'
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: #for cache in Cach.objects.filter( #country_code__isnull=True, #admin_code__isnull=True).order_by('pid'): #country = get_subdiv_data(cache.latitude, cache.longitude) ## print(cache.pid, cache.latitude, cache.longitude) #print(country) #if country and country.get('status') == 'ok': #cache.country_code = country['country_id'] #cache.country_name = country['country_name'] #cache.admin_code = country['sub_id'] #cache.oblast_name = country['sub_name'] #cache.save() #elif country.get('status') == 'limit': #break #for cache in Cach.objects.filter( #country_code__isnull=True #).order_by('pid'): #data = get_country_data(cache.latitude, cache.longitude) #print(data) #if data and data.get('status') == 'ok': #cache.country_code = data['country_iso'] #cache.country_name = geocountry_by_code( #data['country_iso']).name #cache.save() for cache in Cach.objects.filter( country_code__isnull=True).order_by('pid'): r = session.get('http://www.geocaching.su/', params={ 'pn': 101, 'cid': cache.pid }) country = get_country(r.text) print(country) if country: cache.country = country['country'] cache.oblast = country['region'] cache.save() for cache in Cach.objects.filter( admin_code__isnull=True).order_by('pid'): r = session.get('http://www.geocaching.su/', params={ 'pn': 101, 'cid': cache.pid }) country = get_country(r.text) print(country) if country: cache.country = country['country'] cache.oblast = country['region'] cache.save() log(UPDATE_TYPE.set_caches_locations, 'OK') return 'Location of caches has updated'