Beispiel #1
0
class SpotifyService:
    def __init__(self):
        self.auth_token = AuthToken()
        self.access_token = self.auth_token.get_access_token()

    def get_user_playlist_collection(self):
        url = "https://api.spotify.com/v1/me/playlists"
        request = requests.get(url,
                               headers={
                                   "Content-Type": "application/json",
                                   "Authorization": f"Bearer {O_AUTH}"
                               })

        return json.loads(json.dumps(request.json()))

    def get_playlist(self, playlist_id):
        url = "https://api.spotify.com/v1/playlists/{}".format(playlist_id)
        request = requests.get(url,
                               headers={
                                   "Content-Type": "application/json",
                                   "Authorization":
                                   f"Bearer {self.access_token}"
                               })

        return json.loads(json.dumps(request.json()))

    def get_track(self, track_id):
        url = "https://api.spotify.com/v1/tracks/{}".format(track_id)
        request = requests.get(url,
                               headers={
                                   "Content-Type": "application/json",
                                   "Authorization":
                                   f"Bearer {self.access_token}"
                               })
        return json.loads(json.dumps(request.json()))
class AuthData:
    id = -1
    mail_address = ""
    password = ""
    access_token = AuthToken()
    refresh_token = AuthToken()
    is_active = False

    def __init__(self, id, mail_address, password, is_active):
        self.id = id
        self.mail_address = mail_address
        self.password = password
        self.is_active = is_active

    def refreshToken(self):
        self.access_token = AuthToken()
        self.refresh_token = AuthToken()
        baseDatetime = datetime.datetime.now()
        self.access_token.setExpireMinutes(baseDatetime, 1)
        self.refresh_token.setExpireMinutes(baseDatetime, 3)

    def validate(self, check_mail_address, check_password):
        is_same_address = self.mail_address == check_mail_address
        is_same_password = self.password == check_password
        return is_same_address & is_same_password
Beispiel #3
0
def login():
    input_data = request.get_json()
    username = input_data.get('username')
    password = input_data.get('password')
    if username is None or password is None:
        abort(400)
    student = Student()
    try:
        student.login(username, password)
    except InvalidCredential as error:
        abort(401, str(error))
    g.db.set('shu-library-{}'.format(username), pickle.dumps(student), ex=3600)
    return jsonify({'token': AuthToken().generate_jwt(username)})
Beispiel #4
0
def histories():
    authorization = request.headers.get('Authorization')
    if authorization is None or not authorization.startswith('Bearer '):
        abort(403)
    token = authorization[7:]
    try:
        username = AuthToken().validate_jwt(token)
        raw_student_data = g.db.get('shu-library-{}'.format(username))
        if raw_student_data is None:
            abort(403)
        student = pickle.loads(raw_student_data)
        return jsonify({'histories': student.get_histories()})
    except CredentialRequired:
        abort(403)
    except BadToken as error:
        abort(403, str(error))
Beispiel #5
0
def loans():
    authorization = request.headers.get('Authorization')
    if authorization is None or not authorization.startswith('Bearer '):
        abort(403)
    token = authorization[7:]
    try:
        username = AuthToken().validate_jwt(token)
        raw_student_data = g.db.get('shu-library-{}'.format(username))
        if raw_student_data is None:
            abort(403)
        student = pickle.loads(raw_student_data)
        _loans = student.get_loans()
        g.db.set('shu-library-{}'.format(username),
                 pickle.dumps(student),
                 ex=3600)
        return jsonify({'loans': _loans})
    except CredentialRequired:
        abort(403)
    except BadToken as error:
        abort(403, str(error))
    except Exception as error:
        abort(500, str(error))
Beispiel #6
0
from flask import Flask, render_template, url_for, request, redirect
import requests
import json
from albums import Albums
from datetime import datetime
from auth_token import AuthToken
import time

app = Flask(__name__)

token = AuthToken()


@app.route('/auth')
def auth():
    client_id = "26fd557b95a64a33ab3293032169caed"
    redirect_url = "http://*****:*****@app.route('/callback')
def callback():
    code = request.args.get('code')
    response = requests.post(
        "https://accounts.spotify.com/api/token",
        data={
            "grant_type": "authorization_code",
            "code": code,
Beispiel #7
0
 def test_positive(self):
     authtoken = AuthToken(TestAuthTokens.URL)
     self.assertEqual(36, len(authtoken.get_token('admin', 'admin')))
Beispiel #8
0
 def test_negative(self):
     authtoken = AuthToken(TestAuthTokens.URL)
     with self.assertRaises(AuthErr):
         authtoken.get_token('admin', 'test')
 def refreshToken(self):
     self.access_token = AuthToken()
     self.refresh_token = AuthToken()
     baseDatetime = datetime.datetime.now()
     self.access_token.setExpireMinutes(baseDatetime, 1)
     self.refresh_token.setExpireMinutes(baseDatetime, 3)
 def __init__(self):
     a = AuthToken()
     self.lyrics_token = a.get_lyrics_genius_token()
     self.lyrics_genius = lyricsgenius.Genius(self.lyrics_token)
     self.spotify_client = SpotifyClient()
Beispiel #11
0
from register import Register
from reporter import Reporter
from controller import *
from config import Config

config = Config()
AUTH_URL = config.get_auth_url()
AUTH_USERNAME = config.get_auth_username()
AUTH_PASSWORD = config.get_auth_password()
REPORT_URL = config.get_report_url()
REGISTER_URL = config.get_register_url()
INTERVAL = config.get_interval()

device = Device()
Controller.device = device
auth_token = AuthToken(AUTH_URL, AUTH_USERNAME, AUTH_PASSWORD)


def report(interval):
    print "[Info - Reporter] Thread Start"
    reporter = Reporter(REPORT_URL, device)
    while True:
        try:
            resp = reporter.report(auth_token.get_token())
            print resp
        except Exception as exception:
            print exception
            pass
        time.sleep(interval)

Beispiel #12
0
 def __init__(self):
     self.auth_token = AuthToken()
     self.access_token = self.auth_token.get_access_token()