Skip to content

Instantly share code, notes, and snippets.

View duncangh's full-sized avatar
💭
👨‍💻

Graham Duncan duncangh

💭
👨‍💻
View GitHub Profile
@duncangh
duncangh / get_lat_lon_exif_pil.py
Created November 9, 2018 22:13 — forked from erans/get_lat_lon_exif_pil.py
Get Latitude and Longitude from EXIF using PIL
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
def get_exif_data(image):
"""Returns a dictionary from the exif data of an PIL Image item. Also converts the GPS Tags"""
exif_data = {}
info = image._getexif()
if info:
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
@duncangh
duncangh / organize-photos.py
Created November 9, 2018 22:13 — forked from cliss/organize-photos.py
Photo management script. This script will copy photos from "~/Pictures/iPhone Incoming" into a tree the script creates, with folders representing month and years, and photo names timestamped. Completely based on the work of the amazing Dr. Drang; see here: http://www.leancrew.com/all-this/2013/10/photo-management-via-the-finder/ You can see more…
#!/usr/bin/python
import sys
import os, shutil
import subprocess
import os.path
from datetime import datetime
######################## Functions #########################
@duncangh
duncangh / ftp_uploader.py
Created November 12, 2018 23:40 — forked from opnchaudhary/ftp_uploader.py
A sample example for uploading files using ftp in python
#!/usr/bin/python
import ftplib
session = ftplib.FTP('example.com','username','password')
file = open('cup.mp4','rb') # file to send
session.storbinary('STOR '+'cup.mp4', file) # send the file
file.close() # close file and FTP
session.quit()
@duncangh
duncangh / readme.md
Last active November 14, 2018 18:30
Instructions for the nightly check
  1. From the graham-db website (link: https://graham-db.herokuapp.com/#), execute the query:

    select * from realtime_sync.supply_nightly_opis_price_review_v2; 
  2. Export the results of this query to CSV and the file will open in Excel in a file named something like pgweb-8328742.csv

  3. From the exported csv file in step 2, copy columns A and B into the FOB Template Excel File on the sheet named actual_rank in the columns A and B

  4. Columns C and D will autopopulate as the formulae reflect the newly pasted values

@duncangh
duncangh / feeds.py
Created November 14, 2018 06:40 — forked from ksamuel/feeds.py
RSS/Atom link auto detection. Use feedparser and beautifulsoup
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4
"""
Tools to extract feed links, test if they are valid and parse them
with feedparser, returning content or a proper error.
"""
# coding=UTF-8
import nltk
from nltk.corpus import brown
# This is a fast and simple noun phrase extractor (based on NLTK)
# Feel free to use it, just keep a link back to this post
# http://thetokenizer.com/2013/05/09/efficient-way-to-extract-the-main-topics-of-a-sentence/
# Create by Shlomi Babluki
# May, 2013
@duncangh
duncangh / Writing better python code.md
Created November 27, 2018 02:06 — forked from kracekumar/Writing better python code.md
Talk I gave at June bangpypers meetup.

Writing better python code


Swapping variables

Bad code

@duncangh
duncangh / gmail_imap_example.py
Created November 27, 2018 02:28 — forked from robulouski/gmail_imap_example.py
Very basic example of using Python and IMAP to iterate over emails in a gmail folder/label. http://www.voidynullness.net/blog/2013/07/25/gmail-email-with-python-via-imap/
#!/usr/bin/env python
#
# Very basic example of using Python and IMAP to iterate over emails in a
# gmail folder/label. This code is released into the public domain.
#
# RKI July 2013
# http://www.voidynullness.net/blog/2013/07/25/gmail-email-with-python-via-imap/
#
import sys
import imaplib
@duncangh
duncangh / admin_list_editable_autosubmit.js
Created December 3, 2018 16:05 — forked from magopian/admin_list_editable_autosubmit.js
Small js script that automatically submits the changelist form on field changes. This is convenient when used with https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_editable, and avoids having to remember to submit the form when done (the form on the changelist page doesn't look like a form after all, …
/*
* Only useful in changelist pages when the ModelAdmin displayed has
* "list_editable" (https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_editable)
* configured.
*
* When one of the input/select/textarea value is changed, automatically submit
* the form using ajax.
*
* Only form fields relevant to the "list_editable" will trigger a form submit.
*
@duncangh
duncangh / log.py
Created December 4, 2018 16:11 — forked from Bernix01/log.py
drf LogEntry viewset Mixin
'''
Extracted and modified from django-model-logging
It used it's own LogEntry model but since django
has it's own LogEntry maybe someone would want to
register in the same model instead of creating a
new one.
'''
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, ContentType, DELETION
from django.utils.translation import gettext as _