Esempio n. 1
0
def newCard(session):
    account = UserReqs.authRefreshStatus(session)
    if not account:
        return

    userId = account["id"]
    boxId = None
    result = UserReqs.userBoxes(session, userId)
    if result and result["boxes"] and utils.maybeHappen():
        boxId = random.choice(result["boxes"])["id"]

    if boxId is None and utils.maybeHappen():
        box = BoxReqs.newBox(session, {})
        if box:
            boxId = box["id"]

    cardData = {"boxId": boxId}

    places = SearchReqs.searchPlaces(session, utils.randomWord(), 0)
    if places:
        selectedPlaces = [random.choice(places) for i in range(random.randint(1, len(places)))]
        destinations = [place["destination"] for place in selectedPlaces if "destination" in place]
        destinationId = destinations[0]["id"] if destinations else None
        poiIds = [place["poi"]["id"] for place in selectedPlaces] if not destinationId else None
        if destinationId:
            cardData.update({"type": 2, "destination": destinationId})
        elif poiIds:
            cardData.update({"type": 1, "pois": "|".join(list(set(poiIds)))})

    CardReqs.newCard(session, cardData)
Esempio n. 2
0
def cardDetail(session, cardId):
    result = {"cards": [], "boxes": [], "pois": [], "destinations": []}

    card = CardReqs.getCard(session, cardId)
    if not card:
        return result

    if card.get("pois"):
        result["pois"] = [poi["id"] for poi in card["pois"]]

    if card.get("destination"):
        result["destinations"] = [card["destination"]["id"]]

    CardReqs.getCardComments(session, cardId)
    cards = CardReqs.getRelatedCards(session, cardId)
    if cards:
        result["cards"] = [card["id"] for card in cards]

    boxes = CardReqs.getRelatedBoxes(session, cardId)
    if boxes:
        result["boxes"] = [box["id"] for box in boxes]

    if utils.isAnonymous(session):
        return result

    followed = UserReqs.userFollowed(session, card["owner"]["id"])
    if not followed and utils.rarelyHappen():
        gevent.sleep(1)
        UserReqs.followUser(session, card["owner"]["id"])

    if not card["liked"] and utils.rarelyHappen():
        gevent.sleep(1)
        CardReqs.likeCard(session, cardId)

    account = UserReqs.authRefreshStatus(session)
    if not account:
        return result

    if not card["clipped"] and utils.rarelyHappen():
        gevent.sleep(1)

        userId = account["id"]
        boxId = None
        data = UserReqs.userBoxes(session, userId)
        if data and data["boxes"] and utils.maybeHappen():
            boxId = random.choice(data["boxes"])["id"]

        if boxId is None and utils.maybeHappen():
            box = BoxReqs.newBox(session, {})
            if box:
                boxId = box["id"]

        CardReqs.clipCard(session, cardId, boxId)

    return result
Esempio n. 3
0
def cardDetail(session, cardId):
    result = {"cards": [], "boxes": [], "pois": [], "destinations": []}

    card = CardReqs.getCard(session, cardId)
    if not card:
        return result

    if card.get("pois"):
        result["pois"] = [poi["id"] for poi in card["pois"]]

    if card.get("destination"):
        result["destinations"] = [card["destination"]["id"]]

    CardReqs.getCardComments(session, cardId)
    cards = CardReqs.getRelatedCards(session, cardId)
    if cards:
        result["cards"] = [card["id"] for card in cards]

    boxes = CardReqs.getRelatedBoxes(session, cardId)
    if boxes:
        result["boxes"] = [box["id"] for box in boxes]

    if utils.isAnonymous(session):
        return result

    followed = UserReqs.userFollowed(session, card["owner"]["id"])
    if not followed and utils.rarelyHappen():
        gevent.sleep(1)
        UserReqs.followUser(session, card["owner"]["id"])

    if not card["liked"] and utils.rarelyHappen():
        gevent.sleep(1)
        CardReqs.likeCard(session, cardId)

    account = UserReqs.authRefreshStatus(session)
    if not account:
        return result

    if not card["clipped"] and utils.rarelyHappen():
        gevent.sleep(1)

        userId = account["id"]
        boxId = None
        data = UserReqs.userBoxes(session, userId)
        if data and data["boxes"] and utils.maybeHappen():
            boxId = random.choice(data["boxes"])["id"]

        if boxId is None and utils.maybeHappen():
            box = BoxReqs.newBox(session, {})
            if box:
                boxId = box["id"]

        CardReqs.clipCard(session, cardId, boxId)

    return result
Esempio n. 4
0
def destinationDetial(session, destId):
    DestinationReqs.getDestination(session, destId)

    result = {"cards": [], "users": [], "boxes": []}

    cardIds, userIds, boxIds, hasMore = [], [], [], False
    data = DestinationReqs.destinationCards(session, destId)
    if data:
        cardIds = [card["id"] for card in data["cards"]]
        userIds = [card["owner"]["id"] for card in data["cards"]]
        boxIds = [
            card["box"]["id"] for card in data["cards"] if card.get("box")
        ]
        hasMore = data["hasMore"]

    while hasMore and utils.maybeHappen():
        data = DestinationReqs.destinationCards(session,
                                                destId,
                                                last=cardIds[-1])
        if data:
            cardIds.extend([card["id"] for card in data["cards"]])
            userIds.extend([card["owner"]["id"] for card in data["cards"]])
            boxIds.extend([
                card["box"]["id"] for card in data["cards"] if card.get("box")
            ])
            hasMore = data["hasMore"]
        else:
            hasMore = False

    result["cards"] = cardIds
    result["users"] = userIds
    result["boxes"] = boxIds

    return result
Esempio n. 5
0
def poiDetail(session, poiId):
    PoiReqs.getPoi(session, poiId)

    result = {"cards": [], "pois": []}

    cardIds, hasMore = [], False
    data = PoiReqs.poiCards(session, poiId)
    if data:
        cardIds = [card["id"] for card in data["cards"]]
        hasMore = data["hasMore"]

    while hasMore and utils.maybeHappen():
        data = PoiReqs.poiCards(session, poiId, last=cardIds[-1])
        if data:
            cardIds.extend([card["id"] for card in data["cards"]])
            hasMore = data["hasMore"]
        else:
            hasMore = False

    result["cards"] = cardIds

    pois = PoiReqs.poiRecommendPois(session, poiId)
    if pois:
        result["pois"] = [poi["id"] for poi in pois]

    return result
Esempio n. 6
0
def destinationDetial(session, destId):
    DestinationReqs.getDestination(session, destId)

    result = {"cards": [], "users": [], "boxes": []}

    cardIds, userIds, boxIds, hasMore = [], [], [], False
    data = DestinationReqs.destinationCards(session, destId)
    if data:
        cardIds = [card["id"] for card in data["cards"]]
        userIds = [card["owner"]["id"] for card in data["cards"]]
        boxIds = [card["box"]["id"] for card in data["cards"] if card.get("box")]
        hasMore = data["hasMore"]

    while hasMore and utils.maybeHappen():
        data = DestinationReqs.destinationCards(session, destId, last=cardIds[-1])
        if data:
            cardIds.extend([card["id"] for card in data["cards"]])
            userIds.extend([card["owner"]["id"] for card in data["cards"]])
            boxIds.extend([card["box"]["id"] for card in data["cards"] if card.get("box")])
            hasMore = data["hasMore"]
        else:
            hasMore = False

    result["cards"] = cardIds
    result["users"] = userIds
    result["boxes"] = boxIds

    return result
Esempio n. 7
0
def backpackPage(session, backpackId):
    result = {"cards": [], "pois": [], "destinations": []}

    data = BackpackReqs.backpackDetail(session, backpackId)
    if not data:
        return result

    content = data["content"]

    if content.get("poiCards"):
        result["cards"] = [card["id"] for poiCard in content["poiCards"] if poiCard for card in poiCard.get("cards", [])]
        result["pois"] = [poiCard["poi"]["id"] for poiCard in content["poiCards"] if poiCard]

    if content.get("destinationCards"):
        result["cards"].extend([card["id"] for destinationCard in content.get("destinationCards", []) for card in destinationCard.get("cards", [])])
        result["destinations"] = [city["city"]["id"] for destinationCard in content.get("destinationCards", []) for city in destinationCard.get("cities", [])]

    if utils.isAnonymous(session):
        return result

    if utils.maybeHappen():
        cloned = BackpackReqs.backpackCloned(session, backpackId)
        if not cloned:
            BackpackReqs.backpackClone(session, backpackId)

    return result
Esempio n. 8
0
    def on_start(self):
        a = requests.adapters.HTTPAdapter(max_retries=3)
        self.client.mount('http://', a)

        if utils.maybeHappen():
            user = utils.getNextUser("explore")
            token = UserBehavior.userLogin(self.client, user["email"], user["password"])
            if token:
                self.client.headers["Authorization"] = "Token {}".format(token)

        self.explore(self.client)
