def update_listing_cache(request): form_info = datastore_get("Form", "form", FORM_EXPIRE_TIME) if not form_info: form_info = get_search_form() datastore_set("Form", "form", form_info.json()) form_info_cache = SearchForm.parse_raw(form_info.get('data')) # Splits hour into 10 possible indexes mn_idx = datetime.now(timezone.utc).minute // 6 # Multiply by the total possible indexes of mn_idx hr_idx = datetime.now(timezone.utc).hour * 10 hash_index = ((mn_idx + hr_idx) % len(form_info_cache.clean_departments)) # Skip over ALL department if hash_index == 0: return params = { 'YearTerm': form_info_cache.clean_terms[0], 'Dept': form_info_cache.clean_departments[hash_index], 'force': True } try: requests.get(f'{ZOTCOURSE_BASE_URL}/search', params=params, timeout=0.001) except Exception: return
def update_listing_cache_alt(request): form_info = datastore_get("Form", "form", FORM_EXPIRE_TIME) if not form_info: form_info = get_search_form() datastore_set("Form", "form", form_info.json()) form_info_cache = SearchForm.parse_raw(form_info.get('data')) for department in form_info_cache.clean_departments: if department.strip() == 'ALL': continue params = { 'YearTerm': form_info_cache.clean_terms[0], 'Dept': department, 'force': True } try: requests.get(f'{ZOTCOURSE_BASE_URL}/search', params=params, timeout=0.001) except Exception: continue