示例#1
0
        def when_searching_by_date_and_date_range(self, app):
            # Given
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(
                venue, event_name='Training in Modern Jazz')

            event_occurrence = create_event_occurrence(
                offer,
                beginning_datetime=self.three_days_from_now,
                end_datetime=self.three_days_and_one_hour_from_now)

            recommendation = create_recommendation(offer, user)
            stock = create_stock_from_event_occurrence(event_occurrence)
            PcObject.save(stock, recommendation)

            # When
            response = TestClient(app.test_client()).with_auth(
                user.email).get(RECOMMENDATION_URL +
                                '?date=%s&days=1-5' % strftime(self.now))

            # Then
            recommendations = response.json
            assert response.status_code == 200
            assert recommendations[0]['offer']['dateRange'] == [
                strftime(self.three_days_from_now),
                strftime(self.three_days_and_one_hour_from_now)
            ]
            assert len(response.json) == 1
示例#2
0
        def when_searching_by_matching_date_and_non_matching_keywords(
                self, app):
            # Given
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(
                venue, event_name='Training in Modern Jazz')

            event_occurrence = create_event_occurrence(
                offer,
                beginning_datetime=self.in_one_hour,
                end_datetime=self.ten_days_from_now)

            recommendation = create_recommendation(offer, user)
            stock = create_stock_from_event_occurrence(event_occurrence)
            PcObject.save(stock, recommendation)

            # When
            response = TestClient(app.test_client()).with_auth(
                user.email).get(RECOMMENDATION_URL +
                                '?date=%s&keywords=nekfeu' %
                                strftime(self.ten_days_from_now))

            # Then
            assert response.status_code == 200
            assert len(response.json) == 0
示例#3
0
        def when_searching_by_date_and_type_and_pagination_not_in_range(
                self, app):
            # Given
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(
                venue, event_name='The new film', event_type=EventType.CINEMA)
            thing_product = create_product_with_thing_type(
                thing_name='Lire un livre', is_national=True)

            thingOffer = create_offer_with_thing_product(venue, thing_product)

            event_occurrence = create_event_occurrence(
                offer,
                beginning_datetime=self.three_days_from_now,
                end_datetime=self.three_days_and_one_hour_from_now)

            recommendation = create_recommendation(offer, user)
            recommendation2 = create_recommendation(thingOffer, user)
            stock = create_stock_from_event_occurrence(event_occurrence)
            thing_stock = create_stock(price=12, available=5, offer=thingOffer)
            PcObject.save(stock, recommendation, recommendation2, thing_stock)

            # When
            response = TestClient(app.test_client()).with_auth(
                user.email).get(RECOMMENDATION_URL +
                                '?categories=Lire%2CRegarder&days=1-5&page=2' +
                                '&date=%s' % strftime(self.now))

            # Then
            assert response.status_code == 200
            assert len(response.json) == 0
示例#4
0
def touch(file_id, date=None, service_account_string=None):
    if date is None:
        date = datetime.utcnow()

    return create_google_service('drive', service_account_string).files() \
            .update(
                body={
                    "modifiedTime": strftime(date)
                },
                fileId=file_id,
                supportsAllDrives=True) \
            .execute()
示例#5
0
def create_industrial_event_occurrences(event_offers_by_name):
    logger.info('create_industrial_event_occurrences')

    event_occurrences_by_name = {}

    event_offers = list(event_offers_by_name.values())

    event_offers_with_occurrences = remove_every(
        event_offers, EVENT_OFFERS_WITH_OCCURRENCES_REMOVE_MODULO)

    for event_offer_with_occurrences in event_offers_with_occurrences:
        for beginning_datetime in EVENT_OCCURRENCE_BEGINNING_DATETIMES:
            name = "{} / {} / {} ".format(
                event_offer_with_occurrences.product.name,
                event_offer_with_occurrences.venue.name,
                strftime(beginning_datetime))
            event_occurrences_by_name[name] = create_event_occurrence(
                beginning_datetime=strftime(beginning_datetime),
                end_datetime=strftime(beginning_datetime + timedelta(hours=1)),
                offer=event_offer_with_occurrences)

    return event_occurrences_by_name
