Example #1
0
def group_message():
    params = json.loads(dict(request.form)["params"])
    userId = dict(request.form)["userId"]
    accessToken = app.getServiceAccesToken(userId, "yammer")
    jsonResponse = {"direction": "column", "items": []}

    groupId = params["url"].split('?')[1].split('&')[1].split('=')[1]

    yammerResponse = json.loads(
        requests.get("https://www.yammer.com/api/v1/messages/in_group/" +
                     groupId + ".json?threaded=true",
                     headers={
                         "Authorization": "Bearer " + accessToken
                     }).content)
    for message in yammerResponse["messages"]:
        if "title" in message:
            jsonResponse["items"].append({
                "value":
                message["title"][:70] +
                "..." if len(message["title"]) >= 70 else message["title"],
                "link":
                message["web_url"]
            })
        else:
            jsonResponse["items"].append({
                "value":
                message["body"]["plain"][:70] +
                "..." if len(message["body"]["plain"]) >= 70 else
                message["body"]["plain"],
                "link":
                message["web_url"]
            })
        if len(jsonResponse["items"]) == int(params["number"]):
            break
    return jsonify(jsonResponse), status.HTTP_200_OK
Example #2
0
def activities():
    params = json.loads(dict(request.form)["params"])
    userId = dict(request.form)["userId"]
    accessToken = app.getServiceAccesToken(userId, "intra_epitech")
    jsonResponse = {
        "direction":
        "column",
        "items": [{
            "value": params["date"]
        }, {
            "span": 8,
            "value": {
                "direction": "column",
                "items": []
            }
        }]
    }

    intraResponse = json.loads(
        requests.get("https://intra.epitech.eu/" + accessToken +
                     "/planning/load?format=json&start=" + params["date"] +
                     "&end=" + params["date"]).content)
    for activity in intraResponse:
        if activity["event_registered"] != False:
            startHour = activity["start"].split(' ')[1].split(':')
            newActivity = {
                "direction":
                "row",
                "items": [{
                    "span": 2,
                    "value": activity["titlemodule"]
                }, {
                    "span": 2,
                    "value": activity["acti_title"]
                }, {
                    "value": ":".join([startHour[0], startHour[1]])
                }]
            }
            jsonResponse["items"][1]["value"]["items"].append(
                {"value": newActivity})
    jsonResponse["items"][1]["value"]["items"].sort(
        key=lambda x: x["value"]["items"][2]["value"])
    return jsonify(jsonResponse), status.HTTP_200_OK
Example #3
0
def year_grades():
    params = json.loads(dict(request.form)["params"])
    userId = dict(request.form)["userId"]
    accessToken = app.getServiceAccesToken(userId, "intra_epitech")
    jsonResponse = {
        "direction":
        "column",
        "items": [{
            "value": params["year"]
        }, {
            "span": 8,
            "value": {
                "direction": "column",
                "items": []
            }
        }]
    }

    intraResponse = json.loads(
        requests.get("https://intra.epitech.eu/" + accessToken +
                     "/user?format=json").content)
    userLogin = intraResponse["login"]

    intraResponse = json.loads(
        requests.get("https://intra.epitech.eu/" + accessToken + "/user/" +
                     userLogin + "/notes?format=json").content)
    for module in intraResponse["modules"]:
        if str(module["scolaryear"]
               ) == params["year"] and module["grade"] == params["grade"]:
            newGrade = {
                "direction":
                "row",
                "items": [{
                    "span": 2,
                    "value": module["title"]
                }, {
                    "value": "Grade " + module["grade"]
                }]
            }
            jsonResponse["items"][1]["value"]["items"].append(
                {"value": newGrade})
    return jsonify(jsonResponse), status.HTTP_200_OK
