Skip to content

Instantly share code, notes, and snippets.

@grim13b
Created October 7, 2015 09:44
Show Gist options
  • Save grim13b/7e8e5b2b5f42d8f10298 to your computer and use it in GitHub Desktop.
Save grim13b/7e8e5b2b5f42d8f10298 to your computer and use it in GitHub Desktop.
雑にCloudFrontのログにあるURLエンコーディングをデコードする
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