Welcome to the Pythonista Community Forums!
Pythonista is a Python programming environment for iOS. To learn more, head over to the Pythonista Website.
It looks like you're new here. If you want to get involved, click one of these buttons!
javascript:window.location='pythonista://get_url?action=run&argv='+encodeURIComponent(document.location.href);
import sys
import pprint
import console
console.clear()
pprint.pprint(sys.argv[1:])
input_file = sys.argv[1:]
s = input_file
s = urllib.quote(s.encode('utf-8'))
from dropboxlogin import get_client
dropbox_client = get_client()
import clipboard
import keychain
import time
import console
import sys
import webbrowser
import httplib
input_file = sys.argv[1:]
s = input_file
s = urllib.quote(s.encode('utf-8'))
#response = dropbox_client.put_file('/URL_Paste/' + titles +)
print "uploaded!", #response
time.sleep(3) # delay for 3 seconds
console.clear()
def main():
dropbox_client = get_client()
f, meta = dropbox_client.get_file_and_metadata('/URL_Paste/URL_File.txt')
content = f.read() # can use readlines here to get list of lines
# print 'file content:'
# clipboard.set(last)
console.clear()
# print last
webbrowser.open(last)
if __name__ == '__main__':
main()
import sys
import webbrowser
import clipboard
import urllib
input_file = sys.argv[1:]
s = input_file
s = urllib.quote(s.encode('utf-8'))
webbrowser.open('notesy://x-callback-url/append?path=URL/URL_File.txt' + s)
import webbrowser
# This will show an error page but do nothing else:
webbrowser.open('ftp://')
# or:
# This will do a web search for "foo":
webbrowser.open('x-web-search://?foo')
sys.argv is a list (sequence) and Python has some special syntax for slicing and dicing sequences which you're probably not familiar with. The expression sys.argv[1:] that you've used actually extracts all elements beginning from the second, so the result will also be a list and not a string. To get just the second element, use sys.argv[1] (note the missing colon!). This will be a string (well, assuming that the script was started with arguments).import webbrowser
import sys
import clipboard
#s = sys.argv[1]
#clipboard.set(s)
#webbrowser.open('notesy://x-callback-url/append?path=URL/&name=abc.webloc&text=' + s)
import clipboard
import urllib2
import console
from dropboxlogin import get_client
dropbox_client = get_client()
import keychain
import time
import webbrowser
import sys
import urllib
import bs4
numArgs = len(sys.argv)
console.clear()
if numArgs < 2:
url = clipboard.get()
console.show_activity()
soup = bs4.BeautifulSoup(urllib.urlopen(url))
title = soup.title.string
name = title.encode('utf-8')
console.hide_activity()
else:
webpage = sys.argv[1]
name = webpage.encode('utf-8')
url = sys.argv[2]
insta = 'http://instapaper.com/text?u='
URL = insta + url
print 'Generating HTML file...'
getText = urllib2.Request(URL)
openText = urllib2.urlopen(getText)
content = (openText.read().decode('utf-8'))
final = content.encode('utf-8')
print 'Uploading HTML file to Dropbox...'
#Dropbox folder to put file into
response = dropbox_client.put_file('/HTMLs/' + name + '.html', final)
print 'Your HTML file has been uploaded'
print 'Converting to PDF...'
time.sleep(15)
encoded = urllib.quote(name, safe='')
urlstring = 'x-icabmobile://x-callback-url/open?url=http://dl.dropbox.com/u/yourDropboxPublicID/' + encoded + '.html.pdf'
webbrowser.open(urlstring)
import plistlib
webloc = {'URL': 'http://google.com'}
plistlib.writePlist(webloc, 'bookmark.webloc')
plistlib.writePlistToString(webloc) to create the text content of the webloc file. import sys
from dropboxlogin import get_client
dropbox_client = get_client()
s = sys.argv[1]
#Dropbox folder to put file into
response = dropbox_client.put_file('/URL/link.txt', s)
response = dropbox_client.put_file('/URL/' + s + '.txt', s)omz, I tried Your webloc suggestion, but all it does for me is to create a txt file with the link in it, not a real webloc.
import sys
from dropboxlogin import get_client
dropbox_client = get_client()
import datetime
import plistlib
s = sys.argv[1]
w = plistlib.writePlistToString(s)
fmt = '%Y-%m-%d_%H-%M-%S'
dt = str(datetime.datetime.now().strftime(fmt))
newname = 'Link_' + dt + '.webloc'
#Dropbox folder to put file into
response = dropbox_client.put_file('/URL/' + newname, w)
(?xml version="1.0" encoding="UTF-8"?)
(!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd")
(plist version="1.0")
(dict)
(key)URL(/key)
(string)http://www.omz-software.com/(/string)
(/dict)
(/plist)
(?xml version="1.0" encoding="UTF-8"?)
(!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd")
(plist version="1.0")
(string)http://www.omz-software.com(/string)
(/plist)
(dict)(key)URL(/key)...(/dict)the webloc file works.
s is just your URL, you should save the webloc file like this:...
w = plistlib.writePlistToString({'URL': s})
...