Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to suport new API and python 3.6 #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions pastee.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/python2.7
#!/usr/bin/python3.6
#Author : Kartik Jagdale <kartikjagdale[at]gmail[dot]com>
#Github : https://github.com/kartikjagdale/Pastee
"""
Additional Requirements:

1. Requests(version 2.3.0) - requests HTTP library
1. Requests(version 3.6.0) - requests HTTP library
if you don't have please downoad and install it from <http://python-requests.org>.

2. API KEY : sign up at 'paste.ee' and get your own API_KEY instalize API_KEY variable with the given key.
Expand All @@ -16,29 +16,46 @@
import argparse
#-------------------------------------------------------------------------------------------------------------


def find_str(s, char):
index = 0

if char in s:
c = char[0]
for ch in s:
if ch == c:
if s[index:index+len(char)] == char:
return index

index += 1

return -1
#Clipboard Function
def addToClipBoard(text):
cmd = 'echo ' + text.strip() + '| clip'
os.system(cmd)

# Function to Display End msgs
def end(msg):
print msg
print(msg)
return 1


# Our Very own important Function 'THE Pastee'
def pastee(desc, txt):
import requests # Import Requests

API_KEY = '' # Paste your API_KEY here in single quotes
post_param = {'key':API_KEY,'description':desc,'language':'plain','paste':txt,'format':'simple'} #Parameters to pass to the Pastee API
# Paste your API_KEY here in single quotes
API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
r = None

try:
r = requests.post('http://paste.ee/api',data=post_param, verify=False) # Post the params to Pastee API and get the url
# Post the params to Pastee API and get the url
payload = {'expiration': 'never', 'sections':[{'name':desc, 'syntax':'autodetect','contents':txt}]}
headers = {'X-Auth-Token': API_KEY}
r = requests.post(url='https://api.paste.ee/v1/pastes', json=payload, headers=headers)

except requests.ConnectionError as e:
print 'Connection Error'
print('Connection Error')

# Dictonary of errors
error = {
Expand All @@ -50,10 +67,14 @@ def pastee(desc, txt):

if r:
if r.content in error:
print error[r.content] #if any error return error
print(error[r.content]) #if any error return error
else:
print (r.content) #print pastee url to the cmd or python command line
addToClipBoard(r.content) # add pastee url to clipboard
#print(r.content.decode()) #print pastee url to the cmd or python command line
A=find_str(r.content.decode(), '"link":"')
B=find_str(r.content.decode(), '","success":true}')
linkpasteee=r.content.decode()[A+8:B].replace("\/", "/")
print(linkpasteee)
addToClipBoard(linkpasteee) # add pastee url to clipboard

return 0

Expand Down Expand Up @@ -87,7 +108,7 @@ def main():
parser.add_argument('filename', type=argparse.FileType('r'), help='Pass the Filename here') #Filename

args = parser.parse_args()
print 'Please wait......'
print('Please wait......')
try:
path = os.path.abspath(args.filename.name) #get the absoulte path of the file
txt = open(path).read() # read the file from given path
Expand All @@ -107,3 +128,4 @@ def main():
if __name__ == '__main__':
sys.exit(main())