def main():
    google_analytics_metrics = fetch_from_google_analytics()
    mailchimp_metrics = fetch_from_mailchimp()

    with db:
        GlobalMetric.drop_table()
        GlobalMetric.create_table()

        GlobalMetric.create(name='avg_monthly_users',
                            value=google_analytics_metrics['avg_monthly_users'])
        GlobalMetric.create(name='avg_monthly_pageviews',
                            value=google_analytics_metrics['avg_monthly_pageviews'])
        GlobalMetric.create(name='subscribers',
                            value=mailchimp_metrics['subscribers'])

        JobMetric.drop_table()
        JobMetric.create_table()

        for url, value in google_analytics_metrics['users_per_job'].items():
            try:
                job = Job.get_by_url(url)
                JobMetric.create(job=job, name='users', value=value)
            except Job.DoesNotExist:
                pass

        for url, value in google_analytics_metrics['pageviews_per_job'].items():
            try:
                job = Job.get_by_url(url)
                JobMetric.create(job=job, name='pageviews', value=value)
            except Job.DoesNotExist:
                pass

        for url, value in google_analytics_metrics['applications_per_job'].items():
            try:
                job = Job.get_by_url(url)
                JobMetric.create(job=job, name='applications', value=value)
            except Job.DoesNotExist:
                pass

        users_per_external_url = merge_metric_dicts(
            google_analytics_metrics['users_per_external_job'],
            mailchimp_metrics['users_per_external_url']
        )
        for url, value in users_per_external_url.items():
            try:
                job = Job.get_by_link(url)
                JobMetric.create(job=job, name='users', value=value)
            except Job.DoesNotExist:
                pass

        pageviews_per_external_url = merge_metric_dicts(
            google_analytics_metrics['pageviews_per_external_job'],
            mailchimp_metrics['pageviews_per_external_url']
        )
        for url, value in pageviews_per_external_url.items():
            try:
                job = Job.get_by_link(url)
                JobMetric.create(job=job, name='pageviews', value=value)
            except Job.DoesNotExist:
                pass
Beispiel #2
0
def main():
    google_analytics_metrics = fetch_from_google_analytics()
    mailchimp_metrics = fetch_from_mailchimp()

    with db:
        Metric.drop_table()
        Metric.create_table()

        google_analytics_metric_names = [
            'avg_monthly_users',
            'avg_monthly_pageviews',
            'avg_monthly_handbook_users',
            'avg_monthly_handbook_pageviews',
            'avg_monthly_handbook_logo_clicks',
            'avg_monthly_jobs_users',
        ]
        for name in google_analytics_metric_names:
            Metric.create(name=name, value=google_analytics_metrics[name])
        Metric.create(name='subscribers',
                      value=mailchimp_metrics['subscribers'])

        JobMetric.drop_table()
        JobMetric.create_table()

        for url, value in google_analytics_metrics['users_per_job'].items():
            try:
                job = Job.get_by_url(url)
                JobMetric.create(job=job, name='users', value=value)
            except Job.DoesNotExist:
                pass

        for url, value in google_analytics_metrics['pageviews_per_job'].items(
        ):
            try:
                job = Job.get_by_url(url)
                JobMetric.create(job=job, name='pageviews', value=value)
            except Job.DoesNotExist:
                pass

        for url, value in google_analytics_metrics[
                'applications_per_job'].items():
            try:
                job = Job.get_by_url(url)
                JobMetric.create(job=job, name='applications', value=value)
            except Job.DoesNotExist:
                pass

        users_per_external_url = merge_metric_dicts(
            google_analytics_metrics['users_per_external_job'],
            mailchimp_metrics['users_per_external_url'])
        for url, value in users_per_external_url.items():
            try:
                job = Job.get_by_link(url)
                JobMetric.create(job=job, name='users', value=value)
            except Job.DoesNotExist:
                pass

        pageviews_per_external_url = merge_metric_dicts(
            google_analytics_metrics['pageviews_per_external_job'],
            mailchimp_metrics['pageviews_per_external_url'])
        for url, value in pageviews_per_external_url.items():
            try:
                job = Job.get_by_link(url)
                JobMetric.create(job=job, name='pageviews', value=value)
            except Job.DoesNotExist:
                pass

        LogoMetric.drop_table()
        LogoMetric.create_table()

        for url, value in google_analytics_metrics['clicks_per_logo'].items():
            try:
                logo = Logo.get_by_url(url)
                LogoMetric.create(logo=logo, name='clicks', value=value)
            except Logo.DoesNotExist:
                pass

        for logo in Logo.listing():
            values = google_analytics_metrics['handbook_users_per_date']
            metric = LogoMetric.from_values_per_date(logo, 'users', values)
            metric.save()
            values = google_analytics_metrics['handbook_pageviews_per_date']
            metric = LogoMetric.from_values_per_date(logo, 'pageviews', values)
            metric.save()
Beispiel #3
0
def test_get_by_link_raises_does_not_exist_error(db_connection):
    with pytest.raises(Job.DoesNotExist):
        Job.get_by_link('https://example.com/1234')
Beispiel #4
0
def test_get_by_link(db_connection):
    job = create_job('1', link='https://example.com/1234')

    assert Job.get_by_link('https://example.com/1234') == job