示例#6
0
        def when_searching_by_date_and_date_range_and_type(self, app):
            # Given
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(
                venue, event_name='The new film', event_type=EventType.CINEMA)
            offer2 = create_offer_with_event_product(
                venue,
                event_name='Spectacle',
                event_type=EventType.SPECTACLE_VIVANT)
            thing_product = create_product_with_thing_type(
                thing_name='Lire un livre', is_national=True)

            thing_offer = create_offer_with_thing_product(venue, thing_product)

            event_occurrence = create_event_occurrence(
                offer,
                beginning_datetime=self.three_days_from_now,
                end_datetime=self.three_days_and_one_hour_from_now)

            recommendation = create_recommendation(offer, user)
            recommendation2 = create_recommendation(thing_offer, user)
            recommendation3 = create_recommendation(offer2, user)
            stock = create_stock_from_event_occurrence(event_occurrence)
            stock1 = create_stock_from_offer(offer2)
            thing_stock = create_stock(price=12,
                                       available=5,
                                       offer=thing_offer)
            PcObject.save(stock, recommendation, recommendation2,
                          recommendation3, thing_stock, stock1)

            # When
            response = TestClient(app.test_client()).with_auth(
                user.email).get(RECOMMENDATION_URL +
                                '?categories=Lire%2CRegarder' +
                                '&date=%s&days=1-5' % strftime(self.now))

            # Then
            assert response.status_code == 200
            recommendations = response.json
            assert len(recommendations) == 2

            recommendation_names = [
                recommendation['offer']['product']['name']
                for recommendation in recommendations
            ]
            assert 'The new film' in recommendation_names
            assert 'Lire un livre' in recommendation_names

            assert 'Spectacle' not in recommendation_names
    def test_when_days_1_5_and_date_today_returns_dictionary_with_days_intervals_in_one_day_and_in_five_days(
            self, app):
        # Given
        request_args = {'days': '1-5', 'date': strftime(self.now)}

        # When
        search_params = get_recommendation_search_params(request_args)

        # Then
        assert search_params == {
            'days_intervals': [[
                datetime(2019, 2, 1, 12, 0, tzinfo=tzutc()),
                datetime(2019, 2, 5, 12, 0, tzinfo=tzutc())
            ]]
        }
示例#8
0
def buzzsumo_trending_from_result(result):
    return {
        'buzzsumoIdentifier':
        int(result['id']),
        'externalThumbUrl':
        result['thumbnail'],
        'facebookShares':
        result['total_facebook_shares'],
        'publishedDate':
        strftime(datetime.utcfromtimestamp(result['published_date'])),
        'title':
        result['title'],
        'totalShares':
        result['total_shares'],
        'twitterShares':
        result['twitter_shares']
    }
示例#9
0
def article_from_buzzsumo(result):
    return {
        'externalThumbUrl':
        result['thumbnail'],
        'facebookShares':
        result['total_facebook_shares'],
        'publishedDate':
        strftime(datetime.utcfromtimestamp(result['published_date'])),
        'source': {
            'id': 'buzzsumo-{}'.format(result['id']),
            'subdomain': result['subdomain'],
        },
        'title':
        result['title'],
        'totalShares':
        result['total_shares'],
        'twitterShares':
        result['twitter_shares'],
        'type':
        'article',
        'url':
        result.get('og_url', '')
    }
