Giter VIP home page Giter VIP logo

pastebinapi's Introduction

About

The package allows you to communicate directly with Pastebin.com from your Python application, either logged in or anonymously. This can be handy

for a number of reasons - dumping error logs before an abort, regular web based status updates, but can't be bothered getting a web-server running etc.

It allows you to do everything the API allows, which is:

  • Paste, either logged in or anonymously
  • 200+ selectable languages for syntax highlighting
  • Set expiry times on pastes
  • Set public/private/unlisted status for pastes
  • See trending pastes
  • See pastes by a particular user
  • Delete your pastes
  • Retrieve your user details
  • Generate a session (user) key for added security
  • Paste using the old, non-token anonymous API (for as long as they keep it open)

Installation

If you have downloaded the source distribution, to install do the following at the commandline:

$ python setup.py install

If you can use and install Python Egg's, you can do:

$ easy_install Pastebin

And it will download the latest version from the Python Package Index.

Usage Examples

Generate a user/session key (this is required by other functions):

from pastebin import PastebinAPI
pb = PastebinAPI()
my_key = pb.generate_user_key(api_dev_key, username, password)
print(my_key)

Return an XML list of User Details of user specified by API key.

details = pb.user_details(api_dev_key, api_user_key)
print(details)

Return a list of trending pastes. The result is in XML:

trending_pastes = pb.trending(api_dev_key)
print(trending_pastes)

Return an XML list of all pastes by user. Result limit defaults to none, so it will return all pastes:

details = pb.user_details(api_dev_key, api_user_key, results_limit = None)

Delete a paste:

pb.delete_paste(api_dev_key, api_user_key, api_paste_key)

Paste to Pastebin, where api_paste_code is the contents of your paste. This will accept any valid Python data type:

pb.paste(api_dev_key, api_paste_code, api_user_key = None, 
                   paste_name = None, paste_format = None, 
                   paste_private = None, paste_expire_date = None)

Note that any parameter which is listed about as ' = None' is optional. Details of valid input parameters for paste function are below.

Valid paste_private values:

  • 'public'
  • 'unlisted'
  • 'private'

Valid paste_expire_date values:

InputDescription
'N'Never
'10M'10 minutes
'1H'1 hour
'1D'1 day
'1M'1 month

Valid parse_format values:

