Skip to content

Instantly share code, notes, and snippets.

@ian-weisser
ian-weisser / clock.py
Created April 5, 2014 15:10
Tkinter clock widget
#!/usr/bin/python3
import tkinter
import time
"""
Example tkinter Clock widget, counting seconds and minutes in realtime.
Functions just like a Label widget.
@ian-weisser
ian-weisser / find_stops.py
Last active February 14, 2019 02:14
Parse a GTFS file for stops near a location
#!/usr/bin/python3
"""
Locate stop_id candidates from a GTFS stops file.
This is a helper application. You use it to discover a list
of possible stop_ids for your *real* application. It's handy
during debugging, or during setup of an application.
Example: You know an intersection name or a lat/lon pair or
@ian-weisser
ian-weisser / valid_calendar_dates.py
Created April 5, 2014 19:48
Test a GTFS file's calendar and calendar_dates tables for a specific date (like today)
#!/usr/bin/python3
"""
Check a GTFS file's calendar and calendar_dates tables.
Return True if the dates are current or future.
Return False if all dates are in the past and the GTFS file
can be safely deleted.
This is a working example. Try it. Edit the path to match your GTFS file.
"""
@ian-weisser
ian-weisser / ncurses_clock.py
Created April 6, 2014 23:45
Python class that adds an easy, independent clock to a Curses window
#!/usr/bin/python3
import curses
import time
import threading
class Clock(threading.Thread):
""" Clock curses string class. Updates every second. Easy to install """
@ian-weisser
ian-weisser / autocomplete.py
Created April 7, 2014 00:33
Python3 tkinter text entry widget with built-in autocompletion class,, with working example
#!/usr/bin/python3
"""
tkentrycomplete.py
A tkinter widget that features autocompletion.
Created by Mitja Martini on 2008-11-29.
Converted to Python3 by Ian weisser on 2014-04-06.
"""
@ian-weisser
ian-weisser / load_table
Last active July 28, 2016 13:32
Map GTFS table data into a python dict
def map_gtfs_table_to_dict(gtfs_file, table_name):
"""
Read data from a GTFS table, map the data into a list or dict for
easier iteration or searching or other use. Each line of the table
is mapped into a separate subdict, with a unique key.
Many GTFS tables include a unique value (Example: trips_id in the
trips.txt table) that this function automatically uses as the
dict key. If a tables has no unique key (Example: calendar_dates.txt),
the system generates a unique key using an incrementing row counter.
@ian-weisser
ian-weisser / load_stop_times
Created June 13, 2014 21:46
Load stop_times.txt into a python dict
def map_stop_times_to_dict(gtfs_file, list_of_stops):
"""
The stop_times.txt table can be *huge*, and can eat all your RAM
as 100MB of string data gets split into 1GB of dict data.
Instead, load the table in chunks, and filter it for the content
we want before loading the next chunk.
Reducing the huge stop_times file by ~95% also has the side effect
of cutting the script runtime in half.
@ian-weisser
ian-weisser / network_test.py
Last active November 4, 2020 22:24
Python3 - Am I on the right network?
#!/usr/bin/python3
import subprocess
def right_network (fqdn):
"""
# Example of using 'dig' to find the IP address of a network IP address
$ dig -4 +short www.example.com
24.209.187.117