python 简单的黑客使用gnome-screenshot和dropbox上传快速公开截图 - 需要libnotify-bin进行通知

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 简单的黑客使用gnome-screenshot和dropbox上传快速公开截图 - 需要libnotify-bin进行通知相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python
import gtk
import simplejson
import urllib2
import subprocess
import datetime
import string
import random
import time

# !!! DEPENDS ON NOTIFY OSD BINARIES FOR NOTIFICATIONS !!!
# sudo apt-get install libnotify-bin

############################################
#    CONFIGURATION                         #
############################################

DROPBOX_USER_ID = None # REPLACE WITH YOUR DROPBOX PUBLIC ID
DROPBOX_PUBLIC_PATH = "/home/username/Dropbox/Public/"  # CHANGE USERNAME - ensure paths end in /
WAIT_FOR_DROPBOX = True  # don't exit script and return URL until upload is complete
SUB_PATH = ""  # used if you don't want screengrabs in root public dir, make sure this path exists

# URL SHORTENER API SETTINGS
USE_URL_SHORTENER = True
API_PATH = "http://is.gd/create.php?format=json&url=$longurl"  # $longurl will be replaced with image URL
API_RESPONSE_TYPE = "json"  # or "plain"
JSON_SHORTURL_KEY = "shorturl"  # if using "json" above provide the keyname of the short response

############################################
#    END CONFIGURATION                     #
############################################


subprocess.call(["gnome-screenshot", "-c", "-a"])

clipboard = gtk.Clipboard()
content = clipboard.wait_for_image()

filename = "%s_%s.png" % (
	datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S"),
	''.join(random.choice(string.ascii_uppercase) for x in range(5))
)

content.save(
	"%s%s%s" % (
		DROPBOX_PUBLIC_PATH,
		SUB_PATH,
		filename),
	"png"
)

if USE_URL_SHORTENER:
	api_url = string.Template(API_PATH).substitute(
		longurl="http://dl.dropbox.com/u/%d/%s/%s" % (
			DROPBOX_USER_ID,
			SUB_PATH,
			filename
		)
	)

	response = urllib2.urlopen(api_url)

	if API_RESPONSE_TYPE == "json":
		res_dict = simplejson.loads(response.read())
		shorturl = res_dict[JSON_SHORTURL_KEY]

	elif API_RESPONSE_TYPE == "plain":
		shorturl = response.read()
else:
	shorturl = "http://dl.dropbox.com/u/%d/%s/%s" % (
		DROPBOX_USER_ID,
		SUB_PATH,
		filename
	)

clipboard.set_text(shorturl)
clipboard.store()

if WAIT_FOR_DROPBOX:
	subprocess.call(["notify-send", "Screengrab is being uploaded...", "--hint=int:transient:1"])
	while subprocess.check_output(['dropbox', 'status'])[:4] != "Idle":
		time.sleep(2)

subprocess.call(["notify-send", "Screengrab posted. URL copied to clipboard", shorturl, "--hint=int:transient:1"])

以上是关于python 简单的黑客使用gnome-screenshot和dropbox上传快速公开截图 - 需要libnotify-bin进行通知的主要内容,如果未能解决你的问题,请参考以下文章

Python 黑客相关电子资源和书籍推荐

《Python绝技:运用Python成为顶级黑客》 Python实用小工具

程序员快递请查收,来自Python黑客大佬的一份DDOS攻击说明书!

11招玩转黑客攻防——用Python,更安全

程序员快递请查收, 来自Python黑客大佬的一份DDOS攻击说明书!

黑客需要用到的Python技术?