def get_destination_id(self, name): destinations_url = f"https://back.eurolines.eu/euroline_api/origins?q={name}" r = HTMLSession().get(destinations_url) json = r.json() if len(json) == 0: raise DestinationException( f"Destination {name} not found in Eurolines module") d = json[0] self.destinations_by_name[d["name"]] = d["id"] self.destinations_by_name[d["id"]] = d["name"] return d["id"]
def check_user(ids): TAG = "user checker" user_ids = ",".join(str(e) for e in ids) get_link = vk_api_link + "users.get?user_ids=" + str(user_ids) + "&fields=sex,online,last_seen&access_token=" + \ access_token + "&v=" + v + "&lang=ru" ms = int(round(time.time() * 1000)) content = HTMLSession().get(get_link) json = content.json() countMillis = int(round(time.time() * 1000)) - ms sex = [["была в сети", "был в сети"], ["в сети", "в сети"]] device = [ "с мобильного", "с iPhone", "с iPad", "с Android", "с Windows Phone", "с Windows 10", "с ПК", "с VK Mobile" ] log("br", "") title_mes = "" user_online = 0 for i in range(num_of_user): userinfo = json["response"][i] userstat = userinfo["last_seen"] nameofuser = userinfo["first_name"] + " " + userinfo["last_name"] user_id = userinfo["id"] ms_time = time.gmtime(int(userstat["time"]) + 10800) log( "online", nameofuser + " " + sex[int(userinfo["online"])][int(userinfo["sex"]) - 1] + " " + device[int(userstat["platform"]) - 1] + ", " + time.strftime("%d %b %Y %H:%M:%S", ms_time)) if int(userinfo["online"]): user_online += 1 user_state.labels(id=user_id).set(1) else: user_state.labels(id=user_id).set(0) if len(users) > 1: title_mes = str(num_of_user) + " наблюдаемых / " + str( user_online) + " в сети" else: title_mes = nameofuser + " " + sex[int(userinfo["online"])][int(userinfo["sex"]) - 1] + \ " " + device[int(userstat["platform"])-1] + ", " + time.strftime("%H:%M:%S", ms_time) log("br", "") title_ch(title_mes) log(TAG, "Задержка " + str(countMillis) + " мс.")