<commit_before>from sys import platform
import subprocess
import requests
import time
import sys


# Fetch songs with spotify api
class Spotipy:
    url = 'https://ws.spotify.com/search/1/track.json?q='

    # Get our data
    def __init__(self):
        self._songs = {}
        self._history = []
        self._data = None

        if 'linux' in platform:
            import dbus

            try:
                self.interface = dbus.Interface(
                    dbus.SessionBus().get_object(
                        'org.mpris.MediaPlayer2.spotify',
                        '/org/mpris/MediaPlayer2'
                        ),
                        'org.mpris.MediaPlayer2.Player'
                    )

            except dbus.exceptions.DBusException:
                sys.exit('\n Some errors occured. Try restart or start Spotify. \n')

    def search(self, query):
        try:
            response = requests.get(self.url + query)

            self._data = response.json()

            self._history.append(query)
        except StandardError:
            print('Search went wrong? Please try again.')

    # List all. Limit if needed
    def list(self, limit=100):
        space = '{0:3} | {1:25} | {2:30} | {3:30}'

        print(space.format('#', 'Artist', 'Song', 'Album'))
        # Just to make it pwitty
        print(space.format(
            '-' * 3,
            '-' * 25,
            '-' * 30,
            '-' * 30
        ))

        for index, song in enumerate(self._data['tracks']):
            if index == limit:
                break

            print(space.format(
                '%d.' % (index + 1),
                song['artists'][0]['name'][:25],
                song['name'][:30],
                song['album']['name'][:30]
            ))

            # Save spotify uri and song for later use
            self._songs[index + 1] = {
                'href': song['href'],
                'song': '%s - %s' % (song['artists'][0]['name'].encode('utf-8'), song['name'].encode('utf-8'))
            }

            # Sleep's just for the sexy output
            time.sleep(0.01)

    def listen(self, index):
        uri = str(self._songs[index]['href'])
<commit_msg>encode issues in p3 and p2. Fixed.<commit_after>from sys import platform
import subprocess
import requests
import time
import sys


# Fetch songs with spotify api
class Spotipy:
    # Api url
    url = 'https://ws.spotify.com/search/1/track.json?q='

    # hold songs
    _songs = {}

    # history
    _history = []

    # data
    _data = None

    # Get our data
    def __init__(self):
        if 'linux' in platform:
            import dbus

            try:
                self.interface = dbus.Interface(
                    dbus.SessionBus().get_object(
                        'org.mpris.MediaPlayer2.spotify',
                        '/org/mpris/MediaPlayer2'
                        ),
                        'org.mpris.MediaPlayer2.Player'
                    )

            except dbus.exceptions.DBusException:
                sys.exit('\n Some errors occured. Try restart or start Spotify. \n')

    def search(self, query):
        try:
            response = requests.get(self.url + query)

            self._data = response.json()

            self._history.append(query)
        except StandardError:
            print('Search went wrong? Please try again.')

    # List all. Limit if needed
    def list(self, limit=100):
        space = '{0:3} | {1:25} | {2:30} | {3:30}'

        print(space.format('#', 'Artist', 'Song', 'Album'))

        # Just to make it pwitty
        print(space.format(
            '-' * 3,
            '-' * 25,
            '-' * 30,
            '-' * 30
        ))

        for index, song in enumerate(self._data['tracks']):
            if index == limit:
                break

            if sys.version_info >= (3, 0):
                artist_name = song['artists'][0]['name'][:25]
                song_name = song['name'][:30]
                album_name = song['album']['name'][:30]
            else:
                artist_name = song['artists'][0]['name'][:25].encode('utf-8')
                song_name = song['name'][:30].encode('utf-8')
                album_name = song['album']['name'][:30].encode('utf-8')

            print(space.format(
                '%d.' % (index + 1),
                '%s' % artist_name,
                '%s' % song_name,
                '%s' % album_name
            ))

            # Save spotify uri and song for later use
            self._songs[index + 1] = {
                'href': song['href'],
                'song': '%s - %s' % (artist_name, song_name)
            }

            # Sleep's just for the sexy output
            time.sleep(0.01)

    def listen(self, index):
        uri = str(self._songs[index]['href'])

{'fraction_non_alphanumeric': 0.13710012463647694, 'fraction_numerical': 0.018903199002908183, 'mean_word_length': 1.4355083459787557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4848959', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1363, 'n_words': 322}