Imgurup Documentation Release 1.6.0

Imgurup Documentation Release 1.6.0

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 dialog 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 [<image path> [<image path> ...]]] [-d [<album id>]] [-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 [<image path> [<image path> ...]] The images you want to upload -d [<album id>] 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=(<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_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

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    20 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us