mirror of
https://github.com/Luzifer/browser-privacy.git
synced 2024-09-18 21:02:55 +00:00
Add timestamp meta data
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
da9ca6b62b
commit
b954e6e462
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
|||||||
default:
|
default:
|
||||||
|
|
||||||
auto-hook-pre-commit:
|
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
|
git status --porcelain | grep -q '^M filters.txt' && git add filters.txt || true
|
||||||
|
26
checksum.py
26
checksum.py
@ -3,18 +3,31 @@ import re
|
|||||||
import codecs
|
import codecs
|
||||||
import hashlib
|
import hashlib
|
||||||
import base64
|
import base64
|
||||||
|
import datetime
|
||||||
|
|
||||||
checksumRegexp = re.compile(
|
import pytz
|
||||||
r'^\s*!\s*checksum[\s\-:]+([\w\+\/=]+).*\n', re.I | re.M)
|
|
||||||
|
checksumRegexp = re.compile(r'^! Checksum: ([\w\+\/=]+).*\n', re.M)
|
||||||
|
timeUpdRegexp = re.compile(r'^! TimeUpdated: (.*)\n', re.M)
|
||||||
|
|
||||||
|
|
||||||
def addChecksum(data):
|
def addChecksum(data):
|
||||||
checksum = calculateChecksum(data)
|
checksum = calculateChecksum(data)
|
||||||
data = re.sub(checksumRegexp, '', data)
|
data = re.sub(checksumRegexp,
|
||||||
data = re.sub(r'(\r?\n)', r'\1! Checksum: %s\1' % checksum, data, 1)
|
r'! Checksum: {}\n'.format(checksum),
|
||||||
|
data,
|
||||||
|
1)
|
||||||
return data
|
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):
|
def calculateChecksum(data):
|
||||||
data = normalize(data)
|
data = normalize(data)
|
||||||
|
|
||||||
@ -31,6 +44,9 @@ def normalize(data):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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:
|
with open('filters.txt', 'w') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
! Title: Personal Clean-Web
|
! 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
|
! Description: List of filter rules for uBlock Origin to enhance the browsing privacy and replace Ghostery
|
||||||
! Expires: 1 hour
|
! Expires: 1 hour
|
||||||
|
! TimeUpdated: 2018-06-10T12:15:36+00:00
|
||||||
! Homepage: https://github.com/Luzifer/browser-privacy
|
! Homepage: https://github.com/Luzifer/browser-privacy
|
||||||
! License: https://unlicense.org/
|
! License: https://unlicense.org/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user