Created
March 19, 2014 23:41
-
-
Save amontalenti/9654074 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sst.actions import * | |
| import time | |
| import json | |
| from settings import DASH_USERNAME, DASH_PASSWORD, APIKEYS | |
| envs = { | |
| "bri": "dash.parsely.com", | |
| "ue1a": "ue1a-dash-web1.cogtree.com", | |
| } | |
| apikeys = {key: {} for key in APIKEYS} | |
| clear_cookies() | |
| # log in to arstechnica as staff account in each env | |
| apikey = "arstechnica.com" | |
| for env, host in envs.iteritems(): | |
| cust = "https://{host}/{apikey}".format(host=host, apikey=apikey) | |
| url = "{cust}/reports".format(cust=cust) | |
| go_to(url) | |
| write_textfield("id_username", DASH_USERNAME) | |
| write_textfield("id_password", DASH_PASSWORD) | |
| elm = get_element(tag="input", css_class="btn") | |
| click_button(elm) | |
| for apikey in apikeys: | |
| for env, host in envs.iteritems(): | |
| try: | |
| cust = "https://{host}/{apikey}".format(host=host, apikey=apikey) | |
| # visit pulse | |
| start = time.time() | |
| url = "{cust}/pulse".format(cust=cust) | |
| go_to(url) | |
| wait_for(assert_title, 'Pulse - Dash') | |
| total_hits = get_text("total_hits") | |
| end = time.time() | |
| # get the number | |
| total_hits = total_hits.split(" ")[0] | |
| # de-humanize the number | |
| total_hits = int(total_hits.replace(",", "")) | |
| apikeys[apikey][env + "_pulse_hits"] = total_hits | |
| apikeys[apikey][env + "_pulse_elapsed"] = end - start | |
| # visit glimpse | |
| start = time.time() | |
| url = "{cust}/glimpse".format(cust=cust) | |
| go_to(url) | |
| wait_for(assert_title, 'Glimpse - Parse.ly Dash') | |
| clean = lambda text: text.strip().replace(",", "") | |
| def clean_and_record(): | |
| posts_viewed = get_text("posts_viewed") | |
| new_posts = get_text("posts_published") | |
| total_uniques = get_text("total_uniques") | |
| total_views = get_text("total_views") | |
| total_shares = get_text("shares") | |
| for key, val in vars().iteritems(): | |
| apikeys[apikey][env + "_" + key] = clean(val) | |
| clean_and_record() | |
| end = time.time() | |
| apikeys[apikey][env + "_glimpse_elapsed"] = end - start | |
| # move over to historics | |
| start = time.time() | |
| url = "{cust}/posts?start=2014-03-16&end=2014-03-19".format(cust=cust) | |
| go_to(url) | |
| wait_for(assert_title, 'Top Posts - Dash') | |
| for i in range(1, 10+1): | |
| post = get_element("a", css_class="post-link-{}".format(i)) | |
| post_headline = get_text(post).strip() | |
| if i == 1: | |
| apikeys[apikey][env + "_headlines"] = [] | |
| else: | |
| apikeys[apikey][env + "_headlines"].append(post_headline) | |
| apikeys[apikey][env + "_posts_elapsed"] = end - start | |
| except Exception as ex: | |
| apikeys[apikey][env + "_error"] = True | |
| # store stats | |
| with open("stats.json", "w") as stats_file: | |
| json.dump(apikeys, stats_file, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment