<commit_before>#!/usr/bin/python
# coding=UTF-8

#Import wx for create GUI interface
import wx 
#Import os for using system command
import os
#Import datatime to get current time
import datetime
#Import webbrowser to ask for authorization
import webbrowser
#Import json to encoding the string to json file
import json

#Import imgurpython to upload the image
from imgurpython import ImgurClient
openAppKey = open("appkey","r")
appKey = json.loads(file.read(openAppKey))

client = ImgurClient(appKey['client_id'], appKey['client_secret'])

#Import the UI interface
import gui

#Capture screen function
current = datetime.datetime.now()

filename = "Plurk" + current.strftime("%Y-%m-%d") +".png"

catureCmd1 = "screencapture " + filename

catureCmd2 = "screencapture -i " + filename

class mainFrame(gui.mainFrame):
 
    def __init__(self, parent):
        gui.mainFrame.__init__(self, parent)
 
    def catureFullScreen(self, event):
        os.system(catureCmd1)

        if os.path.exists('token.saved'):
            print "檔案存在！"

        else:
            self.Show(False)
            pinFrame(None).Show(True)

    def caturePart(self, event):
    	os.system(catureCmd2)
        self.Show(False)
        pinFrame(None).Show(True)

#If user do not have a access token for imgur, ask pin and get token
class pinFrame(gui.pinFrame):
 
    def __init__(self, parent):
        gui.pinFrame.__init__(self, parent)

    def getPinFromWebSite(self, event):
        auth_url = client.get_auth_url('pin')
        webbrowser.open(auth_url)

    def sendPin(self, event):
        pin = self.inputPin.GetValue()
        credentials = client.authorize(pin, 'pin')
        client.set_user_auth(credentials['access_token'], credentials['refresh_token'])

#Save token to file
        saveToken = file('token.saved', 'w')
        token = {"access_token":credentials['access_token'],"refresh_token":credentials['refresh_token']}

        saveToken.write(json.dumps(token))
        
        uploadImage()

def uploadImage():
    uploaded_image = client.upload_from_path(filename, config=None, anon=False)
    imagelink = uploaded_image['link']
    print imagelink<commit_msg>Can using existed token to upload image<commit_after>#!/usr/bin/python
# coding=UTF-8

#Import wx for create GUI interface
import wx 
#Import os for using system command
import os
#Import datatime to get current time
import datetime
#Import webbrowser to ask for authorization
import webbrowser
#Import json to encoding the string to json file
import json

#Import imgurpython to upload the image
from imgurpython import ImgurClient
openAppKey = open("appkey","r")
appKey = json.loads(file.read(openAppKey))

client = ImgurClient(appKey['client_id'], appKey['client_secret'])

#Import the UI interface
import gui

#Capture screen function
current = datetime.datetime.now()

filename = "Plurk" + current.strftime("%Y-%m-%d") +".png"

catureCmd1 = "screencapture " + filename

catureCmd2 = "screencapture -i " + filename

class mainFrame(gui.mainFrame):
 
    def __init__(self, parent):
        gui.mainFrame.__init__(self, parent)
 
    def catureFullScreen(self, event):
        os.system(catureCmd1)

        if os.path.exists('token.saved'):
            self.Show(False)
            openToken = open("token.saved","r")
            token = json.loads(file.read(openToken))
            client.set_user_auth(token['access_token'], token['refresh_token'])
            uploadImage()

        else:
            self.Show(False)
            pinFrame(None).Show(True)

    def caturePart(self, event):
    	os.system(catureCmd2)

        if os.path.exists('token.saved'):
            self.Show(False)
            openToken = open("token.saved","r")
            token = json.loads(file.read(openToken))
            client.set_user_auth(token['access_token'], token['refresh_token'])
            uploadImage()

        else:
            self.Show(False)
            pinFrame(None).Show(True)

#If user do not have a access token for imgur, ask pin and get token
class pinFrame(gui.pinFrame):
 
    def __init__(self, parent):
        gui.pinFrame.__init__(self, parent)

    def getPinFromWebSite(self, event):
        auth_url = client.get_auth_url('pin')
        webbrowser.open(auth_url)

    def sendPin(self, event):
        pin = self.inputPin.GetValue()
        credentials = client.authorize(pin, 'pin')
        client.set_user_auth(credentials['access_token'], credentials['refresh_token'])

#Save token to file
        saveToken = file('token.saved', 'w')
        token = {"access_token":credentials['access_token'],"refresh_token":credentials['refresh_token']}

        saveToken.write(json.dumps(token))
        
        uploadImage()

def uploadImage():
    uploaded_image = client.upload_from_path(filename, config=None, anon=False)
    imagelink = uploaded_image['link']
    print imagelink
{'fraction_non_alphanumeric': 0.11403869905310828, 'fraction_numerical': 0.0020584602717167557, 'mean_word_length': 3.413260672116258, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3538878', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1468, 'n_words': 356}