Skip to content

Instantly share code, notes, and snippets.

View gpaciga's full-sized avatar

Gregory Paciga gpaciga

View GitHub Profile
@gpaciga
gpaciga / simple_cors_server.py
Last active May 17, 2024 05:39 — forked from acdha/simple_cors_server.py
Python 3: serve the current directory as HTTP while setting CORS headers for XHR debugging
#!/usr/bin/env python3
# encoding: utf-8
"""Use instead of `python3 -m http.server` when you need CORS"""
import sys
from http.server import HTTPServer, SimpleHTTPRequestHandler
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
@gpaciga
gpaciga / ttc-nextbus.py
Created December 30, 2020 22:39
Print next bus arrival times for a TTC stop
import requests
import xml.etree.ElementTree as ET
import time
AGENCY="ttc"
STOP_ID=12345
PREDICTIONS = f"http://webservices.nextbus.com/service/publicXMLFeed?a={AGENCY}&command=predictions&stopId={STOP_ID}"
def print_next():
xml_predictions = requests.get(PREDICTIONS)