imgurup Documentation Release 1.6.0

Chien-Wei Huang

April 29, 2016

Contents

1 imgurup 3 1.1 Feature...... 3 1.2 Installation...... 3 1.3 Usage...... 3 1.4 Packcage Dependency...... 4 1.5 Todo...... 4 1.6 Customize example...... 4 1.7 License...... 5

2 Indices and tables 7 2.1 imgurup...... 7

Python Module Index 13

i ii imgurup Documentation, Release 1.6.0

API Documentation

Contents 1 imgurup Documentation, Release 1.6.0

2 Contents CHAPTER 1

imgurup

Upload to imgur using API(v3). Support CLI, KDE, Zenity(GTK) and Mac upload.

1.1 Feature

Support upload images(anonymously) or with your account. Support CLI, KDE, Zenity(GTK) and Mac dialog upload

1.2 Installation

python setup.py install

or sudo pip install imgurup

1.3 Usage

img [-h] [-f [ [ ...]]] [-d []] [-g] [-n] [-q]

You can just type img without any argument, the program will ask you for another infomation. But add -f argument with your image file would be easier to use, ex: img -f xx.jpg After the authentication, the access_token and refresh_token will be saved in ~/.imgurup.conf

Optional arguments: -h, --help show this help message and exit -f [ [ ...]] The images you want to upload -d [] The album id you want your image to be uploaded to -g GUI mode -n Anonymous upload -s Add command in the context menu of file manager(Support Gnome and KDE)

3 imgurup Documentation, Release 1.6.0

-q Choose album with each file -t Use image name as the title

1.4 Packcage Dependency

• None

1.5 Todo

• None

1.6 Customize example from imgurup import Imgur class MyImgur(Imgur):

def get_error_dialog_args(self, msg='Error'): args=[ 'zenity', '--error', '--text={text}'.format(text=msg), ] return args

def get_auth_msg_dialog_args(self, auth_msg, auth_url): args=[ 'zenity', '--entry', '--text={msg}'.format(msg=auth_msg), '--entry-text={link}'.format(link=auth_url), ] return args

def get_enter_pin_dialog_args(self, token_msg): args=[ 'zenity', '--entry', '--text={msg}'.format(msg=token_msg), ] return args

def get_ask_image_path_dialog_args(self): args=[ 'zenity', '--file-selection', ] return args

def get_ask_album_id_dialog_args(self, albums, no_album_msg):

4 Chapter 1. imgurup imgurup Documentation, Release 1.6.0

i=1 arg=[ 'zenity', '--list', '--text="Choose the album"', '--column=No.', '--column=Album name', '--column=Privacy', ] for album in albums: arg.append(str(i)) arg.append('{album[title]}'.format(album=album)) arg.append('{album[privacy]}'.format(album=album)) i+=1 arg.append(str(i)) arg.append(no_album_msg) arg.append('public')

def get_show_link_dialog_args(self, links): args=[ 'zenity', '--info', '--text={links}'.format(links=links), ] return args

1.7 License

(The MIT License) Copyright (C) 2012-2016 (Chien-Wei Huang) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documen- tation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PAR- TICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT- WARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.7. License 5 imgurup Documentation, Release 1.6.0

6 Chapter 1. imgurup CHAPTER 2

Indices and tables

• genindex • modindex • search

2.1 imgurup

2.1.1 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’) get_show_link_dialog_args(links) show_link(image_link, delete_hash) class imgurup.__init__.Imgur(url=’api.imgur.com’, 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

7 imgurup Documentation, Release 1.6.0

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_msg – Not 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

8 Chapter 2. Indices and tables imgurup Documentation, Release 1.6.0

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 get_show_link_dialog_args(links) 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=(, )) 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_link(image_link, delete_hash) 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

2.1. imgurup 9 imgurup Documentation, Release 1.6.0

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. 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’) get_show_link_dialog_args(links) 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’)

10 Chapter 2. Indices and tables imgurup Documentation, Release 1.6.0

get_show_link_dialog_args(links) show_link(image_link, delete_hash) 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’) get_show_link_dialog_args(links) imgurup.__init__.main()

2.1. imgurup 11 imgurup Documentation, Release 1.6.0

12 Chapter 2. Indices and tables Python Module Index

i imgurup.__init__,7

13 imgurup Documentation, Release 1.6.0

14 Python Module Index Index

