#!/usr/bin/python

# create a new pastbin.m.o entry from STDIN

import os
import sys
import urllib

if len(sys.argv) == 2:
    url = "https://%s.pastebin.mozilla.org" % sys.argv[1]
    fmt = sys.argv[1]
else:
    url = "https://pastebin.mozilla.org"
    fmt = "None"

body = sys.stdin.read()

params = [
    ('parent_pid', ''),
    ('code2', body),
    ('poster', os.environ.get('PASTEBIN_NAME', '')),
    ('expiry', 'd'),
    ('paste', 'Send'),
    ('format', fmt),
    ]

data = urllib.urlencode(params)

req = urllib.urlopen(url, data)

print req.geturl()