Example #4
0
def unregistered_instances():
    params = json.loads(dict(request.form)["params"])
    userId = dict(request.form)["userId"]
    accessToken = app.getServiceAccesToken(userId, "intra_epitech")
    jsonResponse = {
        "direction":
        "column",
        "items": [{
            "value": params["instance_type"]
        }, {
            "span": 8,
            "value": {
                "direction": "column",
                "items": []
            }
        }]
    }

    intraResponse = json.loads(
        requests.get("https://intra.epitech.eu/" + accessToken +
                     "/?format=json").content)
    for entity in intraResponse["board"][params["instance_type"]]:
        if entity["date_inscription"] != False:
            dateTimeOffset = datetime.strptime(
                entity["date_inscription"],
                "%d/%m/%Y, %H:%M") - datetime.now()
            nbDaysOffset = dateTimeOffset.total_seconds() / 3600 / 24
            newEntity = {
                "direction":
                "row",
                "items": [{
                    "span": 2,
                    "value": entity["title"]
                }, {
                    "value": str(int(nbDaysOffset)) + " days"
                }]
            }
            jsonResponse["items"][1]["value"]["items"].append(
                {"value": newEntity})
    return jsonify(jsonResponse), status.HTTP_200_OK
Example #5
0
def group_list():
    params = json.loads(dict(request.form)["params"])
    userId = dict(request.form)["userId"]
    accessToken = app.getServiceAccesToken(userId, "yammer")
    jsonResponse = {"direction": "column", "items": []}

    yammerResponse = json.loads(
        requests.get(
            "https://www.yammer.com/api/v1/users/by_email.json?email=" +
            params["email"],
            headers={
                "Authorization": "Bearer " + accessToken
            }).content)
    userId = yammerResponse[0]["id"]

    yammerResponse = json.loads(
        requests.get("https://www.yammer.com/api/v1/groups/for_user/" +
                     str(userId) + ".json",
                     headers={
                         "Authorization": "Bearer " + accessToken
                     }).content)
    for group in yammerResponse:
        newGroup = {
            "value": {
                "direction":
                "row",
                "items": [{
                    "span": 2,
                    "value": group["full_name"]
                }, {
                    "value": str(group["stats"]["members"]) + " members"
                }]
            },
            "link": group["web_url"]
        }
        jsonResponse["items"].append(newGroup)
    return jsonify(jsonResponse), status.HTTP_200_OK
Example #6
0
def binome_projects():
    params = json.loads(dict(request.form)["params"])
    userId = dict(request.form)["userId"]
    accessToken = app.getServiceAccesToken(userId, "intra_epitech")
    jsonResponse = {
        "direction":
        "column",
        "items": [{
            "value":
            params["firstname"].capitalize() + " " +
            params["lastname"].capitalize()
        }, {
            "span": 8,
            "value": {
                "direction": "column",
                "items": []
            }
        }]
    }

    intraResponse = json.loads(
        requests.get("https://intra.epitech.eu/" + accessToken +
                     "/user?format=json").content)
    userLogin = intraResponse["login"]

    intraResponse = json.loads(
        requests.get("https://intra.epitech.eu/" + accessToken + "/user/" +
                     userLogin + "/binome?format=json").content)
    for binome in intraResponse["binomes"]:
        if binome["login"] == params["firstname"].lower(
        ) + "." + params["lastname"].lower() + "@epitech.eu":
            projects = binome["activities"].split(',')
            for project in projects:
                jsonResponse["items"][1]["value"]["items"].append(
                    {"value": project})
    return jsonify(jsonResponse), status.HTTP_200_OK
