This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # quick and dirty script to download a compressed file and unzip it in memory to an appropriate folder | |
| # useful in pythonista (ios) to handle the fact that ios has no native way to handle compressed files. | |
| # can handle .tar.gzip and .zip files | |
| import requests, zipfile, os, urllib, io, tarfile | |
| url = input('url: ') | |
| filename = os.path.basename(urllib.parse.urlparse(url).path) | |
| dirname = filename.partition(".")[0] | |
| extension = filename.rpartition(".")[-1] | |
| try: |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests, concurrent.futures, time | |
| class FailedRequest(object): | |
| def __init__(self, type_of_failure, details): | |
| self.type = type_of_failure | |
| self.message = details | |
| def __download(url, headers, delay, timeout): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| some images get broken in desktop browsers because they're rotate with exif tags, which desktop browsers don't support, but ios does. | |
| (More specifically, neither desktop Chrome, Safari or Firefox on OSX as of 1/2/18 seem to respect exif tags when the image is embedded | |
| in a page, though at least Chrome respects them when the file is opened in its own tab.) | |
| see: https://www.howtogeek.com/254830/why-your-photos-dont-always-appear-correctly-rotated/ + | |
| https://stackoverflow.com/questions/42401203/chrome-image-exif-orienation-issue | |
| This leads to a weird situation where you can have a photo that was rotated in some exif-happy app that looks correct on ios but not | |
| on any desktop browser. Let's fix this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # CONSTANTS: REPLACE WITH YOUR OWN INFO. IN PARTICULAR, THE TWO DROPBOX FIELDS ARE TO GET YOUR API KEY OUT OF THE PYTHONISTA KEYCHAIN | |
| DATABASE_FILENAME = "weight-tracker-TEST.db" | |
| CSV_FILENAME = 'weights-TEST2.csv' | |
| DROPBOX_KEYCHAIN_NAME = "keychain name goes here, see pythonista keychain docs-- e.g. 'dropbox'" | |
| DROPBOX_KEYCHAIN_FIELD = "keychain field goes here-- e.g. 'myaccount'" | |
| import dropbox, keychain, sqlite3, datetime, csv, dialogs | |
| from matplotlib.pyplot import plot_date, show, subplots, legend |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # like the previous version (https://gist.github.com/paultopia/2cf73cbffe6dde1fd5f21b21d649e79b) but threading by reply previous tweet instead of first one | |
| from dialogs import text_dialog | |
| import twitter | |
| from time import sleep | |
| acct = twitter.get_all_accounts()[0] | |
| # if there are multiple accounts this will need to be changed to get different account. I only have one account so don't care. | |
| # right now I also don't care to have authentication error handling, will need to experiment with unauthenticated devices to figure out what it throws. | |
| def numerate_tweets(tweetlist): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests, appex | |
| from urllib.parse import urlparse | |
| url = appex.get_url().replace("dl=0", "dl=1") | |
| r = requests.get(url) | |
| filename = urlparse(url).path.rpartition("/")[-1].replace(".py", "-downloaded.py") | |
| with open(filename, "wb") as outfile: | |
| outfile.write(r.content) | |
| print("script downloaded as " + filename) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dialogs import text_dialog | |
| import twitter | |
| from time import sleep | |
| acct = twitter.get_all_accounts()[0] | |
| # if there are multiple accounts this will need to be changed to get different account. I only have one account so don't care. | |
| # right now I also don't care to have authentication error handling, will need to experiment with unauthenticated devices to figure out what it throws. | |
| def numerate_tweets(tweetlist): | |
| numtweets = len(tweetlist) | |
| newoutlist = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from requests import post | |
| from xml.etree.ElementTree import fromstring | |
| from copy import deepcopy | |
| endpoint = "http://freecite.library.brown.edu/citations/create" | |
| # the example citations on their webpage | |
| cite1 = "Udvarhelyi, I.S., Gatsonis, C.A., Epstein, A.M., Pashos, C.L., Newhouse, J.P. and McNeil, B.J. Acute Myocardial Infarction in the Medicare population: process of care and clinical outcomes. Journal of the American Medical Association, 1992; 18:2530-2536." | |
| cite2 = "Fielderman, A., Silvester, G., Gatsonis, C.A., Hoenig, J., Flynn, S. Prognostic significance of flow cytometric DNA analysis and proliferative index in stage I non-small cell lung cancer. American Review of Respiratory Disease, 1992; 146:707-710" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function partial(func, arg){ | |
| return function(){ | |
| var args = arguments ? [].slice.call(arguments) : [] | |
| args.unshift(arg); | |
| return func.apply(null, args); | |
| }; | |
| } | |
| // comp applies functions right to left, like Clojure. | |
| function comp(func1, func2){ |