import gmusicapi
from mopidy import commands
from oauth2client.client import OAuth2WebServerFlow


class GMusicCommand(commands.Command):
    def __init__(self):
        super().__init__()
        self.add_child("login", LoginCommand())


class LoginCommand(commands.Command):
    def run(self, args, config):
        oauth_info = gmusicapi.Mobileclient._session_class.oauth
        flow = OAuth2WebServerFlow(**oauth_info._asdict())
        print()
        print(
            "Go to the following URL to get an initial auth code, then "
            + "provide it below: "
            + flow.step1_get_authorize_url()
        )
        print()
        try:
            initial_code = raw_input("code: ")
        except NameError:
            # Python 3
            initial_code = input("code: ")
        credentials = flow.step2_exchange(initial_code)
        refresh_token = credentials.refresh_token
        print("\nPlease update your config to include the following:")
        print()
        print("[gmusic]")
        print("refresh_token =", refresh_token)
        print()

import gmusicapi
from mopidy import commands
from oauth2client.client import OAuth2WebServerFlow


class GMusicCommand(commands.Command):
    def __init__(self):
        super().__init__()
        self.add_child("login", LoginCommand())


class LoginCommand(commands.Command):
    def run(self, args, config):
        oauth_info = gmusicapi.Mobileclient._session_class.oauth
        flow = OAuth2WebServerFlow(**oauth_info._asdict())
        print()
        print(
            "Go to the following URL to get an initial auth code, "
            "then provide it below:"
        )
        print(flow.step1_get_authorize_url())
        print()
        initial_code = input("code: ")
        credentials = flow.step2_exchange(initial_code)
        refresh_token = credentials.refresh_token
        print("\nPlease update your config to include the following:")
        print()
        print("[gmusic]")
        print("refresh_token =", refresh_token)
        print()

Remove Python 2 compatibility code
py3: Remove Python 2 compatibility code

  import gmusicapi
  from mopidy import commands
  from oauth2client.client import OAuth2WebServerFlow
  
  
  class GMusicCommand(commands.Command):
      def __init__(self):
          super().__init__()
          self.add_child("login", LoginCommand())
  
  
  class LoginCommand(commands.Command):
      def run(self, args, config):
          oauth_info = gmusicapi.Mobileclient._session_class.oauth
          flow = OAuth2WebServerFlow(**oauth_info._asdict())
          print()
          print(
-             "Go to the following URL to get an initial auth code, then "
+             "Go to the following URL to get an initial auth code, "
-             + "provide it below: "
+             "then provide it below:"
-             + flow.step1_get_authorize_url()
          )
+         print(flow.step1_get_authorize_url())
          print()
-         try:
-             initial_code = raw_input("code: ")
-         except NameError:
-             # Python 3
-             initial_code = input("code: ")
+         initial_code = input("code: ")
          credentials = flow.step2_exchange(initial_code)
          refresh_token = credentials.refresh_token
          print("\nPlease update your config to include the following:")
          print()
          print("[gmusic]")
          print("refresh_token =", refresh_token)
          print()
  
Remove Python 2 compatibility code
## Code Before:
import gmusicapi
from mopidy import commands
from oauth2client.client import OAuth2WebServerFlow


class GMusicCommand(commands.Command):
    def __init__(self):
        super().__init__()
        self.add_child("login", LoginCommand())


class LoginCommand(commands.Command):
    def run(self, args, config):
        oauth_info = gmusicapi.Mobileclient._session_class.oauth
        flow = OAuth2WebServerFlow(**oauth_info._asdict())
        print()
        print(
            "Go to the following URL to get an initial auth code, then "
            + "provide it below: "
            + flow.step1_get_authorize_url()
        )
        print()
        try:
            initial_code = raw_input("code: ")
        except NameError:
            # Python 3
            initial_code = input("code: ")
        credentials = flow.step2_exchange(initial_code)
        refresh_token = credentials.refresh_token
        print("\nPlease update your config to include the following:")
        print()
        print("[gmusic]")
        print("refresh_token =", refresh_token)
        print()

## Instruction:
Remove Python 2 compatibility code
## Code After:
import gmusicapi
from mopidy import commands
from oauth2client.client import OAuth2WebServerFlow


class GMusicCommand(commands.Command):
    def __init__(self):
        super().__init__()
        self.add_child("login", LoginCommand())


class LoginCommand(commands.Command):
    def run(self, args, config):
        oauth_info = gmusicapi.Mobileclient._session_class.oauth
        flow = OAuth2WebServerFlow(**oauth_info._asdict())
        print()
        print(
            "Go to the following URL to get an initial auth code, "
            "then provide it below:"
        )
        print(flow.step1_get_authorize_url())
        print()
        initial_code = input("code: ")
        credentials = flow.step2_exchange(initial_code)
        refresh_token = credentials.refresh_token
        print("\nPlease update your config to include the following:")
        print()
        print("[gmusic]")
        print("refresh_token =", refresh_token)
        print()
