-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.py
61 lines (45 loc) · 1.49 KB
/
manager.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import firebase_admin
from firebase_admin import credentials, db
import json
import os
from dotenv import dotenv_values
env_vars = dotenv_values(".env")
cred = env_vars.get("CRED")
if not cred:
cred = os.environ.get("CRED")
cred = cred.replace('\n', '\\n')
cred_dict = json.loads(cred)
cred = credentials.Certificate(cred_dict)
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://myezlynk-default-rtdb.firebaseio.com/'})
ref = db.reference('/')
def append_data(route, link):
ref.child('links').child(route).set(link)
return "Data appended successfully!"
def access_all_links():
links_ref = ref.child('links')
all_links = links_ref.get()
return all_links
def access_link_by_route(route):
links_ref = ref.child('links')
link = links_ref.child(route).get()
if link:
return link
else:
return None
import string
def shortest_unused_string(input_dict):
"""Return the shortest string not in use within the given dictionary."""
existing_keys = set(input_dict.keys())
alphabet = string.ascii_lowercase
for char in alphabet:
if char not in existing_keys:
return char
for length in range(2, len(alphabet) + 2):
for first_char in alphabet:
candidate = first_char
for _ in range(length - 1):
for next_char in alphabet:
candidate += next_char
if candidate not in existing_keys:
return candidate