def post_yak(self, message, handle=None, btp=False, basecamp=False): """Post a Yak with optional handle (optionally at basecamp and optionally with parameter bypassedThreatPopup as btp). Return the Yak once loaded (or None if not posted)""" self._validate_basecamp(basecamp) raw = yikyakapi.send_message(self, message, handle, btp, basecamp) # Yaks only post if get_messages is called directly after yikyakapi.get_messages(self, self.location, basecamp=basecamp) self.update() # If success is reported if bool(int(raw.text)): try: return self.get_yaks(basecamp=basecamp)[0] except IndexError: return None else: return None
def get_yaks(self, location=None, basecamp=False): """Return a list of Yaks at particular location (optionally at basecamp)""" # Set location if not None, otherwise set to user's location location = location if location else self.location self._validate_basecamp(basecamp) raw = yikyakapi.get_messages(self, location, basecamp) return self._get_yak_list(raw)
def update(self): """Update Yakarma and basecamp information""" raw = yikyakapi.get_messages(self, self.location, basecamp=True) # Check if too close to school self._get_yak_list(raw) try: self.yakarma = int(raw.json()["yakarma"]) except (KeyError, ValueError): raise ParsingResponseError("Getting Yakarma failed", raw) try: self.basecamp_set = bool(int(raw.json()["bcEligible"])) except (KeyError, ValueError): raise ParsingResponseError("Getting bcEligible failed", raw) try: latitude = float(raw.json()["bcLat"]) longitude = float(raw.json()["bcLong"]) self.basecamp_name = raw.json()["bcName"] self.basecamp_location = Location(latitude, longitude) except (KeyError, ValueError): pass
def get_other_peek_locations(self): """Return a list of other peek locations""" raw = yikyakapi.get_messages(self, self.location) return self._get_peek_location_list(raw, "otherLocations")
def get_featured_peek_locations(self): """Return a list of featured peek locations""" raw = yikyakapi.get_messages(self, self.location) return self._get_peek_location_list(raw, "featuredLocations")