示例#1
0
def download(gist_url):
    try:
        for num, (filename, gist_id,
                  content) in enumerate(download_gist(gist_url), start=1):
            pyuifile = False
            if os.path.splitext(filename)[1] == '.pyui':
                pyuifile = True
            if os.path.isfile(filename):
                i = console.alert(
                    'File exists', 'A file with the name ' + filename +
                    ' already exists in your library.', 'Overwrite', 'Skip')

                if i == 1:
                    os.remove(filename)
                    editor.make_new_file(filename, content)
                    if pyuifile == True:
                        os.rename(
                            os.path.splitext(filename)[0] + '.py', filename)
            else:
                editor.make_new_file(filename, content)
                set_gist_id(gist_id)
                if pyuifile == True:
                    os.rename(os.path.splitext(filename)[0] + '.py', filename)
    except InvalidGistIDError:
        console.alert('No Gist URL', 'Invalid Gist URL.', 'OK')
    except GistDownloadError:
        console.alert('Error', 'The Gist could not be downloaded.')
    if not num:
        console.alert('No Python Files', 'This Gist contains no Python files.')
示例#2
0
def download(gist_url):
	num = 0
	try:
		for num, (filename, content) in enumerate(download_gist(gist_url), start=1):
			if os.path.isfile(filename):
				i = console.alert('File exists', 'A file with the name ' + filename + 
								  ' already exists in your library.',
								  'Auto Rename', 'Skip')
				if i == 1:
					editor.make_new_file(filename, content)
			else:
				editor.make_new_file(filename, content)
				try:
					set_gist_id(editor.get_path(), gist_url)
				except InvalidGistIDError:
					# console.alert('Gist ID not set', filename + '\n' + gist_url)
					pass
	except InvalidGistURLError:
		console.alert('No Gist URL',
					  'Invalid Gist URL.',
					  'OK')
	except GistDownloadError:
		console.alert('Error', 'The Gist could not be downloaded.')
	if not num:
		console.alert('No Python Files', 'This Gist contains no Python files.')
def main():
    gist_url = clipboard.get()
    try:
        filename, content = download_gist(gist_url)
        content = content.encode('ascii', 'ignore')
        if os.path.isfile(filename):
            i = console.alert(
                'File exists', 'A file with the name ' + filename +
                ' already exists in your library.', 'Auto Rename')
            if i == 1:
                editor.make_new_file(filename, content)
        else:
            editor.make_new_file(filename, content)
    except InvalidGistURLError:
        console.alert(
            'No Gist URL',
            'The clipboard doesn\'t seem to contain a valid Gist URL.', 'OK')
    except MultipleFilesInGistError:
        console.alert(
            'Multiple Files', 'This Gist contains multiple ' +
            'Python files, which isn\'t currently supported.')
    except NoFilesInGistError:
        console.alert('No Python Files', 'This Gist contains no Python files.')
    except GistDownloadError:
        console.alert('Error', 'The Gist could not be downloaded.')
示例#4
0
def open_editor(file='', new_tab=True):
    if os.path.isfile(os.getcwd() + '/' + file):
        editor.open_file(os.getcwd() + '/' + file, new_tab)
        console.hide_output()
    else:
        editor.make_new_file(
            file if file else
            'untitled.py')  # new_tab not supported by make_new_file
def main():
    if not appex.is_running_extension():
        gist_url = clipboard.get()
    else:
        gist_url = appex.get_url()
    try:
        filename, content = download_gist(gist_url)
        if os.path.isfile(filename):
            i = console.alert(
                'File exists', 'A file with the name ' + filename +
                ' already exists in your library.', 'Rename', 'Replace')
            if i == 1:
                filename = test_filename(
                    console.input_alert('New File Name',
                                        'Set the name of the Gist file',
                                        filename, 'OK', False))

            try:
                import editor
                editor.make_new_file(filename, content)
            except ImportError:
                with open(filename, 'r+') as file:
                    file.seek(0)
                    file.write(content)
                    file.truncate()
                console.hud_alert('Script added successfully', 'success')

        else:
            try:
                import editor
                editor.make_new_file(filename, content)
            except ImportError:
                with open(filename, 'a+') as file:
                    file.seek(0)
                    file.write(content)
                    file.truncate()
                console.hud_alert('Script added successfully', 'success')
    except InvalidGistURLError:
        console.alert(
            'No Gist URL',
            'The clipboard doesn\'t seem to contain a valid Gist URL.', 'OK')
    except MultipleFilesInGistError:
        console.alert(
            'Multiple Files', 'This Gist contains multiple ' +
            'Python files, which isn\'t currently supported.')
    except NoFilesInGistError:
        console.alert('No Python Files', 'This Gist contains no Python files.')
    except GistDownloadError:
        console.alert('Error', 'The Gist could not be downloaded.')
