Exemplo n.º 1
0
    def new_token(self):
        #retrieving a new token
        print("Refreshing token. . .")

        callRefresh = Refresh()
        self.access_token = callRefresh.refresh()
        self.find_songs()
    def call_refresh(self):
        print("Refreshing token...")
        refresh_caller = Refresh()
        self.spotify_token = refresh_caller.refresh()

        # call find_songs
        self.find_songs()
Exemplo n.º 3
0
 def call_refresh(self):
     print("refreshing token")
     refresh_caller = Refresh()
     self.spotify_token = refresh_caller.refresh()
     self.authorizer = {
         "Content-Type": "application/json",
         "Authorization": "Bearer {}".format(self.spotify_token)
     }
Exemplo n.º 4
0
    def call_refresh(self, args):

        print("Refreshing token")

        refreshCaller = Refresh()

        self.spotify_token = refreshCaller.refresh()

        self.add_to_playlist(args)
Exemplo n.º 5
0
    def call_refresh(self):

        print("Refreshing token")

        refreshCaller = Refresh()

        self.spotify_token = refreshCaller.refresh()

        self.find_songs()
Exemplo n.º 6
0
def index(request):
    if not has_been_called:
        refreshThread = Refresh()
        refreshThread.start()
        global has_been_called
        has_been_called = True

    if 'query' in request.GET:
        return party_search_results(request, request.GET['query'])

    user = request.user
    anon = user.is_anonymous()
    admin = user.is_staff

    if not anon:
        if not Voter.objects.exists():
            current_voter = Voter(username=request.user.username)
            current_voter.save()
        elif Voter.objects.last().username != request.user.username:
            current_voter, _ = Voter.objects.get_or_create(username=request.user.username)
            current_voter.save()

    return render(request, 'index.html', {'anon': anon, 'redirect': False, 'admin': admin})
Exemplo n.º 7
0
    def get_streams(self):

        # Get user_id
        url = f'https://api.twitch.tv/helix/users?login={self.user_name}'
        r = requests.get(url, headers=self.headers)
        logging.info(r.json())
        try:
            user_id = r.json()['data'][0]['id']
        except KeyError:
            if r.json()['message'] == 'Invalid OAuth token':
                print("Invalid Oauth token, resetting . . .")
                new_access_token = Refresh.get_access_token()
                print(f"Refreshed Access Token: {new_access_token}")
                print("Writing to './keys.json' . . .")
                Write.write({'access_token': new_access_token}, './keys.json')
                print("Successfully wrote new access token to './keys.json'")
                sys.exit(0)
            else:
                print("An unexpected error occurred")
                sys.exit(1)

        # Get twitch users you follow
        url = f'https://api.twitch.tv/helix/users/follows?from_id={user_id}'
        r = requests.get(url, headers=self.headers)
        data = r.json()
        followed = []
        for streamer in data['data']:
            followed.append(streamer['to_name'])

        # Sort twitch users
        url = 'https://api.twitch.tv/helix/streams?user_login='******'data']) == 0:
                streams['away'].append(streamer)
            else:
                streams['live'].append(streamer)

        # Create return string
        list = "Live:\n"
        for i in streams['live']:
            list += "          {}\n".format(i)
        list += "Away:\n"
        for i in streams['away']:
            list += "          {}\n".format(i)

        return list
Exemplo n.º 8
0
import requests
import json
from refresh import Refresh
from random import randint
from time import sleep


token = Refresh().refresh()

def play_playlist():

    query = "https://api.spotify.com/v1/me/player/play?device_id=52c39de05bdc3823b15b0ff3187bd13ee92257fb"

    position = randint(0, get_playlist_number() - 3)

    request_body = json.dumps({"context_uri": "spotify:playlist:5xToaLxyFVTuyh6m1wheip",
    "offset": {"position": position},
    "position_ms": 20})

    requests.put(query,
        data = request_body,
        headers = {"Authorization":f"Bearer {token}"})

def get_playlist_number():

    query = f"https://api.spotify.com/v1/playlists/5xToaLxyFVTuyh6m1wheip"

    response = requests.get(query,
        headers = {"Authorization":f"Bearer {token}"})
    
    response_json = response.json()
Exemplo n.º 9
0
    if os.path.isfile(qtconf):
        os.remove(qtconf)
    qtconf_file = open(qtconf, mode='w')
    qtconf_file.write('[Paths]\n')
    qtconf_file.write('Prefix = ' + pyqt4dir + '\n')
    qtconf_file.write('Binaries = ' + pyqt4dir + '\n')
    qtconf_file.close()

from cgrupyqt import QtGui

import cgruconfig
import cmd
from refresh import Refresh
from tray import Tray
from server import Server

# Define keeper launch command if was not:
keeper_cmd = os.getenv('CGRU_KEEPER_CMD')
if keeper_cmd is None:
    keeper_cmd = '"%s" "%s"' % (os.getenv('CGRU_PYTHONEXE'), sys.argv[0])
cgruconfig.VARS['CGRU_KEEPER_CMD'] = keeper_cmd

# Create tray application with refresh:
app = QtGui.QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False)
cmd.Application = app
cmd.Tray = Tray(app)
refresh = Refresh(app)
server = Server(app)
app.exec_()
 def start(self):
     print("Refreshing token....")
     refreshCaller = Refresh()
     self.spotify_access_token = refreshCaller.refresh()
     self.find_songs()