def create_articles(with_capture=False):
    logger.info('create_articles')

    articles_by_name = {}

    articles_by_name["Great Barrier"] = Article(
        authors="James Delingpole",
        is_reviewable=True,
        publishedDate=strftime(today),
        summary=
        "Like the thriving polar bear, like the recovering ice caps, like the doing-just-fine Pacific islands, the Great Barrier Reef has become a totem for the liberal-left not because it’s in any kind of danger but because it’s big and famous and photogenic and lots and lots of people would be really sad if it disappeared.",
        tags="great barrier;",
        theme="Climate",
        title=
        "Great Barrier Reef Still Not Dying, Whatever Washington Post Says…",
        url=
        "https://www.breitbart.com/big-government/2017/03/20/delingpole-great-barrier-reef-still-not-dying-whatever-washington-post-says"
    )

    articles_by_name["Daily Mail inflates disagreement"] = Article(
        authors="David Rose",
        summary=
        "The Mail on Sunday today reveals astonishing evidence that the organisation that is the world’s leading source of climate data rushed to publish a landmark paper that exaggerated global warming and was timed to influence the historic Paris Agreement on climate change.",
        tags="data",
        title=
        "Daily Mail inflates disagreement between scientists about data handling to make unsupported accusation of data manipulation",
        url=
        "http://www.dailymail.co.uk/sciencetech/article-4192182/World-leaders-duped-manipulated-global-warming-data.html"
    )

    articles_by_name["Decline in the amount of dissolved oxygen"] = Article(
        authors="Chris Mooney",
        is_reviewable=True,
        publishedDate=strftime(today + timedelta(days=-1)),
        summary=
        "A large research synthesis, published in one of the world’s most influential scientific journals, has detected a decline in the amount of dissolved oxygen in oceans around the world — a long-predicted result of climate change that could have severe consequences for marine organisms if it continues.",
        tags="ocean;oxygen",
        title=
        "Scientists have just detected a major change to the Earth’s oceans linked to a warming climate",
        url=
        "https://www.washingtonpost.com/news/energy-environment/wp/2017/02/15/its-official-the-oceans-are-losing-oxygen-posing-growing-threats-to-marine-life"
    )

    articles_by_name["Infection bactérienne"] = Article(
        authors="Pascal Santi;Sandrine Cabut",
        is_reviewable=True,
        summary=
        "Selon plusieurs organisations, les recommandations de prise en charge de cette infection bactérienne sont inadaptées.",
        tags="lyme;",
        theme="Health",
        title="Maladie de Lyme : fronde contre la Haute Autorité de santé",
        url=
        "https://www.lemonde.fr/sciences/article/2018/07/24/maladie-de-lyme-fronde-contre-la-haute-autorite-de-sante_5335369_1650684.html"
    )

    articles_by_name["Global carbon budget 2014"] = Article(
        authors=
        "C. Le Quéré1, R. Moriarty1, R. M. Andrew2, G. P. Peters2, P. Ciais3, P. Friedlingstein4, S. D. Jones1, S. Sitch5, P. Tans6, A. Arneth7, T. A. Boden8, L. Bopp3, Y. Bozec9,10, J. G. Canadell11, L. P. Chini12, F. Chevallier3, C. E. Cosca13, I. Harris14, M. Hoppema15, R. A. Houghton16, J. I. House17, A. K. Jain18, T. Johannessen19,20, E. Kato21,22, R. F. Keeling23, V. Kitidis24, K. Klein Goldewijk25, C. Koven26, C. S. Landa19,20, P. Landschützer27, A. Lenton28, I. D. Lima29, G. Marland30, J. T. Mathis13, N. Metzl31, Y. Nojiri21, A. Olsen19,20, T. Ono32, S. Peng3, W. Peters33, B. Pfeil19,20, B. Poulter34, M. R. Raupach35,†, P. Regnier36, C. Rödenbeck37, S. Saito38, J. E. Salisbury39, U. Schuster5, J. Schwinger19,20, R. Séférian40, J. Segschneider41, T. Steinhoff42, B. D. Stocker43,44, A. J. Sutton13,45, T. Takahashi46, B. Tilbrook47, G. R. van der Werf48, N. Viovy3, Y.-P. Wang49, R. Wanninkhof50, A. Wiltshire51, and N. Zeng",
        is_reviewable=True,
        summary=
        "Accurate assessment of anthropogenic carbon dioxide (CO2) emissions and their redistribution among the atmosphere, ocean, and terrestrial biosphere is important to better understand the global carbon cycle, support the development of climate policies, and project future climate change. Here we describe data sets and a methodology to quantify all major components of the global carbon budget, including their uncertainties, based on the combination of a range of data, algorithms, statistics, and model estimates and their interpretation by a broad scientific community. We discuss changes compared to previous estimates, consistency within and among components, alongside methodology and data limitations. CO2 emissions from fossil fuel combustion and cement production (EFF) are based on energy statistics and cement production data, respectively, while emissions from land-use change (ELUC), mainly deforestation, are based on combined evidence from land-cover-change data, fire activity associated with deforestation, and models. The global atmospheric CO2 concentration is measured directly and its rate of growth (GATM) is computed from the annual changes in concentration. The mean ocean CO2 sink (SOCEAN) is based on observations from the 1990s, while the annual anomalies and trends are estimated with ocean models. The variability in SOCEAN is evaluated with data products based on surveys of ocean CO2 measurements. The global residual terrestrial CO2 sink (SLAND) is estimated by the difference of the other terms of the global carbon budget and compared to results of independent dynamic global vegetation models forced by observed climate, CO2, and land-cover-change (some including nitrogen–carbon interactions). We compare the mean land and ocean fluxes and their variability to estimates from three atmospheric inverse methods for three broad latitude bands. All uncertainties are reported as ±1σ, reflecting the current capacity to characterise the annual estimates of each component of the global carbon budget. For the last decade available (2004–2013), EFF was 8.9 ± 0.4 GtC yr−1, ELUC 0.9 ± 0.5 GtC yr−1, GATM 4.3 ± 0.1 GtC yr−1, SOCEAN 2.6 ± 0.5 GtC yr−1, and SLAND 2.9 ± 0.8 GtC yr−1. For year 2013 alone, EFF grew to 9.9 ± 0.5 GtC yr−1, 2.3% above 2012, continuing the growth trend in these emissions, ELUC was 0.9 ± 0.5 GtC yr−1, GATM was 5.4 ± 0.2 GtC yr−1, SOCEAN was 2.9 ± 0.5 GtC yr−1, and SLAND was 2.5 ± 0.9 GtC yr−1. GATM was high in 2013, reflecting a steady increase in EFF and smaller and opposite changes between SOCEAN and SLAND compared to the past decade (2004–2013). The global atmospheric CO2 concentration reached 395.31 ± 0.10 ppm averaged over 2013. We estimate that EFF will increase by 2.5% (1.3–3.5%) to 10.1 ± 0.6 GtC in 2014 (37.0 ± 2.2 GtCO2 yr−1), 65% above emissions in 1990, based on projections of world gross domestic product and recent changes in the carbon intensity of the global economy. From this projection of EFF and assumed constant ELUC for 2014, cumulative emissions of CO2 will reach about 545 ± 55 GtC (2000 ± 200 GtCO2) for 1870–2014, about 75% from EFF and 25% from ELUC. This paper documents changes in the methods and data sets used in this new carbon budget compared with previous publications of this living data set (Le Quéré et al., 2013, 2014). All observations presented here can be downloaded from the Carbon Dioxide Information Analysis Center (doi:10.3334/CDIAC/GCP_2014).",
        tags="carbon;PeerVerified",
        title="Global carbon budget 2014",
        url="https://www.earth-syst-sci-data.net/7/47/2015/essd-7-47-2015.html"
    )

    articles_by_name["Fred Poulet"] = Article(
        authors="Clarisse Fabre",
        is_reviewable=False,
        publishedDate=strftime(today + timedelta(hours=-2)),
        summary=
        "C’est l’histoire d’un garçon qui voulait être Iggy Pop. A Mulhouse, dans les années 1980, il s’imaginait torse nu, le pantalon taille basse, électrisant les foules et se roulant par terre. Mais le rêve post-punk s’est dissous dans les paillettes des combinaisons disco. Et Fred Poulet s’est mis à écrire des chansons, tout en gagnant sa vie comme peintre sur des tournages de film. « C’est pour continuer à rêver que j’écris depuis une trentaine d’années. C’est un peu l’histoire de ma vie », résume le chanteur, emmitouflé dans son imperméable. A 57 ans,il revendique « la désinvolture » comme attitude, au sens de la liberté et de l’élégance.",
        tags="KFC;OnEstChampion;",
        title="Cocorico, Fred Poulet revient à la chanson",
        url=
        "https://www.lemonde.fr/cinema/article/2019/01/10/cocorico-fred-poulet-revient-a-la-chanson_5407141_3476.html"
    )

    ApiHandler.save(*articles_by_name.values())

    if with_capture:
        for article in articles_by_name.values():
            logger.info('capture screenshot for {}...'.format(article.url))
            thumb = capture(article.url)
            save_thumb(article, thumb, 0)
            logger.info('capture screenshot for {}...Done.'.format(
                article.url))

    logger.info('created {} articles'.format(len(articles_by_name)))

    return articles_by_name
