1
0
mirror of https://github.com/Luzifer/browser-privacy.git synced 2024-09-16 11:58:24 +00:00

Add timestamp meta data

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-06-10 14:16:05 +02:00
parent da9ca6b62b
commit b954e6e462
Signed by: luzifer
GPG Key ID: DC2729FDD34BE99E
3 changed files with 24 additions and 7 deletions

View File

@ -1,5 +1,5 @@
default:
auto-hook-pre-commit:
python3 checksum.py
git status --porcelain | grep -q '^.M filters.txt' && python3 checksum.py || true
git status --porcelain | grep -q '^M filters.txt' && git add filters.txt || true

View File

@ -3,18 +3,31 @@ import re
import codecs
import hashlib
import base64
import datetime
checksumRegexp = re.compile(
r'^\s*!\s*checksum[\s\-:]+([\w\+\/=]+).*\n', re.I | re.M)
import pytz
checksumRegexp = re.compile(r'^! Checksum: ([\w\+\/=]+).*\n', re.M)
timeUpdRegexp = re.compile(r'^! TimeUpdated: (.*)\n', re.M)
def addChecksum(data):
checksum = calculateChecksum(data)
data = re.sub(checksumRegexp, '', data)
data = re.sub(r'(\r?\n)', r'\1! Checksum: %s\1' % checksum, data, 1)
data = re.sub(checksumRegexp,
r'! Checksum: {}\n'.format(checksum),
data,
1)
return data
def addDate(data):
d = datetime.datetime.utcnow().replace(microsecond=0)
d_with_timezone = d.replace(tzinfo=pytz.UTC)
now = d_with_timezone.isoformat()
return re.sub(timeUpdRegexp, r'! TimeUpdated: {}\n'.format(now), data)
def calculateChecksum(data):
data = normalize(data)
@ -31,6 +44,9 @@ def normalize(data):
if __name__ == '__main__':
data = addChecksum(open('filters.txt').read())
data = open('filters.txt').read()
data = addDate(data)
data = addChecksum(data)
with open('filters.txt', 'w') as f:
f.write(data)

View File

@ -1,7 +1,8 @@
! Title: Personal Clean-Web
! Checksum: E7mtj8wb20eOhhG24F1CGQ
! Checksum: O1mUaYsu7jkO/1NK70SXig
! Description: List of filter rules for uBlock Origin to enhance the browsing privacy and replace Ghostery
! Expires: 1 hour
! TimeUpdated: 2018-06-10T12:15:36+00:00
! Homepage: https://github.com/Luzifer/browser-privacy
! License: https://unlicense.org/