Example #7
0
def netsoul():
    params = json.loads(dict(request.form)["params"])
    userId = dict(request.form)["userId"]
    accessToken = app.getServiceAccesToken(userId, "intra_epitech")
    jsonResponse = {
        "direction":
        "column",
        "items": [{
            "value": params["method"].capitalize()
        }, {
            "span": 8,
            "value": {
                "direction": "column",
                "items": []
            }
        }]
    }

    intraResponse = json.loads(
        requests.get("https://intra.epitech.eu/" + accessToken +
                     "/user?format=json").content)
    userLogin = intraResponse["login"]

    intraResponse = json.loads(
        requests.get("https://intra.epitech.eu/" + accessToken + "/user/" +
                     userLogin + "/netsoul?format=json").content)

    startDateTimeStamp = datetime.strptime(params["duration"][0],
                                           '%Y-%m-%d').timestamp()
    endDateTimeStamp = datetime.strptime(params["duration"][1],
                                         '%Y-%m-%d').timestamp()

    startDateIndex = 0
    endDateIndex = len(intraResponse) - 1

    for (index, netsoul) in enumerate(intraResponse):
        if netsoul[0] == int(startDateTimeStamp):
            startDateIndex = index
        elif netsoul[0] == int(endDateTimeStamp):
            endDateIndex = index
            break

    netsoulList = intraResponse[startDateIndex:endDateIndex + 1]
    netsoulList.reverse()

    if params["method"] == "daily":
        for i in range(0, len(netsoulList), 1):
            date = datetime.fromtimestamp(
                netsoulList[i][0]).strftime("%Y-%m-%d")
            newNetsoul = {
                "direction":
                "row",
                "items": [{
                    "span": 2,
                    "value": date
                }, {
                    "value":
                    str(round(netsoulList[i][1] / 3600)) + " hours"
                }]
            }
            jsonResponse["items"][1]["value"]["items"].append(
                {"value": newNetsoul})
    elif params["method"] == "weekly":
        for i in range(0, len(netsoulList), 7):
            lastDate = datetime.fromtimestamp(
                netsoulList[i][0]).strftime("%Y-%m-%d")
            firstDate = datetime.fromtimestamp(
                netsoulList[i + 6 if i +
                            6 < len(netsoulList) else len(netsoulList) -
                            1][0]).strftime("%Y-%m-%d")
            newNetsoul = {
                "direction":
                "row",
                "items": [{
                    "span": 2,
                    "value": firstDate + " - " + lastDate
                }, {
                    "value":
                    str(
                        round(
                            sum([
                                netsoulList[i + x][1]
                                if i + x < len(netsoulList) else 0
                                for x in range(0, 7)
                            ]) / 3600)) + " hours"
                }]
            }
            jsonResponse["items"][1]["value"]["items"].append(
                {"value": newNetsoul})
    elif params["method"] == "monthly":
        print("TOTO")
        for i in range(0, len(netsoulList), 31):
            lastDate = datetime.fromtimestamp(
                netsoulList[i][0]).strftime("%Y-%m-%d")
            firstDate = datetime.fromtimestamp(
                netsoulList[i + 29 if i +
                            29 < len(netsoulList) else len(netsoulList) -
                            1][0]).strftime("%Y-%m-%d")
            newNetsoul = {
                "direction":
                "row",
                "items": [{
                    "span": 2,
                    "value": firstDate + " - " + lastDate
                }, {
                    "value":
                    str(
                        round(
                            sum([
                                netsoulList[i + x][1]
                                if i + x < len(netsoulList) else 0
                                for x in range(0, 31)
                            ]) / 3600)) + " hours"
                }]
            }
            jsonResponse["items"][1]["value"]["items"].append(
                {"value": newNetsoul})
    return jsonify(jsonResponse), status.HTTP_200_OK
Example #8
0
def ban_events():
    params = json.loads(dict(request.form)["params"])
    userId = dict(request.form)["userId"]
    accessToken = app.getServiceAccesToken(userId, "twitch")
    jsonResponse = {
        "direction":
        "column",
        "items": [{
            "value": params["user"]
        }, {
            "span": 8,
            "value": {
                "direction": "column",
                "items": []
            }
        }]
    }

    twitchResponse = json.loads(
        requests.get("https://api.twitch.tv/helix/users",
                     headers={
                         "Authorization": "Bearer " + accessToken
                     }).content)
    broadcasterId = twitchResponse["data"][0]["id"]

    twitchResponse = json.loads(
        requests.get("https://api.twitch.tv/helix/users?login="******"user"],
                     headers={
                         "Authorization": "Bearer " + accessToken
                     }).content)
    userId = twitchResponse["data"][0]["id"]

    twitchResponse = json.loads(
        requests.get(
            "https://api.twitch.tv/helix/moderation/banned/events?broadcaster_id="
            + broadcasterId + "&user_id=" + userId,
            headers={
                "Authorization": "Bearer " + accessToken
            }).content)

    for event in twitchResponse["data"]:
        eventType = ""
        if event["event_type"] == "moderation.user.ban":
            eventType = "Banned"
        elif event["event_type"] == "moderation.user.unban":
            eventType = "Unbanned"
        newEvent = {
            "direction":
            "row",
            "items": [{
                "span":
                2,
                "value":
                datetime.strptime(
                    event["event_timestamp"],
                    "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d %H:%M:%S")
            }, {
                "value": eventType
            }]
        }
        jsonResponse["items"][1]["value"]["items"].append({"value": newEvent})

    return jsonify(jsonResponse), status.HTTP_200_OK