import console
console.show_activity()
import webbrowser
import urllib
import clipboard
import datetime
import sys

today = datetime.datetime.now()
base = 'notesy://x-callback-url/append?name=Scratchpad.txt'
file = '&text='

console.hide_activity()

numArgs = len(sys.argv)

if numArgs == 3:

	clip = sys.argv[2]
	link = sys.argv[1]
	
	actions = '&x-success=' + link + '&x-error=notesy://'
	
	if clip =="":
	
		text = "\n" + '_' + today.strftime("%Y-%m-%d") + '_' + "\n" + link
		text = urllib.quote(text, safe='')
	
	else:
	
		text = "\n" + '_' + today.strftime("%Y-%m-%d") + '_' + "\n" + clip + "\n" + "\n" + "From: " + link
		text = urllib.quote(text, safe='')

else:

	url = clipboard.get()
	clip = url.encode('utf-8')
	actions = '&x-success=notesy://&x-error=notesy://'
	text = "\n" + '_' + today.strftime("%Y-%m-%d") + '_' + "\n" + clip
	text = urllib.quote(text, safe='')

webbrowser.open(base + actions + file + text)
