def main(): data = {} info = ElementTree.fromstring(urlopen(feedburner).read()) data['rss'] = int(info.find('feed/entry').get('circulation')) info = decode_json(urlopen(twitter).read()) data['twitter'] = info['followers_count'] info = decode_json(urlopen(github).read()) data['github'] = info['user']['followers_count'] for key, val in data.items(): if key in prev_data: prev_val = prev_data[key] if prev_val > val: val = prev_val else: prev_data[key] = val if val > 1000: val = '%s,%03d' % divmod(val, 1000) else: val = str(val) data[key] = val js = open(output, 'wb') js.write('loadMetrics(') js.write(encode_json(data)) js.write(');\n') js.close() print time(), data
def plan_directive(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): """Setup for tags relating to a plan file.""" global CURRENT_PLAN_ID global CURRENT_PLAN_SETTINGS if not CURRENT_PLAN_ID: raw_node = nodes.raw( '', '<div id="plan-container"></div>' '<script type="text/javascript" src="js/plan.js"></script>' '<hr class="clear" />', format='html' ) else: raw_node = nodes.raw('', '', format='html') content = '\n'.join(content) if content: CURRENT_PLAN_SETTINGS = decode_json(content) else: CURRENT_PLAN_SETTINGS = {} CURRENT_PLAN_ID = arguments[0] return [raw_node]
def post(self, api_method, http_method='POST', expected_status=(200, ), **extra_params): if not (api_method.startswith('http://') or api_method.startswith('https://')): api_method = '%s%s%s' % (self.service_info['default_api_prefix'], api_method, self.service_info['default_api_suffix']) if self.token is None: self.token = OAuthAccessToken.get_by_key_name(self.get_cookie()) fetch = urlfetch(url=api_method, payload=self.get_signed_body(api_method, self.token, http_method, **extra_params), method=http_method) if fetch.status_code not in expected_status: raise ValueError( "Error calling... Got return status: %i [%r]" % (fetch.status_code, fetch.content), ) return decode_json(fetch.content)
def parse_incoming_telex(telex): telex = decode_json(telex) for key in telex: first_char = key[:1] if first_char == '.': # Command pass elif first_char == '_': # Header pass elif first_char == '+': # Signal pass
def post(self, api_method, http_method='POST', expected_status=(200,), **extra_params): if not (api_method.startswith('http://') or api_method.startswith('https://')): api_method = '%s%s%s' % ( self.service_info['default_api_prefix'], api_method, self.service_info['default_api_suffix'] ) if self.token is None: self.token = OAuthAccessToken.get_by_key_name(self.get_cookie()) fetch = urlfetch(url=api_method, payload=self.get_signed_body( api_method, self.token, http_method, **extra_params ), method=http_method) if fetch.status_code not in expected_status: raise ValueError( "Error calling... Got return status: %i [%r]" % (fetch.status_code, fetch.content) ) return decode_json(fetch.content)
def check(): """check if this checkout is up-to-date""" log("Checking the current revision id for your code.", PROGRESS) revision_id = do( 'git', 'show', '--pretty=oneline', '--summary', redirect_stdout=True ).split()[0] log("Checking the latest commits on GitHub.", PROGRESS) commit_info = urlopen(environ.get( 'REDPILL_CHECK_URL', 'https://github.com/api/v2/json/commits/list/tav/ampify/master' )).read() latest_revision_id = decode_json(commit_info)['commits'][0]['id'] if revision_id != latest_revision_id: exit("A new version is available. Please run `git update`.") log("Your checkout is up-to-date.", SUCCESS)
def check(argv=None, completer=None): op = OptionParser(usage="Usage: amp check", add_help_option=False) options, args = parse_options(op, argv, completer) log("Checking the current revision id for your code.", PROGRESS) revision_id = do( 'git', 'show', '--pretty=oneline', '--summary', redirect_stdout=True ).split()[0] log("Checking the latest commits on GitHub.", PROGRESS) commit_info = urlopen( 'http://github.com/api/v2/json/commits/list/tav/ampify/master' ).read() latest_revision_id = decode_json(commit_info)['commits'][0]['id'] if revision_id != latest_revision_id: exit("A new version is available. Please run `git pull`.") log("Your checkout is up-to-date.", SUCCESS)
def STATIC(file, base=static_url, debug=cfg.DEBUG, assets={}): if debug or not assets: f = open('assets.json', 'rb') assets.update(decode_json(f)) f.close() return "%s%s" % (base, assets.get(file, file))
feedburner = "http://feedburner.google.com/api/awareness/1.0/GetFeedData?id=pel7nkvcgomc4kvih3ue7su4dg" twitter = "http://api.twitter.com/1/users/show/tav.json" # ------------------------------------------------------------------------------ # Get Previous Info # ------------------------------------------------------------------------------ prev_data = {} if exists(output): try: prev_file = open(output, 'rb') prev_stream = prev_file.read().split('(', 1)[1].rsplit(')', 1)[0] prev_raw = decode_json(prev_stream.strip()) for key, value in prev_raw.items(): prev_data[key] = int(value.replace(',', '')) prev_file.close() except Exception: pass # ------------------------------------------------------------------------------ # Get Info # ------------------------------------------------------------------------------ def main(): data = {} info = ElementTree.fromstring(urlopen(feedburner).read()) data['rss'] = int(info.find('feed/entry').get('circulation')) info = decode_json(urlopen(twitter).read())