Esempio n. 9
0
    def on_start(self):
        a = requests.adapters.HTTPAdapter(max_retries=3)
        self.client.mount('http://', a)

        if utils.maybeHappen():
            user = utils.getNextUser("explore")
            token = UserBehavior.userLogin(self.client, user["email"],
                                           user["password"])
            if token:
                self.client.headers["Authorization"] = "Token {}".format(token)

        self.explore(self.client)
Esempio n. 10
0
def newCard(session):
    account = UserReqs.authRefreshStatus(session)
    if not account:
        return

    userId = account["id"]
    boxId = None
    result = UserReqs.userBoxes(session, userId)
    if result and result["boxes"] and utils.maybeHappen():
        boxId = random.choice(result["boxes"])["id"]

    if boxId is None and utils.maybeHappen():
        box = BoxReqs.newBox(session, {})
        if box:
            boxId = box["id"]

    cardData = {"boxId": boxId}

    places = SearchReqs.searchPlaces(session, utils.randomWord(), 0)
    if places:
        selectedPlaces = [
            random.choice(places)
            for i in range(random.randint(1, len(places)))
        ]
        destinations = [
            place["destination"] for place in selectedPlaces
            if "destination" in place
        ]
        destinationId = destinations[0]["id"] if destinations else None
        poiIds = [place["poi"]["id"]
                  for place in selectedPlaces] if not destinationId else None
        if destinationId:
            cardData.update({"type": 2, "destination": destinationId})
        elif poiIds:
            cardData.update({"type": 1, "pois": "|".join(list(set(poiIds)))})

    CardReqs.newCard(session, cardData)
Esempio n. 11
0
def userHome(session, userId):
    UserReqs.userInfo(session, userId)

    cardIds, hasMore = [], False
    data = UserReqs.userCards(session, userId)
    if data:
        cardIds = [card["id"] for card in data["cards"]]
        hasMore = data["hasMore"]

    while hasMore and utils.maybeHappen():
        data = UserReqs.userCards(session, userId, last=cardIds[-1])
        if data:
            cardIds.extend([card["id"] for card in data["cards"]])
            hasMore = data["hasMore"]
        else:
            hasMore = False

    boxIds, hasMore = [], False
    data = UserReqs.userBoxes(session, userId)
    if data:
        boxIds = [box["id"] for box in data["boxes"]]
        hasMore = data["hasMore"]

    while hasMore and utils.maybeHappen():
        data = UserReqs.userBoxes(session, userId, last=boxIds[-1])
        if data:
            boxIds.extend([box["id"] for box in data["boxes"]])
            hasMore = data["hasMore"]
        else:
            hasMore = False

    backpackIds = []
    backpacks = UserReqs.userBackpacks(session, userId)
    if backpacks:
        backpackIds = [backpack["id"] for backpack in backpacks]

    return {"cards": cardIds, "boxes": boxIds, "backpacks": backpackIds}
Esempio n. 12
0
def boxHome(session, boxId):
    BoxReqs.boxInfo(session, boxId)

    cardIds, hasMore = [], False
    data = BoxReqs.boxCards(session, boxId)
    if data:
        cardIds = [card["id"] for card in data["cards"]]
        hasMore = data["hasMore"]

    while hasMore and utils.maybeHappen():
        data = BoxReqs.boxCards(session, boxId, last=cardIds[-1])
        if data:
            cardIds.extend([card["id"] for card in data["cards"]])
            hasMore = data["hasMore"]
        else:
            hasMore = False

    return {"cards": cardIds}
Esempio n. 13
0
def backpackPage(session, backpackId):
    result = {"cards": [], "pois": [], "destinations": []}

    data = BackpackReqs.backpackDetail(session, backpackId)
    if not data:
        return result

    content = data["content"]

    if content.get("poiCards"):
        result["cards"] = [
            card["id"] for poiCard in content["poiCards"] if poiCard
            for card in poiCard.get("cards", [])
        ]
        result["pois"] = [
            poiCard["poi"]["id"] for poiCard in content["poiCards"] if poiCard
        ]

    if content.get("destinationCards"):
        result["cards"].extend([
            card["id"]
            for destinationCard in content.get("destinationCards", [])
            for card in destinationCard.get("cards", [])
        ])
        result["destinations"] = [
            city["city"]["id"]
            for destinationCard in content.get("destinationCards", [])
            for city in destinationCard.get("cities", [])
        ]

    if utils.isAnonymous(session):
        return result

    if utils.maybeHappen():
        cloned = BackpackReqs.backpackCloned(session, backpackId)
        if not cloned:
            BackpackReqs.backpackClone(session, backpackId)

    return result