Пример #1
0
    def __get_suggestions(category: Category, search_word: str, locale: str,
                          max_results: int, request: Request,
                          debug: bool) -> List[str]:
        import time
        from kcu import request

        url = 'https://completion.amazon.com/api/2017/suggestions?lop={}&site-variant=desktop&client-info=amazon-search-ui&mid=ATVPDKIKX0DER&alias={}&ks=65&prefix={}&event=onKeyPress&limit=11&fb=1&suggestion-type=KEYWORD&_={}'.format(
            locale, category.value, search_word, int(time.time()))
        suggestions = []

        try:
            j = request.get(url, debug=debug).json()

            for suggestion in j['suggestions']:
                suggestion = suggestion['value']

                if suggestion not in suggestions:
                    suggestions.append(suggestion)

                    if len(suggestions) >= max_results:
                        return suggestions

            return suggestions
        except Exception as e:
            if debug:
                print(e)

            return suggestions


# ---------------------------------------------------------------------------------------------------------------------------------------- #
Пример #2
0
    def __get_posts(
        cls,
        sub: str,
        time_interval: Optional[TimeInterval],
        sorting_type: Optional[SortingType],
        after: Optional[str],
        fake_useragent: bool
    ) -> Tuple[Optional[List[Post]], Optional[str]]:
        url = cls.__sub_url(sub, time_interval, sorting_type, after)

        try:
            import json

            j = json.loads(request.get(url, fake_useragent=fake_useragent).text)

            return [Post(post_json['data']) for post_json in j['data']['children']], j['data']['after']
        except:
            traceback.print_exc()

            return None, None
Пример #3
0
    def __get_images(base_url: str, max: int, json_key: str,
                     user_agent: Optional[str],
                     debug: bool) -> List[UnsplashImage]:
        images = []

        base_url += ('?' if '?' not in base_url else '&') + 'per_page=30&page='
        page = 0

        while len(images) < max:
            page += 1

            try:
                url = base_url + str(page)
                elements = request.get(url, user_agent=user_agent,
                                       debug=debug).json()[json_key]

                if len(elements) == 0:
                    return images

                for e in elements:
                    try:
                        images.append(UnsplashImage(e))
                    except Exception as e:
                        if debug:
                            print(e)

                    if len(images) >= max:
                        return images
            except Exception as e:
                if debug:
                    print(e)

                return images

        return images


# ---------------------------------------------------------------------------------------------------------------------------------------- #
Пример #4
0
    def get_inbox(email_address: str,
                  fake_useragent: bool = False) -> Optional[List[Email]]:
        try:
            email_dicts = request.get(
                'https://api.internal.temp-mail.io/api/v3/email/{}/messages'.
                format(email_address),
                fake_useragent=fake_useragent).json()
            emails = []

            for email_dict in email_dicts:
                try:
                    emails.append(Email.from_dict(email_dict))
                except Exception as e:
                    print(email_dict)
                    print(e)

                    pass

            return emails
        except Exception as e:
            print(e)

            return None
Пример #5
0
    def get_post(
        cls,
        post_id: str,
        sorting_type: SortingType = SortingType.TOP,
        comments_min_score: int = 50,
        comments_include_stickied: bool = False,
        comments_min_ts: int = 0,
        fake_useragent: bool = True
    ) -> Optional[Post]:
        url = cls.__post_url(post_id, sorting_type)

        try:
            import json

            j = json.loads(request.get(url, debug=True, fake_useragent=fake_useragent).text)

            post = Post(j[0]['data']['children'][0]['data'], j[1]['data']['children'])
            post.comments = cls.__filtered_comments(post.comments, comments_min_score, comments_include_stickied, comments_min_ts)

            return post
        except:
            traceback.print_exc()

            return None
Пример #6
0
    def get_domains(fake_useragent: bool = False) -> Optional[List[Domain]]:
        try:
            domain_dicts = request.get(
                'https://api.internal.temp-mail.io/api/v3/domains',
                fake_useragent=fake_useragent).json()
            domains = []

            for domain_dict in domain_dicts:
                try:
                    domains.append(Domain.from_dict(domain_dict))
                except Exception as e:
                    print(domain_dict)
                    print(e)

                    pass

            return domains
        except Exception as e:
            print(e)

            return None


# ---------------------------------------------------------------------------------------------------------------------------------------- #