Example #1
0
File: stats.py Project: jrburke/f1
 def history(self):
     start = request.params.get('start',None)
     end = request.params.get('end',None)
     limit = int(request.params.get('days','0'))
     opts = request.params.get('opts','').split(',')
     whereclause = []
     vars = {}
     groupby = []
     if limit and not start and not end:
         whereclause.append(History.published >= UTCDateTime.now() - timedelta(days=limit))
     if start:
         whereclause.append(History.published >= UTCDateTime.from_string(start))
     if end:
         whereclause.append(History.published < UTCDateTime.from_string(end))
     if 'perday' in opts:
         if 'domain' in opts:
             s = select([func.date_format(History.published, "%Y-%m-%d"), History.domain, func.count(History.domain)],)
             groupby.append(func.to_days(History.published))
             groupby.append(History.domain)
         else:
             s = select([func.date_format(History.published, "%Y-%m-%d"), func.count(History.id)])
             groupby.append(func.to_days(History.published))
     else:
         s = select([func.count(History.domain), History.domain])
         groupby.append(History.domain)
     
     if whereclause:
         s = s.where(and_(*whereclause))
     if groupby:
         s = s.group_by(*groupby)
     return [list(a) for a in Session.execute(s).fetchall()]
Example #2
0
File: stats.py Project: jrburke/f1
    def accounts(self):
        start = request.params.get('start',None)
        end = request.params.get('end',None)
        limit = int(request.params.get('days','0'))
        opts = request.params.get('opts','').split(',')
        groupby = []
        whereclause = []
        if limit and not start and not end:
            whereclause.append(Account.created >= UTCDateTime.now() - timedelta(days=limit))
        if start:
            whereclause.append(Account.created >= UTCDateTime.from_string(start))
        if end:
            whereclause.append(Account.created < UTCDateTime.from_string(end))
        if 'perday' in opts:
            if 'domain' in opts:
                s = select([func.date(Account.created), Account.domain, func.count(Account.id)])
                groupby.append(func.to_days(Account.created))
                groupby.append(Account.domain)
            else:
                s = select([func.date(Account.created), func.count(Account.id)])
                groupby.append(func.to_days(Account.created))
        else:
            s = select([func.count(Account.domain), Account.domain])
            groupby.append(Account.domain)

        if whereclause:
            s = s.where(*whereclause)
        if groupby:
            s = s.group_by(*groupby)
        return [list(a) for a in Session.execute(s).fetchall()]
Example #3
0
    def verify(self, *args, **kw):
        provider = request.params.get('provider')
        service = get_provider(provider)

        auth = service.responder()
        try:
            user = auth.verify()
            account = user['profile']['accounts'][0]
            if not user.get('oauth_token') and not user.get('oauth_token_secret'):
                raise Exception('Unable to get OAUTH access')
            acct = self._get_or_create_account(provider, account['userid'], account['username'])
            acct.profile = user['profile']
            acct.oauth_token = user.get('oauth_token', None)
            if 'oauth_token_secret' in user:
                acct.oauth_token_secret = user['oauth_token_secret']
            acct.updated = UTCDateTime.now()
            try:
                Session.commit()
            except UnicodeEncodeError, e:
                log.exception("***** UnicodeEncodeError! %r: %r: %r %r" % (acct.domain, acct.userid, acct.username,acct.json_attributes,))
                raise e
            # XXX argh, this is also done in get_or_create above, but we have to
            # ensure we have the updated data
            session[acct.key] = acct.to_dict()
            session.save()
Example #4
0
    def verify(self, *args, **kw):
        provider = session.pop('oauth_provider')
        session.save()
        service = get_provider(provider)

        auth = service.responder()
        try:
            user = auth.verify()
            account = user['profile']['accounts'][0]
    
            acct = self._get_or_create_account(provider, account['userid'], account['username'])
            acct.profile = user['profile']
            acct.oauth_token = user.get('oauth_token', None)
            if 'oauth_token_secret' in user:
                acct.oauth_token_secret = user['oauth_token_secret']
            acct.updated = UTCDateTime.now()
            Session.commit()
            # XXX argh, this is also done in get_or_create above, but we have to
            # ensure we have the updated data
            session[acct.key] = acct.to_dict()
            session.save()
        except AccessException, e:
            self._redirectException(e)
Example #5
0
 def __init__(self):
     # can be overridden later, but always have a default for new accounts
     self.key = str(uuid1())
     self.updated = self.created = UTCDateTime.now()