imgurup Package

imgurup Package

class imgurup.__init__.CLIImgur(client_id='55080e3fd8d0644', client_secret='d021464e1b3244d6f73749b94d17916cf361da24')

Bases: imgurup.__init__.Imgur

ask_album_id(albums)
ask_image_path()
ask_pin(auth_msg, auth_url, enter_token_msg)
get_ask_album_id_dialog_args(albums, no_album_msg)
get_ask_image_path_dialog_args()
get_auth_msg_dialog_args(auth_msg, auth_url)
get_enter_pin_dialog_args(token_msg)
get_error_dialog_args(msg='Error')
class imgurup.__init__.Imgur(client_id='55080e3fd8d0644', client_secret='d021464e1b3244d6f73749b94d17916cf361da24')

Bases: object

CONFIG_PATH = '/home/docs/.imgurup.conf'
ask_album_id(albums)

Ask user to choose a album to upload or not belong to any album

Parameters:albums (list of dict) – Albums list
Returns:The id of the album
Return type:str
ask_image_path()

Display a file dialog and prompt the user to select a image

Returns:image path
Return type:str
ask_pin(auth_msg, auth_url, enter_token_msg)

Ask user for pin code

Parameters:
  • auth_msg (str) – Authorization message
  • auth_url (str) – Authorization url
  • enter_token_msg (str) – Prompt token message
Returns:

pin code

Return type:

str

auth()

Authorization

connect(url='api.imgur.com')

Connect to the api host, call this before calling upload() :param url: url of API server :type url: str

get_ask_album_id_dialog_args(albums, no_album_msg)

Return the subprocess args of choose album dialog

Parameters:
  • albums (list of dict) – Albums list
  • no_album_msgNot belong to any album message
Returns:

A list include dialog command

Return type:

list

get_ask_image_path_dialog_args()

Return the subprocess args of file dialog

Returns:A list include dialog command, ex: [‘kdialog’, ‘–msgbox’, ‘hi’]
Return type:list
get_auth_msg_dialog_args(auth_msg, auth_url)

Return the subprocess args of show authorization message dialog

Parameters:
  • auth_msg (str) – Authorization message
  • auth_url (str) – Authorization url
Returns:

A list include dialog command

Return type:

list

get_enter_pin_dialog_args(token_msg)

Return the subprocess args of enter pin dialog

Parameters:token_msg (str) – Enter token message
Returns:A list include dialog command
Return type:list
get_error_dialog_args(msg='Error')

Return the subprocess args of display error dialog

Parameters:msg (str) – Error message
Returns:A list include dialog command, ex: [‘kdialog’, ‘–msgbox’, ‘hello’]
Return type:list

Return the subprocess args of show link dialog

Parameters:links (str) – String of the image link and delete link
Returns:A list include dialog command
Return type:list
is_success(response)

Check the value of the result is success or not

Parameters:response (dict) – The result return from the server
Returns:True if success, else False
Return type:bool
request_album_list(*args, **kwargs)
request_new_tokens()

Request new tokens

Returns:json tokens
Return type:dict
request_new_tokens_and_update()

Request and update the access token and refresh token

request_upload_image(*args, **kwargs)
retry(errors=(<class 'imgurup.__init__.ImgurError'>, <class 'httplib.BadStatusLine'>))

Retry calling the decorated function using an exponential backoff.

http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/ original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry

set_tokens_using_config()

Read the token value from the config file Set tokens to None if can’t be found in config

show_error_and_exit(msg='Error')

Display error message and exit the program

Parameters:msg (str) – Error message

Show image link

Parameters:
  • image_link (str) – Image link
  • delete_hash (str) – Image delete hash string
upload(image_path=None, meta=None)

Upload a image

Parameters:
  • image_path (str) – The path of the image you want to upload
  • meta (dict) – Meta information of anonymous and album id
Returns:

write_tokens_to_config()

Write token value to the config

exception imgurup.__init__.ImgurError

Bases: exceptions.Exception

class imgurup.__init__.ImgurFactory

Used to produce imgur instance. ex: imgur = ImgurFactory.get_imgur(ImgurFactory.detect_env(is_gui))

static get_instance(prefer_gui=True, **kwargs)

Detect environment

Parameters:
  • prefer_gui (bool) – If False, choose CLI, otherwise detect settings and choose a GUI mode
  • kwargs – remaining keyword arguments passed to Imgur
Tpe kwargs:

dict

Returns:

Subclass of Imgur

Return type:

Imgur

class imgurup.__init__.KDEImgur(client_id='55080e3fd8d0644', client_secret='d021464e1b3244d6f73749b94d17916cf361da24')

Bases: imgurup.__init__.Imgur

get_ask_album_id_dialog_args(albums, no_album_msg)
get_ask_image_path_dialog_args()
get_auth_msg_dialog_args(auth_msg, auth_url)
get_enter_pin_dialog_args(token_msg)
get_error_dialog_args(msg='Error')
class imgurup.__init__.MacImgur(client_id='55080e3fd8d0644', client_secret='d021464e1b3244d6f73749b94d17916cf361da24')

Bases: imgurup.__init__.Imgur

ask_album_id(albums)
get_ask_album_id_dialog_args(albums, no_album_msg)
get_ask_image_path_dialog_args()
get_auth_msg_dialog_args(auth_msg, auth_url)
get_enter_pin_dialog_args(token_msg)
get_error_dialog_args(msg='Error')
class imgurup.__init__.ZenityImgur(client_id='55080e3fd8d0644', client_secret='d021464e1b3244d6f73749b94d17916cf361da24')

Bases: imgurup.__init__.Imgur

get_ask_album_id_dialog_args(albums, no_album_msg)
get_ask_image_path_dialog_args()
get_auth_msg_dialog_args(auth_msg, auth_url)
get_enter_pin_dialog_args(token_msg)
get_error_dialog_args(msg='Error')
imgurup.__init__.main()