コード例 #1
0
def get_token(name, balance=0, currency='usd'):
    try:
        r_token = requests.get(__endpoint_token.format(name,
                                                       currency)).json()[0]
        return model.Token(r_token, balance, currency)
    except:
        return None
コード例 #2
0
 def update(self):
     if self.player.get_state() == vlc.State.Ended:
         self.timer.stop()  # stop the timer
         self.chapter_ended.emit()  # emit event
         return
     newPosition = self.getPosition()
     if not self.nextPauseTime is None and newPosition >= self.nextPauseTime:
         self.pause()  # auto-pause
         return
     if self.skipIntro and newPosition > self.content.audioEnd:
         self.stop()
         self.chapter_ended.emit()
         return
     if not self.prevPosition == newPosition:
         self.prevPosition = newPosition
         self.position_changed.emit(newPosition)
         if self.content:
             tkn = self.content.currentToken(newPosition)
             if tkn != self.token:
                 self.token = tkn
                 if tkn >= 0:
                     tkn_obj = model.Token(tkn, *self.content.audioMap[tkn])
                     bead = self.content.currentBead(tkn_obj.text_end)
                     if bead != self.bead:
                         self.bead = bead
                         bead_obj = model.Bead(*self.content.beads[bead])
                         self.bead_changed.emit(bead_obj)
                         self.currentBead = bead_obj
                     self.token_changed.emit(tkn_obj)
                     self.currentToken = tkn_obj
コード例 #3
0
def get_top_tokens(limit=100):
    r_tokens = requests.get(__endpoint_tokens_limit.format(limit)).json()
    tokens = []
    for r_token in r_tokens:
        try:
            tokens.append(model.Token(r_token))
        except:
            pass
    return tokens
コード例 #4
0
def search_tokens(search, limit=100):
    r_tokens = requests.get(__endpoint_tokens_all).json()
    tokens = []
    for r_token in r_tokens:
        try:
            token = model.Token(r_token)
            if token.matches(search):
                tokens.append(token)
            if len(tokens) >= limit:
                break
        except:
            pass
    return tokens
コード例 #5
0
ファイル: auth.py プロジェクト: fi-ksi/web-backend
    def __init__(self, client_id):
        self.value = _generate_token()
        self.expire = datetime.datetime.utcnow() + datetime.timedelta(hours=1)
        self.kind = 'Bearer'
        self.refresh = _generate_token()

        token = model.Token()
        token.access_token = self.value
        token.expire = self.expire
        token.refresh_token = self.refresh
        token.user = client_id

        try:
            session.add(token)
            session.commit()
        except:
            session.rollback()
            raise