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