Skip to content

Instantly share code, notes, and snippets.

View ethandrower's full-sized avatar

Ethan Drower ethandrower

View GitHub Profile
@ethandrower
ethandrower / selenium.py
Last active March 6, 2024 15:24
Configuring Selenium Downloads
## create a temp dir to manage the download
download_dir = os.path.join("/tmp/", str(uuid.uuid4()))
os.makedirs(download_dir, exist_ok=True)
# Create directories if they don't exist
## update selenium to download to your new directory
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir}}
import logging
from settings import LOGGING_LEVEL
LOGGING_FORMAT = '%(asctime)s - AutoUpload - \
%(levelname)s - %(message)s'
logging.basicConfig(level=LOGGING_LEVEL, format=LOGGING_FORMAT)
@ethandrower
ethandrower / heroku-cron-job.py
Created February 9, 2022 01:06
Python Cronjob Crontab Repeating Tasks and Scripts
from apscheduler.schedulers.blocking import BlockingScheduler
import sys, traceback
sched = BlockingScheduler()
@sched.scheduled_job('interval',
id='check_carts',
minutes=1,
@ethandrower
ethandrower / zip_creator.py
Created December 9, 2021 16:02
Creating Zip Files in Python
temp_folder = "/tmp/" + str(uuid.uuid4()) + "/"
zip_file = 'images_{0}.zip'.format(uuid.uuid4())
os.mkdir(temp_folder)
for image in images:
# generate some dir
# figure out how to use unique name (from s3)
image_name = image.converted.name.replace("converted/", "").replace("tmp/","")
image = image.converted.open()
@ethandrower
ethandrower / measuring time long functions.py
Created August 1, 2021 23:09
measuring time in seconds for long running functions
import time
start = time.time()
print("hello")
end = time.time()
print(end - start)
@ethandrower
ethandrower / shopify-login-redirect.liquid
Last active July 7, 2021 03:53
Shopify how to redirect customers after they login
<!-- this is in your customers/login.liquid template file -->
{% form 'customer_login', novalidate: 'novalidate', return_to: '/pages/test-page' %}
@ethandrower
ethandrower / shopify-force-login.js
Last active July 7, 2021 00:57
Shopify force users to login with redirect template
// put this in your theme's header.liquid template file
{% if customer %}
//requires JS Cookies library if you want to store their email. *optional*
Cookies.set('email','{{ customer.email }}',{expires:1});
{% else %}
if (window.location.href.indexOf('account') == -1){
@ethandrower
ethandrower / jupyter-install-pip.py
Created June 18, 2021 15:13
Install pip python package on a jupyter-notebook
#from Bio import Medline
import sys
!{sys.executable} -m pip install biopython
"""" README
This is a simpler workaround to the heroku django database package. If you want to run a local sqlite database
and be able to easily switch to a remote heroku database (through only one ENV with the DATABASE_URL) this will work.
Installation:
The below code goes into your django settings file (in place of the existing database configuration)
Set the ENV DATABASE_URL by copying it over from your Heroku Instance.
Set the ENV LOCAL=0 to connect to Heroku
@ethandrower
ethandrower / django_s3_files.py
Created October 28, 2020 23:06
Working With Files in Django Requests and S3 Objects
from django.core.files import File
import requests
## to download from a URL and store in a django FileField()
s3_url = "yours3_url_here"
with open('temp_file.txt', 'wb') as f:
f.write(requests.get(s3_url).content)