├── Twitter2Tweetbot.py ├── PySky.py ├── ImageResize.py ├── dropboxlogin.py ├── DraftLink.py └── README.md /Twitter2Tweetbot.py: -------------------------------------------------------------------------------- 1 | import clipboard 2 | import console 3 | import webbrowser 4 | import string 5 | from glob import glob 6 | from urlparse import urlparse 7 | import sys 8 | 9 | twitter_name = 'jayhickey' 10 | 11 | try: 12 | mytext = sys.argv[1] 13 | print clipboard.get() 14 | except IndexError: 15 | mytext = clipboard.get() 16 | 17 | 18 | u = urlparse(mytext) 19 | mytext = mytext.replace('https://twitter.com/', 'tweetbot://') 20 | mytext = mytext.replace('statuses', 'status') 21 | mytext = mytext.replace('http://twitter.com/', 'tweetbot://') 22 | mytext = mytext.replace('http://mobile.twitter.com/', 'tweetbot://') 23 | mytext = mytext.replace('https://mobile.twitter.com/', 'tweetbot://') 24 | 25 | if mytext.count('/') < 3 or mytext.find('tweets') != -1: 26 | mytext = 'tweetbot://' + twitter_name + '/user_profile' + u.path 27 | 28 | # console.clear() 29 | print mytext 30 | 31 | webbrowser.open(mytext) 32 | -------------------------------------------------------------------------------- /PySky.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import json 3 | import urllib 4 | from os import environ 5 | from sys import exit, argv 6 | 7 | 8 | # If desired, enter lat & long as arguments 9 | try: 10 | lat = argv[1] 11 | lon = argv[2] 12 | except IndexError: 13 | lat = 39.200932 14 | lon = -84.376009 15 | 16 | # Get my API key and construct the URL 17 | APIkey = 'YOUR_API_KEY' 18 | dsURL = 'https://api.darkskyapp.com/v1/forecast/%s/%s,%s' \ 19 | % (APIkey, lat, lon) 20 | 21 | 22 | # Get the data from Dark Sky. 23 | try: 24 | jsonString = urllib.urlopen(dsURL).read() 25 | weather = json.loads(jsonString) 26 | except (IOError, ValueError): 27 | print "Connection failure to %s" % dsURL 28 | exit() 29 | 30 | print 'NOW\n' + str(weather['currentSummary']).capitalize() + ', '\ 31 | + str(weather['currentTemp']) + u'° F'.encode('utf8') + '\n' 32 | print 'NEXT HOUR \n' + weather['hourSummary'].capitalize() + '\n' 33 | 34 | # Highest intensity in the next 3 hours. 35 | hrsType = [ i['type'] for i in weather['dayPrecipitation'][1:4] ] 36 | hrsProb = [ i['probability'] for i in weather['dayPrecipitation'][1:4] ] 37 | 38 | chance = max(hrsProb) 39 | probIndex = hrsProb.index(chance) 40 | 41 | if chance > 0.8: 42 | nextThreeHrs = '%s' % (str(hrsType[probIndex])).capitalize() 43 | elif chance > 0.5: 44 | nextThreeHrs = '%s likely' % (str(hrsType[probIndex])).capitalize() 45 | elif chance > 0.2: 46 | nextThreeHrs = 'Possible %s' % str(hrsType[probIndex]) 47 | else: 48 | nextThreeHrs = 'No precipitation' 49 | 50 | print 'FOLLOWING 3 HRS\n' + nextThreeHrs.capitalize() + '\n' 51 | print 'NEXT 24 HRS \n' + weather['daySummary'].capitalize() + '\n' 52 | 53 | -------------------------------------------------------------------------------- /ImageResize.py: -------------------------------------------------------------------------------- 1 | import Image, ImageOps, ImageFilter 2 | import ftplib 3 | import console 4 | import clipboard 5 | import datetime 6 | from io import BytesIO 7 | import urllib 8 | 9 | today = datetime.datetime.now() 10 | image = clipboard.get_image() 11 | fileName = console.input_alert("Image Title", "Enter Image File Name") 12 | if fileName != '': 13 | fileName = fileName+'_'+today.strftime("%Y-%m-%d-%H%M%S") +'.png' 14 | else: 15 | fileName = today.strftime("%Y-%m-%d-%H%M%S") +'.png' 16 | 17 | userName = "server_username" 18 | userPass = "server_password" 19 | host = "server_ip" 20 | port = 22 21 | urlBase = "http://www.jayhickey.com/media/mobile/" 22 | 23 | remotePath = "/Dropbox/Blog/media/mobile/" 24 | 25 | # datePath = today.strftime("%Y/%m/") 26 | # Used to create full remote file path 27 | remoteFilePath = remotePath 28 | 29 | def customSize(img): 30 | w, h = img.size 31 | print 'w: ' + str(w) 32 | print 'h: '+ str(h) 33 | if w > 620: 34 | wsize = 620/float(w) 35 | print 'wsize: '+str(wsize) 36 | hsize = int(float(h)*float(wsize)) 37 | print 'hsize: ' + str(hsize) 38 | 39 | img = img.resize((620, hsize), Image.ANTIALIAS) 40 | return img 41 | 42 | image = customSize(image) 43 | print image.size 44 | image.show() 45 | 46 | buffer = BytesIO() 47 | image.save(buffer, 'PNG') 48 | buffer.seek(0) 49 | 50 | print remoteFilePath 51 | print fileName 52 | 53 | fileURL = urllib.quote(fileName) 54 | 55 | ftp = ftplib.FTP(host, userName, userPass) 56 | ftp.cwd(remoteFilePath) 57 | ftp.storbinary('STOR '+fileName, buffer) 58 | ftp.quit() 59 | imageLink = urlBase+fileURL 60 | print(imageLink) 61 | clipboard.set(imageLink) -------------------------------------------------------------------------------- /dropboxlogin.py: -------------------------------------------------------------------------------- 1 | # YOU NEED TO INSERT YOUR APP KEY AND SECRET BELOW! 2 | # Go to dropbox.com/developers/apps to create an app. 3 | 4 | app_key = 'YOUR_KEY' 5 | app_secret = 'YOUR_SECRET' 6 | 7 | # access_type can be 'app_folder' or 'dropbox', depending on 8 | # how you registered your app. 9 | access_type = 'dropbox' 10 | 11 | import webbrowser 12 | from dropbox import client, rest, session 13 | import keychain 14 | import pickle 15 | import console 16 | 17 | def get_request_token(): 18 | console.clear() 19 | print 'Getting request token...' 20 | sess = session.DropboxSession(app_key, app_secret, access_type) 21 | request_token = sess.obtain_request_token() 22 | url = sess.build_authorize_url(request_token) 23 | console.clear() 24 | webbrowser.open(url, modal=True) 25 | return request_token 26 | 27 | def get_access_token(): 28 | token_str = keychain.get_password('dropbox', app_key) 29 | if token_str: 30 | key, secret = pickle.loads(token_str) 31 | return session.OAuthToken(key, secret) 32 | request_token = get_request_token() 33 | sess = session.DropboxSession(app_key, app_secret, access_type) 34 | access_token = sess.obtain_access_token(request_token) 35 | token_str = pickle.dumps((access_token.key, access_token.secret)) 36 | keychain.set_password('dropbox', app_key, token_str) 37 | return access_token 38 | 39 | def get_client(): 40 | access_token = get_access_token() 41 | sess = session.DropboxSession(app_key, app_secret, access_type) 42 | sess.set_token(access_token.key, access_token.secret) 43 | dropbox_client = client.DropboxClient(sess) 44 | return dropbox_client 45 | 46 | def main(): 47 | # Demo if started run as a script... 48 | # Just print the account info to verify that the authentication worked: 49 | print 'Getting account info...' 50 | dropbox_client = get_client() 51 | account_info = dropbox_client.account_info() 52 | print 'linked account:', account_info 53 | 54 | if __name__ == '__main__': 55 | main() 56 | -------------------------------------------------------------------------------- /DraftLink.py: -------------------------------------------------------------------------------- 1 | # Draft a markdown blog file 2 | # from a this bookmarklet: 3 | # javascript:(function()%7Bif(document.location.href.indexOf('http')===0)document.location.href='pythonista://DraftLink?action=run&argv='+document.location.href;%7D)(); 4 | 5 | import clipboard 6 | import sys 7 | import re 8 | import console 9 | import codecs 10 | from os import remove 11 | import webbrowser 12 | import urllib 13 | import dropboxlogin 14 | 15 | # Convert title to slug 16 | def convert_title(title): 17 | # Repace non alphanumerics with dashes 18 | slug = re.sub(r'[\t !"#$%;:&\'()*\-/<=>?@\[\\\]^_`{|},.]+', "-", title).lower() 19 | # Remove trailing dashes 20 | while slug.endswith('-'): 21 | slug = slug[:-1] 22 | return slug 23 | 24 | # Create a draft markdown text file 25 | def makefile(slug, url, title): 26 | f = codecs.open(slug + '.md', 'w', 'utf-8') 27 | f.write(title + '\n') 28 | f.write('======\n') 29 | f.write('Link: ' + url + '\n') 30 | f.write('publish-not-yet\n\n') 31 | isLink = console.alert('', '', 'Blockquote', 'No Blockquote') 32 | if isLink == 1: 33 | f.write('> ' + clipboard.get()) 34 | f.close() 35 | 36 | # Upload draft to Dropbox 37 | def upload(slug, dropbox_draft_path): 38 | print '\nUploading ' + slug +'.md' 39 | f = open(slug + '.md') 40 | db = dropboxlogin.get_client() 41 | response = db.put_file(dropbox_draft_path + slug + '.md', f) 42 | remove(slug + '.md') 43 | 44 | 45 | if __name__ == '__main__': 46 | # Path to drafts folder 47 | dropbox_draft_path = '/Blog/blog/drafts/' 48 | 49 | print sys.argv[1] 50 | url = sys.argv[1] 51 | title = sys.argv[2] 52 | title = console.input_alert('Edit Title', '', title) 53 | slug = console.input_alert('Edit Slug', '', convert_title(title)) 54 | makefile(slug, url, title) 55 | upload(slug, dropbox_draft_path) 56 | 57 | # Open draft in Nebulous Notes 58 | nebulous = 'nebulous:/' + dropbox_draft_path + slug + '.md' 59 | webbrowser.open(nebulous) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Pythonista Scripts 2 | ===== 3 | 4 | This is a list of my personal [Pythonista] scripts. I've uploaded them here mostly for personal reference and backup, but also on the off chance someone finds them useful. 5 | 6 | DraftLink.py 7 | ------ 8 | Drafts a Markdown text file from a URL passed with this bookmarklet: 9 | 10 | javascript:window.location='pythonista://DraftLink?action=run&argv='+encodeURIComponent(document.location.href)+'&argv='+encodeURIComponent(document.title); 11 | 12 | and can also include a block quote from copied text on the clipboard. The file is uploaded to a specified path on Dropbox, and then opened in Nebulous Notes for additional commentary. The `dropboxlogin.py` script handles the Dropbox requests. This Dropbox module was taken from Pythonista creator OMZ's [post on the Pythonista forums]. 13 | 14 | PySky.py 15 | ----- 16 | Mimics text part of my [PySky] script by telling you the precipitation currently, in the next hour, the following 3 hours, and next 24 hours. 17 | 18 | Twitter2Tweetbot.py 19 | ------ 20 | A modification of Federico Viticci's script for [converting Twitter.com URLs to Tweetbot Links] with the additional abilities to both work as a bookmarklet and open a user profile, not just a specific tweet, in Tweetbot. 21 | 22 | ImageResize.py 23 | ----- 24 | An adaptation of an image resizing script by [MacDrfiter]. Image sizes and paths have been modified so they work with [jayhickey.com], my blog. 25 | 26 | [jayhickey.com]:http://jayhickey.com 27 | [Pythonista]:https://itunes.apple.com/us/app/pythonista/id528579881?mt=8&ign-mpt=uo%3D4 28 | [MacDrfiter]:http://www.macdrifter.com/2012/11/the-power-of-pythonista-12.html 29 | [converting Twitter.com URLs to Tweetbot Links]:http://www.macstories.net/tutorials/convert-twitter-com-urls-to-tweetbot-links/ 30 | [PySky]:https://github.com/jayhickey/PySky 31 | [post on the Pythonista forums]:http://omz-software.com/pythonista/forums/discussion/10/using-the-dropbox-module#Item_3 32 | --------------------------------------------------------------------------------