예제 #1
0
def ask_for_credentials():
    """Make an instance of the api and attempts to login with it.
    Return the authenticated api.
    """

    api = Api()

    logged_in = False
    attempts = 0

    while not logged_in and attempts < 3:
        email = raw_input("Email: ")
        password = getpass()

        logged_in = api.login(email, password)
        attempts += 1

    return api
def ask_for_credentials():
    """Make an instance of the api and attempts to login with it.
    Return the authenticated api.
    """

    api = Api()

    logged_in = False
    attempts = 0

    while not logged_in and attempts < 3:
        email = raw_input("Email: ")
        password = getpass()

        logged_in = api.login(email, password)
        attempts += 1

    return api
def no_auth_initially():
    api = Api()
    assert_false(api.is_authenticated())
def auto_playlists_are_empty():
    # this doesn't actually hit the server at the moment.
    # see issue 102
    api = Api()
    assert_equal(api.get_all_playlist_ids(auto=True, user=False),
                 {'auto': {}})
예제 #5
0
from gmusicapi import Api
from filecache import filecache
import sqlite3
import re

api = Api()
conn = sqlite3.connect('music.sqlite3', check_same_thread = False)
conn.row_factory = sqlite3.Row
cursor = conn.cursor()

def login(email, password):
    attempts = 0

    while not api.is_authenticated() and attempts < 3:
        api.login(email, password)
        attempts += 1

    if api.is_authenticated():
        print 'Logged in'
        initialise_database()
        store_songs(get_songs())
        print 'Songs cached'
    else:
        print 'Could not log in'
        exit(1)

def initialise_database():
    cursor.execute('''CREATE TABLE IF NOT EXISTS songs (
                song_id VARCHAR NOT NULL PRIMARY KEY,
                comment VARCHAR,
                rating INTEGER,