Input Language
'4cs'4CS
'6502acme'6502 ACME Cross Assembler
'6502kickass'6502 Kick Assembler
'6502tasm'6502 TASM/64TASS
'abap'ABAP
'actionscript'ActionScript
'actionscript3'ActionScript 3
'ada'Ada
'algol68'ALGOL 68
'apache'Apache Log
'applescript'AppleScript
'apt_sources'APT Sources
'asm'ASM (NASM)
'asp'ASP
'autoconf'autoconf
'autohotkey'Autohotkey
'autoit'AutoIt
'avisynth'Avisynth
'awk'Awk
'bascomavr'BASCOM AVR
'bash'Bash
'basic4gl'Basic4GL
'bibtex'BibTeX
'blitzbasic'Blitz Basic
'bnf'BNF
'boo'BOO
'bf'BrainFuck
'c'C
'c_mac'C for Macs
'cil'C Intermediate Language
'csharp'C#
'cpp'C++
'cpp-qt'C++ (with QT extensions)
'c_loadrunner'C: Loadrunner
'caddcl'CAD DCL
'cadlisp'CAD Lisp
'cfdg'CFDG
'chaiscript'ChaiScript
'clojure'Clojure
'klonec'Clone C
'klonecpp'Clone C++
'cmake'CMake
'cobol'COBOL
'coffeescript'CoffeeScript
'cfm'ColdFusion
'css'CSS
'cuesheet'Cuesheet
'd'D
'dcs'DCS
'delphi'Delphi
'oxygene'Delphi Prism (Oxygene)
'diff'Diff
'div'DIV
'dos'DOS
'dot'DOT
'e'E
'ecmascript'ECMAScript
'eiffel'Eiffel
'email'Email
'epc'EPC
'erlang'Erlang
'fsharp'F#
'falcon'Falcon
'fo'FO Language
'f1'Formula One
'fortran'Fortran
'freebasic'FreeBasic
'freeswitch'FreeSWITCH
'gambas'GAMBAS
'gml'Game Maker
'gdb'GDB
'genero'Genero
'genie'Genie
'gettext'GetText
'go'Go
'groovy'Groovy
'gwbasic'GwBasic
'haskell'Haskell
'hicest'HicEst
'hq9plus'HQ9 Plus
'html4strict'HTML
'html5'HTML 5
'icon'Icon
'idl'IDL
'ini'INI file
'inno'Inno Script
'intercal'INTERCAL
'io'IO
'j'J
'java'Java
'java5'Java 5
'javascript'JavaScript
'jquery'jQuery
'kixtart'KiXtart
'latex'Latex
'lb'Liberty BASIC
'lsl2'Linden Scripting
'lisp'Lisp
'llvm'LLVM
'locobasic'Loco Basic
'logtalk'Logtalk
'lolcode'LOL Code
'lotusformulas'Lotus Formulas
'lotusscript'Lotus Script
'lscript'LScript
'lua'Lua
'm68k'M68000 Assembler
'magiksf'MagikSF
'make'Make
'mapbasic'MapBasic
'matlab'MatLab
'mirc'mIRC
'mmix'MIX Assembler
'modula2'Modula 2
'modula3'Modula 3
'68000devpac'Motorola 68000 HiSoft Dev
'mpasm'MPASM
'mxml'MXML
'mysql'MySQL
'newlisp'newLISP
'text'None
'nsis'NullSoft Installer
'oberon2'Oberon 2
'objeck'Objeck Programming Language
'objc'Objective C
'ocaml-brief'OCalm Brief
'ocaml'OCaml
'pf'OpenBSD PACKET FILTER
'glsl'OpenGL Shading
'oobas'Openoffice BASIC
'oracle11'Oracle 11
'oracle8'Oracle 8
'oz'Oz
'pascal'Pascal
'pawn'PAWN
'pcre'PCRE
'per'Per
'perl'Perl
'perl6'Perl 6
'php'PHP
'php-brief'PHP Brief
'pic16'Pic 16
'pike'Pike
'pixelbender'Pixel Bender
'plsql'PL/SQL
'postgresql'PostgreSQL
'povray'POV-Ray
'powershell'Power Shell
'powerbuilder'PowerBuilder
'proftpd'ProFTPd
'progress'Progress
'prolog'Prolog
'properties'Properties
'providex'ProvideX
'purebasic'PureBasic
'pycon'PyCon
'python'Python
'q'q/kdb+
'qbasic'QBasic
'rsplus'R
'rails'Rails
'rebol'REBOL
'reg'REG
'robots'Robots
'rpmspec'RPM Spec
'ruby'Ruby
'gnuplot'Ruby Gnuplot
'sas'SAS
'scala'Scala
'scheme'Scheme
'scilab'Scilab
'sdlbasic'SdlBasic
'smalltalk'Smalltalk
'smarty'Smarty
'sql'SQL
'systemverilog'SystemVerilog
'tsql'T-SQL
'tcl'TCL
'teraterm'Tera Term
'thinbasic'thinBasic
'typoscript'TypoScript
'unicon'Unicon
'uscript'UnrealScript
'vala'Vala
'vbnet'VB.NET
'verilog'VeriLog
'vhdl'VHDL
'vim'VIM
'visualprolog'Visual Pro Log
'vb'VisualBasic
'visualfoxpro'VisualFoxPro
'whitespace'WhiteSpace
'whois'WHOIS
'winbatch'Winbatch
'xbasic'XBasic
'xml'XML
'xorg_conf'Xorg Config
'xpp'XPP
'yaml'YAML
'z80'Z80 Assembler
'zxbasic'ZXBasic

pastebinapi's People

Contributors

codewarrior0 avatar fabaff avatar howiezhao avatar ivanalejandro0 avatar morrolan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pastebinapi's Issues

