Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import sys, os
- from src import pastebinfuncs, pastebininfo, pastebinrequest
- USAGEMESSAGE = "usage: {} <file>".format(os.path.basename(sys.argv[0]) )
- def usage():
- print(USAGEMESSAGE, file=sys.stderr)
- def usageExit():
- usage()
- sys.exit()
- def errorExit(message):
- print("ERROR: " + message, file=sys.stderr)
- usageExit()
- def main(args):
- if len(args) <= 1:
- errorExit("no file specified")
- return # just in case
- pbFile = args[1]
- apiKey, userKey = pastebinfuncs.getAPIKeys()
- if apiKey is None:
- print("Adding API key to {}.".format(pastebinfuncs.KEYDIR) )
- print("You can get your API key at \"http://http://pastebin.com/api\".")
- while not apiKey:
- apiKey = input("API key: ")
- keyFile = open(pastebinfuncs.replaceHome(pastebinfuncs.KEYDIR), "a")
- keyFile.write("apikey = {}\n".format(apiKey))
- keyFile.close()
- if userKey is None:
- print("Adding user key to {}.".format(pastebinfuncs.KEYDIR) )
- userKey = pastebinfuncs.loginPastebin(apiKey, write=True)
- # by now, we should have a user and API key
- try:
- pbInfo = pastebininfo.PastebinInfo.fromFile(pbFile, key=apiKey, userKey=userKey)
- except IOError:
- errorExit("\"{}\" does not exist".format(pbFile) )
- return
- pbRequ = pastebinrequest.PastebinRequest(pbInfo)
- try:
- url = pbRequ.getPage()
- except pastebinrequest.PastebinError:
- exc = sys.exc_info()
- errorExit("{}".format(exc[1]))
- return
- print(url)
- if __name__ == '__main__':
- main(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement