Skip to content

Instantly share code, notes, and snippets.

View shacker's full-sized avatar
💭
Djangonaut, tree hugger

Scot Hacker shacker

💭
Djangonaut, tree hugger
View GitHub Profile
# General pattern for a data "chunking" process to prevent a server from hitting memory limits
# when calling .update() or .delete() on large amounts of data. In this example, we enter an
# infinite loop, then keep deleting 1000 records at a time until the records are exhausted,
# then exit the loop. You can't call .update() or .delete() after taking a slice, hence the need
# for two queries rather than one.
t = Territory.objects.get(name="some-territory")
while True:
loc_ids = Location.objects.filter(territory=t)[:1000].values_list("id", flat=True)
@shacker
shacker / import_drupal_pages.py
Created August 20, 2015 18:44
Django management command to import flat Drupal page sets into a wagtail tree
from datetime import datetime
import json
import requests
import sys
from bs4 import BeautifulSoup
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
@shacker
shacker / gift-circle.py
Created December 5, 2010 22:13
Replace "drawing names from a hat" gift exchanges with a quick script
#!/usr/bin/python
'''
Python-based gift exchange randomizer.
Step through a list of people and, for each member of that list,
select someone else to be a recipient of their gift. That recipient:
A) Must not be themselves (no self-gifting)
B) Must not already have been assigned as a recipient
@shacker
shacker / gist:87908e13c9ee6655ce90
Last active October 5, 2023 17:46
Using the Workday API with Python and the suds client library
import sys
from suds import client
from suds.wsse import Security, UsernameToken
from suds.sax.text import Raw
from suds.sudsobject import asdict
from suds import WebFault
'''
Given a Workday Employee_ID, returns the last name of that employee.