C'est mon premier soft en Python, critiques bienvenue :)

Spécial dédicass à dzen

#!/usr/bin/python
 
import sys
import urllib
import getopt
 
format = "text"
data_on_stdin = 1
str = ""
 
usage = """Usage: ./pastebin.py [-l language] [-f fichier]
Example: cat mycode.c | pastebin.py -l c
       : ./pastebin.py -f mycode.c
       : ./pastebin.py -l bash -f myscrip.sh
 
Option -l :
bash c cpp html4strict java javascript lua perl php python ruby
abap actionscript ada apache applescript asm asp autoit blitzbasic
bnf c_mac caddcl csharp cfm css d delphi diff dos eiffel fortran
freebasic genero gml groovy haskell idl ini inno latex matlab m68k
mpasm mirc mysql nsis objc ocaml oobas oracle8 pascal plswl qbasic
rails robots scheme smalltalk smarty tcl vb vbnet visualfoxpro xml
z80"""
 
 
try:
	opts, args = getopt.getopt(sys.argv[1:], "l:f:h", ["language=", "file=", "help"])
except getopt.GetoptError:
	sys.exit(usage)
for opt, arg in opts:
	if opt in ("-f", "--file"):
		file_to_paste = open(arg, 'r')
		str = file_to_paste.read()
		file_to_paste.close()
		data_on_stdin = 0
	elif opt in ("-l", "--language"):
		format = arg
	elif opt in ("-h", "--help"):
		sys.exit(usage)
 
if data_on_stdin:
	str = sys.stdin.read()
 
data = urllib.urlencode({"paste_code":str,"paste_format":format})
 
f = urllib.urlopen("http://pastebin.com/api_public.php", data)
paste_url = f.read()
f.close()
 
print paste_url

jfg 2007/09/15 18:57

codaz/python/pastebin_en_console.txt · Last modified: 2010/08/08 21:56 by orion64