Created
October 7, 2015 09:44
-
-
Save grim13b/7e8e5b2b5f42d8f10298 to your computer and use it in GitHub Desktop.
雑にCloudFrontのログにあるURLエンコーディングをデコードする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import sys | |
from urllib.parse import unquote | |
from urllib.parse import unquote_plus | |
def decode(filename): | |
with open(filename, 'r') as f: | |
reader = csv.reader(f, delimiter='\t') | |
for row in reader: | |
print('\t'.join(decode_line(row))) | |
def decode_line(fields): | |
for i, field in enumerate(fields): | |
fields[i] = unquote_plus(unquote(unquote(field))) | |
return fields | |
decode(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment