-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_db.py
More file actions
45 lines (40 loc) · 1.59 KB
/
init_db.py
File metadata and controls
45 lines (40 loc) · 1.59 KB
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
import firebase_admin
from firebase_admin import credentials, db
from datetime import datetime
# Initialize Firebase
cred = credentials.Certificate("serviceAccountKey.json")
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://codeeditor-db5bc-default-rtdb.firebaseio.com/'
})
# Get a reference to the problems node
problems_ref = db.reference('/problems')
# Sample problems
sample_problems = {
'two-sum': {
'title': 'Two Sum',
'description': 'Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.',
'difficulty': 'Easy',
'starter_code': 'def two_sum(nums, target):\n # Your code here\n pass',
'test_cases': [
{'input': [[2, 7, 11, 15], 9], 'output': [0, 1]},
{'input': [[3, 2, 4], 6], 'output': [1, 2]}
],
'video_id': 'KLlXCFG5TnA', # Example YouTube video ID
'created_at': datetime.utcnow().isoformat()
},
'palindrome': {
'title': 'Palindrome Number',
'description': 'Given an integer x, return true if x is a palindrome, and false otherwise.',
'difficulty': 'Easy',
'starter_code': 'def is_palindrome(x):\n # Your code here\n pass',
'test_cases': [
{'input': [121], 'output': True},
{'input': [-121], 'output': False},
{'input': [10], 'output': False}
],
'created_at': datetime.utcnow().isoformat()
},
}
# Set the problems in the database
problems_ref.set(sample_problems)
print("Sample problems initialized successfully!")