API

The following Python 3 code can be used as a simple command line client for this Pastebin service:

#!/usr/bin/env python

import urllib.request, urllib.parse, urllib.error
import urllib.request, urllib.error, urllib.parse
import os
import sys

def paste_code():
    fields = []
    fields.append(('content', ''.join(sys.stdin.readlines())))
    fields.append(('author', os.getlogin()))
    fields.append(('lexer', 'python'))
    encoded_data = urllib.parse.urlencode(fields).encode('utf-8')
    request = urllib.request.Request(
        'https://www.geany.org/p/api/',
        encoded_data,
    )
    response = urllib.request.urlopen(request)
    response_content = response.read()
    print(response_content.decode())

if __name__ == '__main__':
    paste_code()

Save this script in /usr/local/bin/gpaste and chmod +x /usr/local/bin/gpaste/.

Usage: cat foo.txt | gpaste

Supported fields

The only mandatory field is content which should contain the text to be pasted.

Other accepted, optional fields are:

Field Possible values Description
expires
  • 3600 (1 hour)
  • 604800 (1 week)
  • 2592000 (1 month)
Time to live in seconds, defaults to 3600
title Maximum 120 characters The title of this paste
author Maximum 30 characters The author's name
lexer python, text, php, perl, c, bash, ... The lexer to be used, all lexers supported by Pygments are possible and also most of Geany's filetype names (geany --ft-names)