@keestalkstech/

ValidGuiltyScript

Python

No description

fork
loading
Files
  • main.py
  • data.tmp
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import hashlib, math, sys

def get_s3_key_with_hash(name):

  name_in_bytes = bytes(name, 'UTF-8')
  hash_in_bytes = hashlib.md5(name_in_bytes).digest();
  int32 = int.from_bytes(hash_in_bytes[0:4], sys.byteorder, signed=True)
  int32 = math.fabs(int32)
  prefix = str(int32).zfill(4)
  prefix = prefix[0:4]

  return prefix + '/' + name


with open('data.tmp', 'r') as content_file:
    test_data = content_file.read()

print("Removing hash-folders from test data...")
pairs = map(lambda x: x.split('/'), test_data.split('\n'))

print()
print("Calculating hash-folders for test data:")
for pair in pairs:
    name = pair[1]
    full = pair[0] + '/' + pair[1]
    key = get_s3_key_with_hash(name)
    same = key == full
    print(('👍' if same else '☠️') + '  ' + key)

print()
print("Done!")