A get_ask_image_path_dialog_args() (imgu- ask_album_id() (imgurup.__init__.CLIImgur method),7 rup.__init__.ZenityImgur method), 11 ask_album_id() (imgurup.__init__.Imgur method),7 get_auth_msg_dialog_args() (imgu- ask_album_id() (imgurup.__init__.MacImgur method), rup.__init__.CLIImgur method),7 10 get_auth_msg_dialog_args() (imgurup.__init__.Imgur ask_image_path() (imgurup.__init__.CLIImgur method), method),8 7 get_auth_msg_dialog_args() (imgu- ask_image_path() (imgurup.__init__.Imgur method),8 rup.__init__.KDEImgur method), 10 ask_pin() (imgurup.__init__.CLIImgur method),7 get_auth_msg_dialog_args() (imgu- ask_pin() (imgurup.__init__.Imgur method),8 rup.__init__.MacImgur method), 10 auth() (imgurup.__init__.Imgur method),8 get_auth_msg_dialog_args() (imgu- rup.__init__.ZenityImgur method), 11 C get_enter_pin_dialog_args() (imgu- rup.__init__.CLIImgur method),7 CLIImgur (class in imgurup.__init__),7 get_enter_pin_dialog_args() (imgurup.__init__.Imgur CONFIG_PATH (imgurup.__init__.Imgur attribute),7 method),8 D get_enter_pin_dialog_args() (imgu- rup.__init__.KDEImgur method), 10 detect_env() (imgurup.__init__.ImgurFactory static get_enter_pin_dialog_args() (imgu- method), 10 rup.__init__.MacImgur method), 10 get_enter_pin_dialog_args() (imgu- G rup.__init__.ZenityImgur method), 11 get_ask_album_id_dialog_args() (imgu- get_error_dialog_args() (imgurup.__init__.CLIImgur rup.__init__.CLIImgur method),7 method),7 get_ask_album_id_dialog_args() (imgu- get_error_dialog_args() (imgurup.__init__.Imgur rup.__init__.Imgur method),8 method),9 get_ask_album_id_dialog_args() (imgu- get_error_dialog_args() (imgurup.__init__.KDEImgur rup.__init__.KDEImgur method), 10 method), 10 get_ask_album_id_dialog_args() (imgu- get_error_dialog_args() (imgurup.__init__.MacImgur rup.__init__.MacImgur method), 10 method), 10 get_ask_album_id_dialog_args() (imgu- get_error_dialog_args() (imgurup.__init__.ZenityImgur rup.__init__.ZenityImgur method), 11 method), 11 get_ask_image_path_dialog_args() (imgu- get_imgur() (imgurup.__init__.ImgurFactory static rup.__init__.CLIImgur method),7 method), 10 get_ask_image_path_dialog_args() (imgu- get_show_link_dialog_args() (imgu- rup.__init__.Imgur method),8 rup.__init__.CLIImgur method),7 get_ask_image_path_dialog_args() (imgu- get_show_link_dialog_args() (imgurup.__init__.Imgur rup.__init__.KDEImgur method), 10 method),9 get_ask_image_path_dialog_args() (imgu- get_show_link_dialog_args() (imgu- rup.__init__.MacImgur method), 10 rup.__init__.KDEImgur method), 10 get_show_link_dialog_args() (imgu-

15 imgurup Documentation, Release 1.6.0

rup.__init__.MacImgur method), 10 get_show_link_dialog_args() (imgu- rup.__init__.ZenityImgur method), 11 I Imgur (class in imgurup.__init__),7 ImgurError, 10 ImgurFactory (class in imgurup.__init__), 10 imgurup.__init__ (module),7 is_success() (imgurup.__init__.Imgur method),9 K KDEImgur (class in imgurup.__init__), 10 M MacImgur (class in imgurup.__init__), 10 main() (in module imgurup.__init__), 11 R request_album_list() (imgurup.__init__.Imgur method),9 request_new_tokens() (imgurup.__init__.Imgur method), 9 request_new_tokens_and_update() (imgu- rup.__init__.Imgur method),9 request_upload_image() (imgurup.__init__.Imgur method),9 retry() (imgurup.__init__.Imgur method),9 S set_tokens_using_config() (imgurup.__init__.Imgur method),9 show_error_and_exit() (imgurup.__init__.Imgur method),9 show_link() (imgurup.__init__.CLIImgur method),7 show_link() (imgurup.__init__.Imgur method),9 show_link() (imgurup.__init__.MacImgur method), 11 U upload() (imgurup.__init__.Imgur method),9 W write_tokens_to_config() (imgurup.__init__.Imgur method), 10 Z ZenityImgur (class in imgurup.__init__), 11

16 Index