Add debug file caching

This commit is contained in:
2020-11-16 15:15:39 -05:00
parent c0c4837519
commit fd91cce506

View File

@@ -3,10 +3,14 @@
import tkinter as tk
from tkinter import filedialog
from tkinter import ttk
import os.path
import pandas
import gzip
import urllib.request
# This will enable file caching and some dev output
debug=True
class Main(tk.Frame):
"""This module generates information for the tkinter gui"""
@@ -45,7 +49,18 @@ class Main(tk.Frame):
self.columnconfigure(1, weight=1)
def get_toh_df(self):
cache_file = "sources/toh.tsv"
if debug is True and os.path.isfile(cache_file):
with open(cache_file) as infile:
try:
toh_df = pandas.read_csv(infile)
except:
os.remove(cache_file)
else:
toh_gz_handle = urllib.request.urlopen("https://openwrt.org/_media/toh_dump_tab_separated.gz")
toh_handle = gzip.open(toh_gz_handle)
toh_df = pandas.read_csv(toh_handle, sep="\t", encoding = "ISO-8859-1")
@@ -53,6 +68,9 @@ class Main(tk.Frame):
(toh_df.subtarget.notnull()) &
(toh_df.target != '¿') &
(toh_df.subtarget != '¿')]
if debug is True:
with open(cache_file, 'w') as outfile:
toh_df.to_csv(outfile)
return toh_df