Exemple #1
0
    def get_schema(self, lang):
	## 0.  memcache hit -> response
	schema = self.cache_get(lang)
	if schema:
	    return schema
	url = self.format_url(lang)

	## 1. mmemcache miss -> url fetch
	try:
	    schema = jsonloads(urlopen(url).read())
	    app_uri = application_uri(self.request.environ)
	    img_fixes = self.img_fixes
	    for item in schema['result']['items']['item']:
		if item['defindex'] in img_fixes:
		    item['image_url'] = app_uri + img_fixes[item['defindex']]
	except (Exception, ), exc:
	    ## 1a.  fetch failure -> history lookup
	    storage = History.all().filter('url =', url).get()
	    if storage:
		## this assumes that the schema has already been
		## parsed and fixed at least one time.
		schema = jsonloads(storage.payload)
		self.cache_set(schema, lang)
	    else:
		## 1b. total failure
		schema = {}
Exemple #2
0
    def _init(self):

        from application.lib.systemstats import get_serial
        self.fsmdic['deviceserial'] = get_serial()

        wifiapsfile = appwd + '/' + 'wifiaps.json'
        try:
            self.fsmdic['wifiaps'] = jsonloads(open(wifiapsfile, 'r').read())
        except:
            self.fsmdic['wifiaps'] = []

        if devmode:
            self.fsmdic['wifiaps'].append({
                'ssid': 'ThunderFace2',
                'password': '******'
            })
            self.fsmdic['wifiaps'].append({
                'ssid': 'DonCarnage',
                'password': '******'
            })

#with open(filename, 'w') as f:
#json = jsondumps(twitterleads2, separators=(',', ':'), use_decimal=True, sort_keys=True, indent=4)
#f.write(json)

        return 'next'
Exemple #3
0
    def get_news(self):
	url = self.news_url % (self.count, self.max_length)
	news = self.cache_get(url)
	if news:
	    return news
	try:
	    news = jsonloads(urlopen(url).read())['appnews']['newsitems']['newsitem']
	except (Exception, ), exc:
	    news = []
Exemple #4
0
    def get_items(self, id64):
	## 0.  memcache hit -> response
	items = self.cache_get(id64)
	if items:
	    return items
	url = self.format_url(id64)

	## 1.  memcache miss -> url fetch
	try:
	    items = jsonloads(urlopen(url).read())['result']['items']['item']
	except (Exception, ), exc:
	    ## 1a.  fetch failure -> history lookup
	    storage = History.all().filter('url =', url).get()
	    if storage:
		items = jsonloads(storage.payload)
		self.cache_set(items, id64)
	    else:
		## 1b.  total failure
		items = {}
Exemple #5
0
    def get_profile(self, id64):
	## 0. memcache hit -> response
	profile = self.cache_get(id64)
	if profile:
	    return profile
	url = self.format_url(id64)

	## 1.  memcache miss -> url fetch
	try:
	    profile = jsonloads(urlopen(url).read())
	    if not self.is_public(profile):
		profile = {'exception':'private profile'}
	    else:
		profile = self.reformat_profile(profile)
	except (Exception, ), exc:
	    ## 1a.  fetch failure -> history lookup
	    storage = History.all().filter('url =', url).get()
	    if storage:
		profile = jsonloads(storage.payload)
		self.cache_set(profile, id64)
	    else:
		## 1b.  total failure
		profile = {}
Exemple #6
0
    def get_status(self, id64):
	status = self.cache_get(id64)
	if status:
	    return status

	## 1.  memcache miss -> url fetch
	url = self.format_url(id64)
	try:
	    raw_status = urlopen(url).read(1024)
	except (Exception, ), exc:
	    ## 1a. memcache miss -> fetch failure -> history lookup
	    storage = History.all().filter('url =', url).get()
	    if storage:
		status = jsonloads(storage.payload)
		self.cache_set(status, id64)
	    else:
		## 1b. memcache miss -> fetch failure -> history failure =total failure
		status = {}
Exemple #7
0
 def apirequest(cls, url, apikey=None, **params):
     """Create query to the BTC-e API (decoded response).
     @raise APIError, httplib.HTTPException: BTC-e and CloudFlare errors
     @param url: plain URL without parameters (Public/Trade API)
     @param apikey: API-key dict {'Key': '...', 'Secret': '...'}
     @param **params: method and/or parameters (Public/Trade API)
     @return: API response (decoded data) <type 'dict'>"""
     data = cls.jsonrequest(url, apikey, **params)
     try:
         data = jsonloads(data, parse_float=Decimal, parse_int=Decimal)
     except ValueError:
         if cls.resp.status == _HTTP_OK:
             # BTC-e API unknown errors.
             raise APIError(str(data) or "Unknown Error")
         else:
             # HTTP or CloudFlare errors.
             raise HTTPException("{} {}".format(cls.resp.status,
                                                cls.resp.reason))
     else:
         if 'error' in data:
             # BTC-e API standard errors.
             raise APIError(str(data['error']))
     return data
Exemple #8
0
 def apirequest(cls, url, apikey=None, **params):
     """Create query to the BTC-E API (decoded response).
     @raise APIError, httplib.HTTPException: BTC-E and CloudFlare errors
     @param url: Public/Trade API plain URL without parameters
     @param apikey: Trade API Key {'Key': 'KEY', 'Secret': 'SECRET'}
     @param **params: Public/Trade API method and/or parameters
     @return: BTC-E API response (decoded data) <type 'dict'>"""
     data = cls.jsonrequest(url, apikey, **params)
     try:
         data = jsonloads(data, parse_float=Decimal, parse_int=Decimal)
     except ValueError:
         if cls._resp.status != httplib.OK:
             # CloudFlare HTTP errors
             raise httplib.HTTPException("{} {}".format(
                 cls._resp.status, cls._resp.reason))
         else:
             # BTC-E API unknown errors
             raise APIError(str(data) or "Unknown Error")
     else:
         if 'error' in data:
             # BTC-E API standard errors
             logging.info(params)
             raise APIError(str(data['error']))
     return data
#!/bin/env python
#-*- coding: utf-8 -*-

import sys
import os
from urlfetch import get
try:
    from simplejson import loads as jsonloads
except ImportError:
    from json import loads as jsonload

user = sys.argv[1]
auth = None if len(sys.argv) <= 2 else (user, sys.argv[2])

r = get('https://api.bitbucket.org/1.0/users/' + user, auth=auth)
repos = jsonloads(r.body)['repositories']

for repo in repos:
    cmd = repo['scm']
    cmd += ' clone '
    cmd += 'ssh://%[email protected]/%s/%s' % (repo['scm'], user, repo['name'])
    if repo['scm'] == 'git':
        cmd += '.git'
    print cmd, '......'
    os.system(cmd)