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
def main(): with db: JobNewsletterMention.drop_table() JobNewsletterMention.create_table() api = MailChimpClient(MAILCHIMP_API_KEY) campaigns = get_collection(api.get('/campaigns/'), 'campaigns') for campaign in campaigns: if not campaign.get('send_time'): continue data = api.get(get_link(campaign, 'content'), count=1000) for url in find_urls(data['html']): try: job = Job.get_by_url(url) except (ValueError, Job.DoesNotExist): pass else: JobNewsletterMention.create( job=job, sent_at=arrow.get(campaign['send_time']).date(), link=campaign['long_archive_url'])
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()
def test_get_by_url_raises_does_not_exist_error(db_connection): with pytest.raises(Job.DoesNotExist): Job.get_by_url('https://junior.guru/jobs/1/')
def test_get_by_url_raises_value_error(db_connection): with pytest.raises(ValueError): Job.get_by_url('https://example.com/jobs/xyz/')
def test_get_by_url(db_connection): job = create_job('1') assert Job.get_by_url('https://junior.guru/jobs/1/') == job