示例#6
0
def main():
	gist_url = clipboard.get()
	num = 0
	try:
		for num, (filename, content) in enumerate(download_gist(gist_url), start=1):
			if os.path.isfile(filename):
				i = console.alert('File exists', 'A file with the name ' + filename + 
			                      ' already exists in your library.',
			                      'Auto Rename', 'Skip')
				if i == 1:
					editor.make_new_file(filename, content)
			else:
				editor.make_new_file(filename, content)
	except InvalidGistURLError:
		console.alert('No Gist URL',
		              'The clipboard doesn\'t seem to contain a valid Gist URL.',
		              'OK')
	except GistDownloadError:
		console.alert('Error', 'The Gist could not be downloaded.')
	if not num:
		console.alert('No Python Files', 'This Gist contains no Python files.')
示例#7
0
def main():
    path = editor.get_path()

    if not path:
        tab.new_file()
        return

    folder = os.path.dirname(path)
    try:
        file_name = console.input_alert('Enter filename').strip()

        if not file_name:
            raise KeyboardInterrupt

        path = os.path.join(folder, file_name)
        if os.path.exists(path):
            editor.open_file(path, new_tab=True)
        else:
            editor.make_new_file(path, new_tab=True)

    except KeyboardInterrupt:
        pass
示例#8
0
def main():
    gist_url = clipboard.get()
    num = 0
    try:
        for num, (filename, content) in enumerate(download_gist(gist_url),
                                                  start=1):
            if os.path.isfile(filename):
                i = console.alert(
                    'File exists', 'A file with the name ' + filename +
                    ' already exists in your library.', 'Auto Rename', 'Skip')
                if i == 1:
                    editor.make_new_file(filename, content)
            else:
                editor.make_new_file(filename, content)
    except InvalidGistURLError:
        console.alert(
            'No Gist URL',
            'The clipboard doesn\'t seem to contain a valid Gist URL.', 'OK')
    except GistDownloadError:
        console.alert('Error', 'The Gist could not be downloaded.')
    if not num:
        console.alert('No Python Files', 'This Gist contains no Python files.')
示例#9
0
def main():
	gist_url = clipboard.get()
	try:
		filename, content = download_gist(gist_url)
		if os.path.isfile(filename):
			i = console.alert('File exists', 'A file with the name ' + filename + 
			                  ' already exists in your library.',
			                  'Auto Rename')
			if i == 1:
				editor.make_new_file(filename, content)
		else:
			editor.make_new_file(filename, content)
	except InvalidGistURLError:
		console.alert('No Gist URL',
		              'The clipboard doesn\'t seem to contain a valid Gist URL.',
		              'OK')
	except MultipleFilesInGistError:
		console.alert('Multiple Files', 'This Gist contains multiple ' +
			            'Python files, which isn\'t currently supported.')
	except NoFilesInGistError:
		console.alert('No Python Files', 'This Gist contains no Python files.')
	except GistDownloadError:
		console.alert('Error', 'The Gist could not be downloaded.')
示例#10
0
if choose_option == 3:
	new_content = selected_text
elif choose_option == 2:
	new_content = clipboard.get()
elif choose_option == 1:
	new_content = text
else:
	sys.exit()

#if choose_option == "Selection":
#	new_content = selected_text
#elif choose_option == "Clipboard":
#	new_content = clipboard.get()
#elif choose_option == "Script":
#	new_content = text
#else:
#	sys.exit()

try:
	new_name = str(dialogs.text_dialog(title="New Script Name:", text=current_filepath) + ".py")
	
	editor.make_new_file(new_name, new_content)
	
	editor.open_file(new_name, new_tab=True)
except TypeError:
	sys.exit()
except FileNotFoundError:
	print("To save to iPhone ~/Documents, don't include any file path")
	sys.exit()

示例#11
0
# I got help from here: http://twolivesleft.com/Codea/Talk/discussion/1652/what-others-do%3A-pythonista/p1
# I got help from here: http://www.macdrifter.com/2012/09/pythonista-trick-url-to-markdown.html
# I got help from here: http://www.macstories.net/tutorials/from-instapaper-and-pythonista-to-dropbox-and-evernote-as-pdf/

import sys
import urllib2
import editor
import os

url = sys.argv[1]
scriptName = os.path.basename(url)
contents = urllib2.urlopen(url).read()
editor.make_new_file(scriptName[:-3], contents)

示例#12
0
    print('No Gist URL provided')
    sys.exit(1)

pattern = re.compile('https://gist.github.com/[a-zA-Z0-9_]+/([a-f0-9]+)')
match = pattern.search(sys.argv[1])
try:
    gist_id = match.group(1)
except IndexError:
    print("Could not parse Gist ID from URL '%s'" % sys.argv[1])
    sys.exit(1)

gist_url = 'https://api.github.com/gists/' + gist_id

r = requests.get(gist_url, auth=(GITHUB_USER, GITHUB_TOKEN))
if r.status_code is not 200:
    print("Something's wrong! API returned status %d" % r.status_code)
    sys.exit(1)

files = r.json['files']
for key in list(files.keys()):
    tup = key.rpartition('.')
    name = tup[0]
    if name is '':
        name = tup[2]
    if files[key]['language'] == 'Python':
        # Create file
        editor.make_new_file(FOLDER_PREFIX + name, files[key]['content'])
        print("Imported script '%s'" % name)

