import plotly.offline as py_offline

### Offline Mode	

def go_offline(connected=False):
	try:
		py_offline.init_notebook_mode(connected)
	except TypeError:
		#For older versions of plotly
		py_offline.init_notebook_mode()
	py_offline.__PLOTLY_OFFLINE_INITIALIZED=True

def go_online():
	py_offline.__PLOTLY_OFFLINE_INITIALIZED=False

def is_offline():
	return py_offline.__PLOTLY_OFFLINE_INITIALIZED

def upgrade(url=None):
	from .auth import get_config_file
	if not url:
		if 'http' not in get_config_file()['offline_url']:
			raise Exception("No default offline URL set \n"
							"Please run cf.set_config_file(offline_url=xx) to set \n"
							"the default offline URL.")
		else:
			url=get_config_file()['offline_url']
	py_offline.download_plotlyjs(url)

import plotly.offline as py_offline

### Offline Mode	

def run_from_ipython():
    try:
        __IPYTHON__
        return True
    except NameError:
        return False


def go_offline(connected=False):
    if run_from_ipython():
        try:
            py_offline.init_notebook_mode(connected)
        except TypeError:
            #For older versions of plotly
            py_offline.init_notebook_mode()
        py_offline.__PLOTLY_OFFLINE_INITIALIZED=True

def go_online():
	py_offline.__PLOTLY_OFFLINE_INITIALIZED=False

def is_offline():
	return py_offline.__PLOTLY_OFFLINE_INITIALIZED

def upgrade(url=None):
	from .auth import get_config_file
	if not url:
		if 'http' not in get_config_file()['offline_url']:
			raise Exception("No default offline URL set \n"
							"Please run cf.set_config_file(offline_url=xx) to set \n"
							"the default offline URL.")
		else:
			url=get_config_file()['offline_url']
	py_offline.download_plotlyjs(url)

Call init_notebook_mode only if inside IPython
Call init_notebook_mode only if inside IPython

  import plotly.offline as py_offline
  
  ### Offline Mode	
  
+ def run_from_ipython():
+     try:
+         __IPYTHON__
+         return True
+     except NameError:
+         return False
+ 
+ 
  def go_offline(connected=False):
- 	try:
+     if run_from_ipython():
+         try:
- 		py_offline.init_notebook_mode(connected)
+             py_offline.init_notebook_mode(connected)
- 	except TypeError:
+         except TypeError:
- 		#For older versions of plotly
+             #For older versions of plotly
- 		py_offline.init_notebook_mode()
+             py_offline.init_notebook_mode()
- 	py_offline.__PLOTLY_OFFLINE_INITIALIZED=True
+         py_offline.__PLOTLY_OFFLINE_INITIALIZED=True
  
  def go_online():
  	py_offline.__PLOTLY_OFFLINE_INITIALIZED=False
  
  def is_offline():
  	return py_offline.__PLOTLY_OFFLINE_INITIALIZED
  
  def upgrade(url=None):
  	from .auth import get_config_file
  	if not url:
  		if 'http' not in get_config_file()['offline_url']:
  			raise Exception("No default offline URL set \n"
  							"Please run cf.set_config_file(offline_url=xx) to set \n"
  							"the default offline URL.")
  		else:
  			url=get_config_file()['offline_url']
  	py_offline.download_plotlyjs(url)
  
Call init_notebook_mode only if inside IPython
## Code Before:
import plotly.offline as py_offline

### Offline Mode	

def go_offline(connected=False):
	try:
		py_offline.init_notebook_mode(connected)
	except TypeError:
		#For older versions of plotly
		py_offline.init_notebook_mode()
	py_offline.__PLOTLY_OFFLINE_INITIALIZED=True

def go_online():
	py_offline.__PLOTLY_OFFLINE_INITIALIZED=False

def is_offline():
	return py_offline.__PLOTLY_OFFLINE_INITIALIZED

def upgrade(url=None):
	from .auth import get_config_file
	if not url:
		if 'http' not in get_config_file()['offline_url']:
			raise Exception("No default offline URL set \n"
							"Please run cf.set_config_file(offline_url=xx) to set \n"
							"the default offline URL.")
		else:
			url=get_config_file()['offline_url']
	py_offline.download_plotlyjs(url)

## Instruction:
Call init_notebook_mode only if inside IPython
## Code After:
import plotly.offline as py_offline

### Offline Mode	

def run_from_ipython():
    try:
        __IPYTHON__
        return True
    except NameError:
        return False


def go_offline(connected=False):
    if run_from_ipython():
        try:
            py_offline.init_notebook_mode(connected)
        except TypeError:
            #For older versions of plotly
            py_offline.init_notebook_mode()
        py_offline.__PLOTLY_OFFLINE_INITIALIZED=True

def go_online():
	py_offline.__PLOTLY_OFFLINE_INITIALIZED=False

def is_offline():
	return py_offline.__PLOTLY_OFFLINE_INITIALIZED

def upgrade(url=None):
	from .auth import get_config_file
	if not url:
		if 'http' not in get_config_file()['offline_url']:
			raise Exception("No default offline URL set \n"
							"Please run cf.set_config_file(offline_url=xx) to set \n"
							"the default offline URL.")
		else:
			url=get_config_file()['offline_url']
	py_offline.download_plotlyjs(url)
