Exemplo n.º 1
0
    def get_packt_free_book(self):
        date_from = datetime.datetime.utcnow().date()
        date_to = date_from + datetime.timedelta(days=1)

        # Primeira requisição obtém o ID do livro do dia
        r = requests.get(
            url="https://services.packtpub.com/free-learning-v1/offers",
            params={
                "dateFrom": date_from.strftime("%Y-%m-%dT00:00:00.000Z"),
                "dateTo": date_to.strftime("%Y-%m-%dT00:00:00.000Z")
            },
        )
        book_id = r.json()['data'][0]['productId']

        # Segunda requisição obtém as informações do livro do dia
        r = requests.get(
            url="https://static.packt-cdn.com/products/%s/summary" % book_id)
        data = r.json()

        book = util.AttributeDict()
        book['name'] = data['title']
        book['summary'] = data['oneLiner']
        book['cover'] = data['coverImage']
        book['expires'] = datetime.datetime.combine(
            date_to,
            datetime.time.min).replace(tzinfo=util.UTC_TZ).timestamp()

        return book
Exemplo n.º 2
0
    def get_packt_free_book(self):
        date_from = datetime.datetime.utcnow().date()
        date_to = date_from + datetime.timedelta(days=1)

        # Primeira requisição obtém o ID do livro do dia
        r = requests.get(
            url=self._BOOK_URL_OFFERS,
            params={
                "dateFrom": date_from.strftime("%Y-%m-%dT00:00:00.000Z"),
                "dateTo": date_to.strftime("%Y-%m-%dT00:00:00.000Z")
            },
        )
        book_id = r.json()['data'][0]['productId']

        # Segunda requisição obtém as informações do livro do dia
        r = requests.get(url=self._BOOK_URL_SUMMARY.format(book_id))
        data = r.json()

        book = util.AttributeDict()
        book['name'] = data['title']
        book['summary'] = data['oneLiner']
        book['cover'] = data['coverImage']
        book['expires'] = datetime.datetime.combine(
            date_to,
            datetime.time.min).replace(tzinfo=util.UTC_TZ).timestamp()

        return book
Exemplo n.º 3
0
class MockResources(mock.NonCallableMock):
    def __init__(self, book=True, **kwargs):
        super().__init__(**kwargs)

        if book is False:
            self.BOOK = None

        self.configure_mock(
            **{
                'get_events.side_effect':
                lambda n: self.EVENTS[:n],
                'get_packt_free_book.return_value':
                self.BOOK,
                'get_short_url.side_effect':
                lambda url: url,
                'load_states.return_value':
                defaultdict(lambda: defaultdict(lambda: util.StateDict({
                }, mock.call))),
            })

    EVENTS = [
        {
            'link': 'http://www.meetup.com/GDG-Aracaju/events/229313880/',
            'name': 'Hackeando sua Carreira #Hangout',
            'time': datetime.fromtimestamp(1459378800, AJU_TZ)
        },
        {
            'link': 'http://www.meetup.com/GDG-Aracaju/events/229623381/',
            'name': 'Android Jam 2: Talks Dia 2',
            'time': datetime.fromtimestamp(1459612800, AJU_TZ)
        },
        {
            'link': 'http://www.meetup.com/GDG-Aracaju/events/mwnsrlyvgbjb/',
            'name': 'Coding Dojo',
            'time': datetime.fromtimestamp(1459980000, AJU_TZ)
        },
        {
            'link': 'http://www.meetup.com/GDG-Aracaju/events/229591464/',
            'name': 'O Caminho para uma Arquitetura Elegante #Hangout',
            'time': datetime.fromtimestamp(1460160000, AJU_TZ)
        },
        {
            'link': 'http://www.meetup.com/GDG-Aracaju/events/229770309/',
            'name': 'Android Jam 2: #Curso Dia 2',
            'time': datetime.fromtimestamp(1460217600, AJU_TZ)
        },
        {
            'link': 'http://www.meetup.com/GDG-Aracaju/events/mwnsrlyvhbgb/',
            'name': 'Coding Dojo',
            'time': datetime.fromtimestamp(1462399200, AJU_TZ)
        },
        {
            'link': 'http://www.meetup.com/GDG-Aracaju/events/229951204/',
            'name': 'Google I/O Extended',
            'time': datetime.fromtimestamp(1463587200, AJU_TZ)
        },
        {
            'link': 'http://www.meetup.com/GDG-Aracaju/events/229951264/',
            'name': 'Google IO Extended 2016',
            'time': datetime.fromtimestamp(1463608800, AJU_TZ)
        },
    ]

    BOOK = util.AttributeDict(
        name="Android 2099",
        summary="Good practices with Miguel O’Hara",
        cover='//test.jpg',
        expires=4091565600,
    )
Exemplo n.º 4
0
class MockResources:
    def __init__(self):
        # Falso cache de eventos
        self.cache_events = [
            {
                'link': 'http://www.meetup.com/GDG-Aracaju/events/229313880/',
                'name': 'Hackeando sua Carreira #Hangout',
                'time': datetime.fromtimestamp(1459378800, AJU_TZ)
            },
            {
                'link': 'http://www.meetup.com/GDG-Aracaju/events/229623381/',
                'name': 'Android Jam 2: Talks Dia 2',
                'time': datetime.fromtimestamp(1459612800, AJU_TZ)
            },
            {
                'link':
                'http://www.meetup.com/GDG-Aracaju/events/mwnsrlyvgbjb/',
                'name': 'Coding Dojo',
                'time': datetime.fromtimestamp(1459980000, AJU_TZ)
            },
            {
                'link': 'http://www.meetup.com/GDG-Aracaju/events/229591464/',
                'name': 'O Caminho para uma Arquitetura Elegante #Hangout',
                'time': datetime.fromtimestamp(1460160000, AJU_TZ)
            },
            {
                'link': 'http://www.meetup.com/GDG-Aracaju/events/229770309/',
                'name': 'Android Jam 2: #Curso Dia 2',
                'time': datetime.fromtimestamp(1460217600, AJU_TZ)
            },
            {
                'link':
                'http://www.meetup.com/GDG-Aracaju/events/mwnsrlyvhbgb/',
                'name': 'Coding Dojo',
                'time': datetime.fromtimestamp(1462399200, AJU_TZ)
            },
            {
                'link': 'http://www.meetup.com/GDG-Aracaju/events/229951204/',
                'name': 'Google I/O Extended',
                'time': datetime.fromtimestamp(1463587200, AJU_TZ)
            },
            {
                'link': 'http://www.meetup.com/GDG-Aracaju/events/229951264/',
                'name': 'Google IO Extended 2016',
                'time': datetime.fromtimestamp(1463608800, AJU_TZ)
            },
        ]

    def get_events(self, n):
        return self.cache_events[:n]

    # Valor fixo para get_packt_free_book
    book = util.AttributeDict(
        name="Android 2099",
        summary="Good practices with Miguel O’Hara",
        expires=4091565600,
    )

    def get_packt_free_book(self):
        return self.book

    def get_short_url(self, long_url):
        return long_url