Created
February 25, 2020 08:08
-
-
Save abramsymons/32cc5ba32ef889e56ae3a6d9a9911e4a to your computer and use it in GitHub Desktop.
This file contains 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 time | |
from arango import ArangoClient | |
db = ArangoClient().db('_system') | |
users = db.collection('users') | |
connections = db.collection('connections') | |
def urlSafeB64ToB64(s): | |
s = s.replace('_', '/').replace('-', '+') | |
while len(s) % 4: | |
s += '=' | |
return s | |
def setSigningKey(): | |
for user in users: | |
if 'signingKey' in user: | |
continue | |
user['signingKey'] = urlSafeB64ToB64(user['_key']) | |
users.update(user) | |
print(user['_key'], user['signingKey']) | |
def setCreatedAt(): | |
createdAt = {} | |
for conn in connections: | |
if 'timestamp' not in conn: | |
print(conn) | |
continue | |
f = conn['_from'].replace('users/', '') | |
t = conn['_to'].replace('users/', '') | |
if f not in createdAt or conn['timestamp'] < createdAt[f]: | |
createdAt[f] = conn['timestamp'] | |
if t not in createdAt or conn['timestamp'] < createdAt[t]: | |
createdAt[t] = conn['timestamp'] | |
for user in users: | |
if 'createdAt' in user: | |
continue | |
user['createdAt'] = createdAt.get(user['_key'], int(1000*time.time())) | |
users.update(user) | |
print(user['_key'], user['createdAt']) | |
if __name__ == '__main__': | |
setSigningKey() | |
setCreatedAt() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment