-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDb_insertion.py
More file actions
128 lines (115 loc) · 4.06 KB
/
Db_insertion.py
File metadata and controls
128 lines (115 loc) · 4.06 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Model_table = {
"OpenAI": {
"gpt-4.1": 10.0,
"gpt-4.1-mini": 2.0,
"gpt-4.1-nano": 0.5,
"gpt-4o": 12.50,
"gpt-4o-mini": 1.00,
},
"Claude": {
"claude-3-5-sonnet": 0.8,
"claude-3-5-haiku": 0.5,
},
"Gemini": {
"gemini-1.5-pro-latest": 0.6,
"gemini-2.5-flash": 0.4,
}
}
# Packages = {
# "Basic": {
# "Credits": 1000,
# "Price": 10,
# "Description": "Perfect for light usage",
# "Features": [
# "1,000 Credits",
# "No expiration",
# "All models included",
# "Email support"
# ],
# "Link": "https://buy.stripe.com/test_cNi7sEdVc8g8aV52xSg3600",
# "Popular": False
# },
# "Pro": {
# "Credits": 5000,
# "Price": 40,
# "Description": "Most popular choice",
# "Features": [
# "5,000 Credits",
# "No expiration",
# "All models included",
# "Priority support",
# "20% savings"
# ],
# "Link": "https://buy.stripe.com/test_7sY14g4kCcwo7ITa0kg3601",
# "Popular": True,
# "Discount": "20% off"
# },
# "Enterprise": {
# "Credits": 10000,
# "Price": 70,
# "Description": "Best value for heavy users",
# "Features": [
# "10,000 Credits",
# "No expiration",
# "All models included",
# "Priority support",
# "Bulk discount",
# "30% savings"
# ],
# "Link": "https://buy.stripe.com/test_8x23co7wO3ZS1kv5K4g3602",
# "Popular": False,
# "Discount": "30% off"
# }
# }
# Database insertion code
import os
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def insert_data_to_collections():
"""
Insert Model_table and Packages data into MongoDB collections
"""
try:
# Setup MongoDB connection
uri = os.getenv('MONGO_URL')
if not uri:
print("Error: MONGO_URL environment variable not found")
return False
client = MongoClient(uri, server_api=ServerApi('1'))
db = client["Translator-Data"]
# Get collections
model_cost_collection = db["Model Cost"]
translation_packages_collection = db["Translation packages"]
# Clear existing data (optional - remove if you want to preserve existing data)
print("Clearing existing data...")
model_cost_collection.delete_many({})
translation_packages_collection.delete_many({})
# Insert Model_table into "Model Cost" collection
print("Inserting Model_table into 'Model Cost' collection...")
model_cost_collection.insert_one({
"_id": "model_costs",
"data": Model_table,
"inserted_at": "2024-01-20",
"description": "Model pricing information for different AI providers"
})
# Insert Packages into "Translation packages" collection
print("Inserting Packages into 'Translation packages' collection...")
translation_packages_collection.insert_one({
"_id": "pricing_packages",
"data": Packages,
"inserted_at": "2024-01-20",
"description": "Available credit packages for users"
})
print("✅ Successfully inserted data into MongoDB collections!")
print(f"- Model Cost collection: {model_cost_collection.count_documents({})} documents")
print(f"- Translation packages collection: {translation_packages_collection.count_documents({})} documents")
client.close()
return True
except Exception as e:
print(f"❌ Error inserting data: {str(e)}")
return False
if __name__ == "__main__":
insert_data_to_collections()