imgurup Package

imgurup Package

class imgurup.__init__.CLIImgur(url='api.imgur.com', 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(url='api.imgur.com', client_id='55080e3fd8d0644', client_secret='d021464e1b3244d6f73749b94d17916cf361da24')

Bases: object

CONFIG_PATH = '/Users/carlcarl/.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

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 album list with the account

Parameters:account (str) – The account name, ‘me’ means yourself
Returns:Response of requesting albums list (json)
Return type:list of dict
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)

Request upload image

Parameters:
  • url (str) – Upload url
  • body (str) – The content string of the request
  • headers (dict) – The headers of the request
Returns:

Response of upload image

Return type:

dict

retry(tries=2, delay=1)

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

Parameters:
  • tries (int) – number of times to try (not retry) before giving up
  • delay (int) – initial delay between retries in seconds
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 There will be maybe more setting needed to be written to config So I just pass result

class imgurup.__init__.ImgurFactory

Used to produce imgur instance. You can call detect_env to auto get a suitable imgur class, and use it as argument in get_imgur. ex: imgur = ImgurFactory.get_imgur(ImgurFactory.detect_env(is_gui)) you can also manually choose a imgur class, ex: imgur = ImgurFactory.get_imgur(KDEImgur)

static detect_env(is_gui=True)

Detect environment

Parameters:is_gui (bool) – If False, choose CLI, otherwise detect settings and choose a GUI mode
Returns:Subclass of Imgur
Return type:type
static get_imgur(imgur_class)

Get imgur instance

Parameters:imgur_class (type) – The subclass name of Imgur
Returns:Imgur instance
class imgurup.__init__.KDEImgur(url='api.imgur.com', 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(url='api.imgur.com', 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(url='api.imgur.com', 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()

Table Of Contents

Previous topic

imgurup

This Page