Skip to content

Instantly share code, notes, and snippets.

View craigderington's full-sized avatar
🚀
Automate Everything

Craig Derington craigderington

🚀
Automate Everything
View GitHub Profile
@craigderington
craigderington / get-cta-bus-route.py
Last active September 26, 2016 17:40
CTA bus route tracking from Python Data Hacking
#! /usr/bin/python
import time
import requests
import xml.etree.ElementTree as ET
my_latitude = 39.0548746
url = 'http://ctabustracker.com/bustime/map/getBusesForRoute.jsp?route='
route = str(input('Please select a bus route to view: '))
import os
import collections
import random
import time
DataPoint = collections.namedtuple('DataPoint', 'id, x, y, temp, quality')
def main():
print('Creating dataset.')
data_list = []
#! /usr/bin/python
import os
import re
import requests
from bs4 import BeautifulSoup
url = 'http://random-name-generator.info'
hdr = {
@craigderington
craigderington / models.py
Last active November 23, 2016 14:15
Solved: Django Tables2 and AJAX
from django.contrib.auth.models import User
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models import Q
class Alert(models.Model):
SYSTEM_ALERT = 'system_alert'
@craigderington
craigderington / models.py
Last active November 29, 2016 13:58
Customer Model
# models.py
from django.db import models
class Customer(models.Model):
company = models.ForeignKey('Company', null=False)
customer_first_name = models.CharField(null=False, blank=False, max_length=50)
customer_last_name = models.CharField(null=False, blank=False, max_length=50)
customer_email = models.CharField(null=False, blank=False, max_length=80)
{% extends "base.html" %}
{% load bootstrap3 %}
{% load querystring from django_tables2 %}
{% load title from django_tables2 %}
{% load trans blocktrans from i18n %}
{% block "content" %}
{% if table.page %}
@craigderington
craigderington / views.py
Last active November 29, 2016 13:59
CustomerListView - Generic List View with Django Tables
from django.views.generic import ListView
from braces.views import LoginRequiredMixin, GroupRequiredMixin
from django_tables2 import RequestConfig
from .models import Customer
from .tables import CustomerTable
class CustomerListView(LoginRequiredMixin, GroupRequiredMixin, ListView):
model = Customer
template_name = 'customer_list.html'
#! flask/bin/python
from flask import Flask, request, jsonify, abort, make_response, url_for
from flask_restful import Api, Resource, reqparse, fields, marshal
from flask_httpauth import HTTPBasicAuth
from datetime import datetime
import pyodbc
import json
import config
class Item(TimeStampedModel):
LEADTIME_PERIOD = (
('D', 'DAYS'),
('W', 'WEEKS'),
('M', 'MONTHS'),
)
sku = models.CharField(max_length=50, blank=False, null=False)
item_name = models.CharField(max_length=50, blank=False, null=False)
item_description = models.TextField()
class Location(BaseAddress, TimeStampedModel):
location_name = models.CharField(max_length=50, blank=False, null=False)
default_location = models.BooleanField(default=False)
def __unicode__(self):
if self.location_name and self.city:
return unicode(str(self.location_name + '-' + self.city))
class Meta:
verbose_name = 'Location'