editor.reload_files()
示例#13
0
# coding: utf-8
import urllib.request, urllib.parse, urllib.error
import editor
url = 'https://gist.githubusercontent.com/gillibrand/3271073/raw/155ac9f391db74a1ace1c5c954fa7ed4e74255db/air_hockey.py'
contents = urllib.request.urlopen(url).read()
editor.make_new_file('AirHockey.py', contents)
示例#14
0
文件: edit.py 项目: BBOOXX/stash
def open_editor(file='', new_tab=True):
    if os.path.isfile(os.getcwd()+'/'+file):
        editor.open_file(os.getcwd()+'/'+file, new_tab)
        console.hide_output()
    else:
        editor.make_new_file(file if file else 'untitled.py') # new_tab not supported by make_new_file
	def make_file(self, filename, contents):
		editor.make_new_file(filename, contents)
示例#16
0
import editor, requests

print "* Downloading pipista"
pipista_code = requests.get("https://raw.githubusercontent.com/mjpizz/hackista/master/pipista.py").text

print "* Installing pipista"
editor.make_new_file("pipista", pipista_code)
editor.reload_files()

try:
    print "* Verifying pipista installation"
    import pipista
    print "* Successfully installed pipista"
except ImportError:
    print "* Error: failed to instal pipista"
示例#17
0
# https://gist.github.com/anonymous/2a520253d378f3bd1d77

# This will create a new python script from the clipboard.  The

import editor
import clipboard
import webbrowser
import os
import time
import sys

time.sleep(1)
editor.make_new_file(sys.argv[1], clipboard.get())
time.sleep(1)
execfile(sys.argv[1] + '.py')
time.sleep(1)
os.remove(sys.argv[1] + ".py")
time.sleep(1)
webbrowser.open('workflow://')
time.sleep(1)
示例#18
0
# https://gist.github.com/pfcbenjamin/a3c355f6857a00f5b685
import urllib.request, urllib.parse, urllib.error, webbrowser, clipboard, editor, os.path

url = clipboard.get()

page = urllib.request.urlopen(url)
content = page.read()

# Code below ripped from Ole Zorn's New from Gist script
from urllib.parse import urlparse
filename = os.path.split(urlparse(url).path)[1]
editor.make_new_file(filename, content)
# This Pythonista script increments and saves the current file.  
# I wrote it so I could quickly save different versions of scripts.
# It is meant to be added to the editor's action menu. 

import editor, os, sys, re
text = editor.get_text()
if not text:
    sys.exit('No text in the Editor.')

filename = os.path.split(editor.get_path())[1][:-3]

#finds number at end
num = re.split('[^\d]', filename)[-1]

#check if number string is empty
#if file ends with a number, increment it
l = len(num)

if l >=1:
	num2 = int(num) + 1
	filename = filename[:-l] + str(num2) + ".py"
else:
	filename = filename + str(1) + ".py"

#write new file
editor.make_new_file(filename, text)
示例#20
0
# http://omz-forums.appspot.com/pythonista/post/5903756180848640
# https://gist.github.com/weakmassive/2400bcca3ae2c0a6a43c

# This Pythonista script increments and saves the current file.
# I wrote it so I could quickly save different versions of scripts.
# It is meant to be added to the editor's action menu.

import editor, os, re
text = editor.get_text()
if not text:
    sys.exit('No text in the Editor.')

filename = os.path.split(editor.get_path())[1][:-3]

#finds number at end
num = re.split('[^\d]', filename)[-1]

#check if number string is empty
#if file ends with a number, increment it
l = len(num)

if l >= 1:
    num2 = int(num) + 1
    filename = filename[:-l] + str(num2) + ".py"
else:
    filename = filename + str(1) + ".py"

#write new file
editor.make_new_file(filename, text)
示例#21
0
# https://github.com/heliomass/iOSWorkflows
import clipboard
import editor
import urllib
import console
url = clipboard.get()
filename = url.split('/')[-1]
console.hud_alert('Downloading and creating ' + filename)
f = urllib.urlopen(url)
content = f.read()
f.close()
editor.make_new_file(filename, content)
editor.open_file(filename)
示例#22
0
import editor, requests

print "* Downloading pipista"
pipista_code = requests.get(
    "https://raw.githubusercontent.com/mjpizz/hackista/master/pipista.py").text

print "* Installing pipista"
editor.make_new_file("pipista", pipista_code)
editor.reload_files()

try:
    print "* Verifying pipista installation"
    import pipista
    print "* Successfully installed pipista"
except ImportError:
    print "* Error: failed to instal pipista"
# I got help from here: http://twolivesleft.com/Codea/Talk/discussion/1652/what-others-do%3A-pythonista/p1
# I got help from here: http://www.macdrifter.com/2012/09/pythonista-trick-url-to-markdown.html
# I got help from here: http://www.macstories.net/tutorials/from-instapaper-and-pythonista-to-dropbox-and-evernote-as-pdf/

import sys
import urllib2
import editor
import os

url = sys.argv[1]
scriptName = os.path.basename(url)
contents = urllib2.urlopen(url).read()
editor.make_new_file(scriptName[:-3], contents)