jason_original / cf /trace_processing /convertTTLDict.py
1a1a11a's picture
Add files using upload-large-folder tool
8dc315b verified
import os, sys
import time
import csv
import requests
import pickle, json
from inspect import currentframe, getframeinfo
from collections import defaultdict, Counter
import hashlib
import struct
import socket
CONTENT_TYPE_SET = set(['jpeg', 'bin', 'json', 'js', 'png', 'webp', '', 'ts', 'css', 'html', 'm3u8', 'svg', 'gif', 'empty', 'dat', 'mp4', 'xml', 'txt', 'ors', 'woff', 'bundle', 'woff2', 'tgz', 'jpg', 'cer', 'plist', 'mpga' , 'ico', 'pbf', 'ccbi', 'qt', 'ttf', 'webm', 'tar', 'zip', 'ics', 'rss', 'aac', 'pdf', 'conda', 'eot', 'debounce', 'crl', 'm4s', 'enc', 'otf', 'wav', 'm4a', 'flat', 'atlas', 'der', 'wys', 'oga', 'gz', 'manifest', 'get', 'mp3', 'php', 'swf', 'skel', 'jar', 'template', 'odft', 'bmp', 'apk', 'rpm', 'xz', 'mpd', 'io', 'btx', 'fnt', 'xhtml', 'pub', 'exe', 'unityweb', 'csv', 'mat', 'events', 'ogx', 'geo', 'docx', 'sprite', 'micro', 'mid', 'jp2', 'doc', 'identity', 'vtt', 'terrain', 'xlsx', 'atom', 'epub', 'chunk', 'si d', 'm3u', '7z', 'invert', 'findkey', 'axd', 'xls', 'db', 'mpf', 'lua', 'webvtt', 'unity3d', 'appcache', 'tiff', 'rtf', 'wasm', 'jpgx', 'gzip', 'md', 'ppt', 'lb', 'ashx', 'm4v', 'py', 'srt', 'psd', 'settings', 'dmg', 'asp', 'sh', 'aspx', 'patch', 'dib', 'mov', 'rar', 'last', 'gcfg', 'yml', 'atf', 'java', 'stl', 'chm', 'crc', 'yaml', 'ai', 'c', 'unity', 'srx', 'scss', 'includes', 'flac', 'caf', 'extra', 'xslt', 'gpg', 'rdf', 'bam', ])
EXTENSION_SET = set(['jpg', '', 'tgz', 'js', 'png', 'json', 'm3u8', 'ts', 'css', 'webp', 'jpeg', 'svg', 'php', 'gif', 'mp4', 'dat', 'woff2', 'html', 'bundle', 'woff', 'rss', 'axd', 'crt', 'plist', 'mp3', 'txt', 'ico', 'pbf', 'gz', 'mov', 'ttf', 'm4s', 'ccbi', 'bin', 'lb', 'gzip', 'aspx', 'webm', 'jpgx', 'bz2', 'xml', 'zip ', 'ics', 'aac', 'pdf', 'conda', 'asp', 'ashx', 'eot', 'do', 'htm', 'atlas', 'crl', 'id', 'otf', 'map', 'bam', 'lua', 'xsd', 'erik', 'fca', 'enc', 'rpoly', 'properties', 'wav', 'h', 'flat', 'ogg', 'wys', 'manifest', 'm4a', 'jar', 'ece', 'gmp', 'dds', 'sig', 'pk2mz', 'swf', 'debounce', 'skel', 'template', 'acz', 'pack', 'cdiff', 'cson', 'jsonp', 'hash', 'dmg', 'sml', 'apk', 'lzma', 'jsp', 'rpm', 'cdf', 'io', 'csv', 'xz', 'tga', 'mpd', 'sha256', 'fnt', 'btx', 'depmap', 'distro', 'unity3d', 'svga', 'omit', 'xhtml', 'vipr', 'uniq', 'res', 'pub', 'b3dm', 'exe', 'fit', 'ln4', 'crop', 'pairs', 'prefab', 'pl', 'mkv', 'mat', 'cef', 'wmt', 'bif', 'dxt', 'vtt', 'deb', 'lm', 'geo', 'py', 'sprite', 'vghddata', 'docx', 'jfif', 'nfs', 'js', 'gifv', 'dlt', 'mid', 'data', 'unityweb', 'cms', 'jp2', 'identity', 'gcd', 'img', 'bmp', 'doc', 'cur', 'ect', 'page', 'pic', 'db', 'mjs', 'tif', 'meta', 'image', 'faces', 'prop', 'dll', 'xlsx', 'pfx', 'box', 'ani', 'chunk', 'terrain', 'epub', '7z', 'jnx', 'midi', 'tfl', 'asr', 'act', 'xrf', 'mpf', 'ln3', 'ejs', 'lani', 'avif', 'sh', 'inc', 'vue', 'xaf', 'webvtt', 'pptx', 'aff', 'wasm', 'flow', 'jmm', 'atom', 'ovpn', 'log', 'so', 'xpf', 'xls', 'anm', 'pngx', 'cmfv', 'gaf', 'aiu', 'srt', 'hvm', 'dwg', 'yml', 'mem', 'mobile', 'cvd', '3ds', 'java', 'lmat', 'md', 'sha1', 'm4v', 'tar', 'vbs', 'msi', 'rtf', 'svgz', 'appcache', 'psd', 'tmx', 'eps', 's3d', 'vpk', 'ini', 'stl', 'link', 'shtml', 'ppt', 'pkg', 'br', 'ttc', 'patch', 'dib', 'gcfg', 'yaml', 'atf', 'app', 'heic', 'lyric', 'simple', 'rss2', 'ebr', 'unity', 'rar', 'rgx', 'obj', 'md2', 'chm', 'crc', 'trf', 'gpi', 'lib', 'jpe', 'scss', 'xsl', 'pkmlz', 'cgi', 'srx', 'mdr' 'stat', 'sqlite', 'tiff', 'flac', 'sep', 'caf', 'mps', 'tdb', 'jpeg', 'cfm', 'gpg', 'geojson', 'sql', 'scml', 'gtt', 'bat', 'c', 'xmf', 'gsm', 'fsp', 'gcode', 'gifx', 'odt', 'opus', 'rbxm', 'gl', 'apkm', 'pak', 'util', 'cr2', 'conf', 'dylib', 'dict', 'm3u', 'cer', 'cpp', 'md5', 'xlsm', 'tsx', 'javascript'])
def convert_ttl_dict():
""" because some data such as allcolo.sort does not have content type information,
and the key is (hostname, content_type),
so we convert it into a chained dict with hostname, extension as keys,
and if we cannot find TTL for a given hostname, extension, we use a TTL of other content type for the same hostname
"""
ttl_dict_new = defaultdict(dict)
with open("ttl_dict.pickle", "rb") as f:
ttl_dict = pickle.load(f)
seen_content_type = set()
for (hostname, content_type), ttl in ttl_dict.items():
ttl_dict_new[hostname][content_type] = ttl
ttl_dict_new[hostname]["unknown"] = ttl
ttl_dict_new[hostname][""] = ttl
if content_type not in seen_content_type:
seen_content_type.add(content_type)
print(content_type)
with open("ttl_dict_new.pickle", "wb") as ofile:
pickle.dump(ttl_dict_new, ofile)
if __name__ == "__main__":
convert_ttl_dict()