def keyrefresh():
	accesstoken, refreshtoken = conf.da_token()
	CLIENT_ID, CLIENT_SECRET = conf.da_client()
	client_auth = requests.auth.HTTPBasicAuth(CLIENT_ID, CLIENT_SECRET)
	post_data = {"grant_type": "refresh_token", "refresh_token": refreshtoken}
	response = requests.post("https://www.deviantart.com/oauth2/token", auth=client_auth, data=post_data)
	parsed_json = response.json()
	if parsed_json['status'] == 'success':
		configuration = 'conf.json'
		with open(configuration) as data_file:    
			data = json.load(data_file)
		data['deviantart']['accesstoken'] = parsed_json['access_token']
		data['deviantart']['refreshtoken'] = parsed_json['refresh_token']
		with open(configuration, 'w') as f:
			json.dump(data, f, sort_keys = True, indent = 4,ensure_ascii=False)
		global access_token
		access_token,refresh_token = conf.da_token()
	return parsed_json['status']
from flask import Flask, abort, request, redirect
from uuid import uuid4
from support import conf
import requests, requests.auth, urllib, json

#This script is used to get access tokens from deviantart, to get this working, you must fill out Client Id and Client Secret in conf.json with your own values via creating a new application at http://deviantart.com/developers
#This is only a temporary solution until I'm finished developing the main script, a solution to this would be to run a dedicated server to hand out access tokens.
conf = 'conf.json'
CLIENT_ID, CLIENT_SECRET = conf.da_client()
REDIRECT_URI = "http://127.0.0.1:5000/da_callback"

app = Flask(__name__)
@app.route('/')


def hompage():
    state = str(uuid4())
    save_created_state(state)
    params = {"client_id": CLIENT_ID,
              "response_type": "code",
              "state": state,
              "redirect_uri": REDIRECT_URI,
			  "scope": "stash basic gallery browse"}
    try:
        url = "https://www.deviantart.com/oauth2/authorize?" + urllib.parse.urlencode(params)
    except:
        url = "https://www.deviantart.com/oauth2/authorize?" + urllib.urlencode(params)
    return redirect(url, code=302)

def save_created_state(state):
    pass