def updateServers(self): self.servers = [] count = 0 response = jsonRequests.getResponse( "https://api.status.salesforce.com/v1/instances/status") if response.status: jsonData = response.data self.servers = [] for server in jsonData: if server["status"] != "OK": try: s = Server(server["key"], server["status"]) self.servers.append(s) except: continue if len(self.servers) == 0: self.statusString = "All servers operational." self.affectedServers = "" self.ids.status.pos_hint = {"top": .7} else: issues = {svr.status.upper() for svr in self.servers} self.statusString = "Servers are impacted." if "MINOR_INCIDENT_CORE" in issues: self.statusString = "Minor incident." if "MAJOR_INCIDENT_CORE" in issues: self.statusString = "Major incident." self.affectedServers = makeServersString( [svr.name for svr in self.servers], 8) self.ids.status.pos_hint = {"top": .9} else: Logger.error("Salesforce Status: Couldn't get latest calendar: " + response.message)
def updateData(self): url = "https://api.nytimes.com/svc/topstories/v2/" + self.location + ".json?api-key=" + self.key response = jsonRequests.getResponse(url) if response.status: jsonData = response.data result = jsonData["results"][0] if self.stringDict != None: # If a stringDict is wired up, then find an article not yet shown. count = 0 while jsonData["results"][count]["title"].lower( ) in self.stringDict.values(): count += 1 result = jsonData["results"][count] self.stringDict[self.id] = result["title"].lower() title = result["title"] img = "" for m in result["multimedia"]: if m["format"] == "superJumbo": img = m["url"] if img != self.article_source: self.article_source = img self.article_headline = title self.article_link = result["url"] self.qr_link = "https://api.qrserver.com/v1/create-qr-code/?data=" + self.article_link else: Logger.error("NewsApp: Couldn't get news: " + response.message)
def getJsonData(): url = "https://www.softwareanywhere.com/services/apexrest/TimeSlips" response = jsonRequests.getResponse(url) if response.status: parsed = json.loads(response.raw.decode('string-escape').strip('"')) return parsed else: return False
def updateData(self): url = "https://www.softwareanywhere.com/services/apexrest/TimeSlips" response = jsonRequests.getResponse(url) if response.status: if response.raw != self.lastValidData: Logger.info("Time Slips App: Time Slips Changed.") parsed = json.loads( response.raw.decode('string-escape').strip('"')) TimeSlipGraphUtility.saveImage(parsed, "timeSlips.png") self.lastValidData = response.raw self.img.source = "timeSlips.png" self.img.reload()
def getWeather(location): global oldWeather # Using Weather.gov's API. forecast_url = "https://api.weather.gov/gridpoints/SGX/43,50/forecast" observation_url = "https://api.weather.gov/stations/E2061/observations/latest" observation_response = jsonRequests.getResponse(observation_url) temp = 0 if observation_response.status: try: jsonData = observation_response.data temp = celsiusToFahrenheit(jsonData["properties"]["temperature"]["value"]) except Exception as e: print(e) oldWeather = "Could not get weather." return oldWeather forecast_response = jsonRequests.getResponse(forecast_url) high = 0 low = 0 if forecast_response.status: try: jsonData = forecast_response.data if jsonData["properties"]["periods"][0]["isDaytime"]: high = jsonData["properties"]["periods"][0]["temperature"] low = jsonData["properties"]["periods"][1]["temperature"] else: high = jsonData["properties"]["periods"][1]["temperature"] low = jsonData["properties"]["periods"][2]["temperature"] except Exception as e: print(e) oldWeather = "Could not get weather." return oldWeather oldWeather = str(int(round(temp))) + " F | " + str(high) + " / " + str(low) return oldWeather
def getWeather_app(location): return None, None baseurl = "https://query.yahooapis.com/v1/public/yql?q=" query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="'+location+'")' form = "&format=json" response = jsonRequests.getResponse(baseurl+query+form) if response.status: jsonData = response.data item = jsonData["query"]["results"]["channel"]["item"] forecast=item["forecast"] condition=item["condition"] else: Logger.error("Weather Module: Had issues: "+response.message) return forecast, condition
def updateData(self): baseurl = "https://query.yahooapis.com/v1/public/yql?q=" query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="' + self.location + '")' form = "&format=json" response = jsonRequests.getResponse(baseurl + query + form) if response.status: jsonData = response.data try: item = jsonData["query"]["results"]["channel"]["item"] except: Logger.error("Weather App: jsonData was invalid.") return forecast = item["forecast"] condition = item["condition"] fc = forecast[0] temp = condition["temp"] cond = weathercodes.code_strings[condition["code"]] high = fc["high"] low = fc["low"] string = temp + " F | " + cond + " | " + high + " / " + low self.current_weather = string for i in range(1, 6): fc = forecast[i] widget = self.ids["day_" + str(i)] img = "./weather_icons/" + weathercodes.weathercodes[ fc["code"]] widget.condition = img widget.day = weathercodes.days[fc["day"].encode( 'utf-8').lower()] widget.high = fc["high"] widget.low = fc["low"] else: Logger.error("WeatherApp: Couldn't update data: " + response.message)
def getTrafficTime(self, origin, destinations, api_key): d_query = "|".join(["+".join(x.split(" ")) for x in destinations]) #print(d_query) Logger.info("Traffic Time App: Loading times.") url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins="+("+".join(origin.split(" ")))+"&destinations="+d_query+"&departure_time=now&key="+self.api_key response = jsonRequests.getResponse(url) output = None if response.status: output = {} rows = response["rows"][0]["elements"] for i in range(len(self.destinations)): dest = self.destinations[i] row = rows[i] duration = -1 if "duration_in_traffic" in row: duration = row["duration_in_traffic"]["text"] output[dest] = duration else: Logger.error("TrafficTimeApp: Failed to get latest traffic time: "+response.message) return output
def updateCalendar(self): response = jsonRequests.getResponse( "https://api.status.salesforce.com/v1/maintenances?startTime=" + time.strftime("%Y-%m-%d")) if response.status: jsonData = response.data evts = {} for evt in jsonData: name = evt["name"] timeString = evt["plannedStartTime"] start = time.strptime(timeString, "%Y-%m-%dT%H:%M:%S.000Z") if timeString + name not in evts: evts[timeString + name] = Event(name, set(evt["instanceKeys"]), start) else: for server in list(evt["instanceKeys"]): evts[timeString + name].instances.add(server) self.evts = list(evts.values()) self.evts.sort(key=lambda x: x.startTime) else: Logger.error( "Salesforce status: Couldn't get the latest status: " + response.message) for i in range(3): e = self.evts[i] box = self.ids["evt_" + str(i)] box.eventName = time.strftime("%m/%d/%y: ", e.startTime) + e.name svrs = [] for name in e.instances: try: svrs.append(Server(name, "")) except: continue svrs.sort() box.servers = makeServersString([svr.name for svr in svrs], 6)
def updateData(self): baseurl = "https://query.yahooapis.com/v1/public/yql?q=" query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="' + self.location + '")' form = "&format=json" r = jsonRequests.getResponse(baseurl + query + form) if r.status: item = r["query"]["results"]["channel"]["item"] condition = item["condition"] forecasts = item["forecast"] todayFC = forecasts[0] self.forecastString = todayFC["high"] + " / " + todayFC[ "low"] + " " + weatherCodes.codes[todayFC["code"]] self.currentConditions = condition[ "temp"] + " | " + weatherCodes.codes[condition["code"]] self.day1 = forecasts[1]["day"] + " | " + forecasts[1][ "high"] + " / " + forecasts[1][ "low"] + " " + weatherCodes.codes[forecasts[1]["code"]] self.day2 = forecasts[2]["day"] + " | " + forecasts[2][ "high"] + " / " + forecasts[2][ "low"] + " " + weatherCodes.codes[forecasts[2]["code"]] self.day3 = forecasts[3]["day"] + " | " + forecasts[3][ "high"] + " / " + forecasts[3][ "low"] + " " + weatherCodes.codes[forecasts[3]["code"]] self.day4 = forecasts[4]["day"] + " | " + forecasts[4][ "high"] + " / " + forecasts[4][ "low"] + " " + weatherCodes.codes[forecasts[4]["code"]] self.day5 = forecasts[5]["day"] + " | " + forecasts[5][ "high"] + " / " + forecasts[5][ "low"] + " " + weatherCodes.codes[forecasts[5]["code"]] else: Logger.Error("WeatherApp: Had trouble getting weather.")
if __name__ == "__main__": s1 = Server("NA01", "OK") s2 = Server("NA02", "OK") s3 = Server("CS02", "OK") print(s1) print(s2) print(s1 < s2) print(s2 < s1) print(s3 < s2) print(s2 < s3) servers = [] count = 0 response = jsonRequests.getResponse( "https://api.status.salesforce.com/v1/instances/status") if response.status: jsonData = response.data for server in jsonData: try: s = Server(server["key"], server["status"]) servers.append(s) except: continue servers.sort() for server in servers: print(server) print(len(servers)) print("Getting upcoming events...")