-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaste.py
executable file
·54 lines (48 loc) · 1.24 KB
/
paste.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
# coding=utf-8
import cookielib
import urllib2
import urllib
import sys
import os
CookieJar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(CookieJar));
def paste(txt,user="UCU",language="text"):
url = "http://paste.ubuntu.com"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2376.0 Safari/537.36"
}
data = {
"poster" : user,
"syntax" : language,
"content" : txt
}
#print txt
post_data = urllib.urlencode(data)
#print post_data
req = urllib2.Request(url,post_data,headers)
res = opener.open(req);
#print res.getcode()
return res.geturl()
def readFromFile(filename):
f = open(os.getcwd()+"/"+filename);
str = "";
for line in f.readlines():
str = str + line
return str
filename = ""
user = "UCU"
language = "text"
#print len(sys.argv)
if len(sys.argv) >= 2 :
filename = sys.argv[1]
if len(sys.argv) >= 3:
user = sys.argv[2]
if len(sys.argv) >= 4:
language = sys.argv[3]
while True:
try:
print paste(readFromFile(filename),user,language)
except Exception:
continue
break