示例#11
0
        def when_searching_by_date_and_type_activation(self, app):
            # Given
            category_and_date_search = "categories=Lire%2CRegarder%2CActivation&date=" + strftime(
                self.now) + "&days=1-5"
            user = create_user(email='*****@*****.**')

            offerer = create_offerer()
            venue = create_venue(offerer)

            cinema_event_offer = create_offer_with_event_product(
                venue, event_name='The new film', event_type=EventType.CINEMA)

            activation_event_offer = create_offer_with_event_product(
                venue,
                event_name='Activation de votre Pass Culture',
                event_type=EventType.ACTIVATION)

            book_thing = create_product_with_thing_type(
                thing_name='Lire un livre', is_national=True)
            book_thing_offer = create_offer_with_thing_product(
                venue, book_thing)
            cinema_event_occurrence = create_event_occurrence(
                cinema_event_offer,
                beginning_datetime=self.three_days_from_now,
                end_datetime=self.three_days_and_one_hour_from_now)
            activation_event_occurrence = create_event_occurrence(
                activation_event_offer,
                beginning_datetime=self.three_days_from_now,
                end_datetime=self.three_days_and_one_hour_from_now)

            cinema_recommendation = create_recommendation(
                cinema_event_offer, user)
            book_recommendation = create_recommendation(book_thing_offer, user)
            activation_recommendation = create_recommendation(
                activation_event_offer, user)

            cinema_event_occurence_stock = create_stock_from_event_occurrence(
                cinema_event_occurrence)
            activation_event_occurence_stock = create_stock_from_event_occurrence(
                activation_event_occurrence)
            book_thing_stock = create_stock(price=12,
                                            available=5,
                                            offer=book_thing_offer)

            PcObject.save(cinema_recommendation, book_recommendation,
                          activation_recommendation,
                          cinema_event_occurence_stock,
                          activation_event_occurence_stock, book_thing_stock)

            # When

            response = TestClient(app.test_client()).with_auth(
                user.email).get(RECOMMENDATION_URL +
                                '?%s' % category_and_date_search)

            # Then
            assert response.status_code == 200
            assert len(response.json) == 3
            recommendations = response.json
            recommendation_names = [
                recommendation['offer']['product']['name']
                for recommendation in recommendations
            ]
            assert 'Activation de votre Pass Culture' in recommendation_names