Replace urllib.urlopen to urllib.request.urlopen

python3 raise AttributeError.

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python3.5/dist-packages/flask_restful/__init__.py", line 270, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 32, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.5/dist-packages/flask_restful/__init__.py", line 270, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 32, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.5/dist-packages/flask_restful/__init__.py", line 462, in wrapper
    resp = resource(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/flask/views.py", line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/flask_restful/__init__.py", line 572, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/media/sf_workspace/python/flask/codebot_kakao/app.py", line 66, in post
    url = save_to_pastebin(code, format="python")
  File "/media/sf_workspace/python/flask/codebot_kakao/app.py", line 28, in save_to_pastebin
    paste_private = 'unlisted')
  File "/usr/local/lib/python3.5/dist-packages/pastebin.py", line 679, in paste
    request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv))
AttributeError: module 'urllib' has no attribute 'urlopen'

It should be replace to urllib.request.urlopen

Cannot delete pastes

There's an error in the delete_paste function where request_string is referenced in line 342 of pastebin.py. This name does not exist, and I assume the line above should read request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)). Thus the delete function does not work.

raise PastebinError(response) "http://pastebin.com" vs "https://pastebin.com"

Looks like the error checking below expects "http://pastebin.com" but is getting "https://pastebin.com" back in the response, thus triggering the error.

    # do some basic error checking here so we can gracefully handle any 
    # errors we are likely to encounter
    if response.startswith(self._bad_request):
        raise PastebinError(response)
    elif not response.startswith(self._prefix_url):
        raise PastebinError(response)  

    return response

Problems installing from pypi, Pastebin.py not found.

I have this problem installing the package using pip and easy_install.
Here the logs:

(venv:pruebas) ➜ pip install Pastebin
Downloading/unpacking Pastebin
  Downloading Pastebin-1.1.1.tar.gz (55kB): 55kB downloaded
  Running setup.py egg_info for package Pastebin

    file Pastebin.py (for module Pastebin) not found
Requirement already satisfied (use --upgrade to upgrade): setuptools in /home/ivan/.virtualenvs/pruebas/lib/python2.7/site-packages (from Pastebin)
Installing collected packages: Pastebin
  Running setup.py install for Pastebin
    file Pastebin.py (for module Pastebin) not found
    file Pastebin.py (for module Pastebin) not found
    warning: install_lib: 'build/lib.linux-i686-2.7' does not exist -- no Python modules to install


    file Pastebin.py (for module Pastebin) not found
    file Pastebin.py (for module Pastebin) not found
Successfully installed Pastebin
Cleaning up...
(venv:pruebas) ➜ easy_install Pastebin
Searching for Pastebin
Reading https://pypi.python.org/simple/Pastebin/
Best match: Pastebin 1.1.1
Downloading https://pypi.python.org/packages/source/P/Pastebin/Pastebin-1.1.1.tar.gz#md5=d9374efc32f442e9fb4589d4f5a9b74b
Processing Pastebin-1.1.1.tar.gz
Writing /tmp/easy_install-KfbedV/Pastebin-1.1.1/setup.cfg
Running Pastebin-1.1.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-KfbedV/Pastebin-1.1.1/egg-dist-tmp-I9DzMO
file Pastebin.py (for module Pastebin) not found
file Pastebin.py (for module Pastebin) not found
file Pastebin.py (for module Pastebin) not found
warning: install_lib: 'build/lib.linux-i686-2.7' does not exist -- no Python modules to install

zip_safe flag not set; analyzing archive contents...
Adding Pastebin 1.1.1 to easy-install.pth file

Installed /home/ivan/.virtualenvs/pruebas/lib/python2.7/site-packages/Pastebin-1.1.1-py2.7.egg
Processing dependencies for Pastebin
Finished processing dependencies for Pastebin

Notes:

  • I tried installing with Pastebin and pastebin, no luck.
  • I was able to install the app using python setup.py install from this repo.

urllib doesn't support Python 3

Attempting to use generate_user_key gives the following error:
AttributeError: module 'urllib' has no attribute 'urlopen'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.