generated from nyu-software-engineering/python-package-exercise
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup mongoDB database + added seed scripts for mongoDB + line random…
…izer
- Loading branch information
zeep
authored and
zeep
committed
Nov 4, 2023
1 parent
dcb1a05
commit 17103ec
Showing
6 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pymongo==4.6.0 | ||
python-dotenv==0.16.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"lines": [ | ||
"Is it okay if I walk you home? My heart seems to follow wherever you go.\n", | ||
"If beauty were a moment, you'd be an eternity.\n", | ||
"Did we just share an elevator? Because I believe we have some serious uplifted chemistry.\n", | ||
"I must be a snowflake because I've fallen for you.\n", | ||
"Every time I see you, it feels like I've discovered a new shade of color.\n", | ||
"If stars would shine every time I thought of you, the night sky would never be dark.\n", | ||
"Do you believe in love at first sight, or should I walk by again?\n", | ||
"Your voice is my favorite sound, and your name is my favorite noun.\n", | ||
"If I were to rewrite the alphabet, I'd put U and I together.\n", | ||
"Have you been to the doctor recently? Because I think you've got a case of being mesmerizing.\n", | ||
"I wouldn't need a camera to savor this moment; I just need you.\n", | ||
"Is it hot in here, or is it just the aura of warmth you radiate?\n", | ||
"I tried finding the perfect line to make you smile, but then I realized you are the line.\n", | ||
"If you were a vegetable, you'd be a 'cute-cumber.'\n", | ||
"If life was a song, your smile would be the melody that gets stuck in my head.\n", | ||
"I'm not a photographer, but I can surely picture us together.\n", | ||
"If you were a fruit, you'd be a fine-apple.\n", | ||
"I'm not sure if it was the sparkle in your eyes or your radiant smile, but something just lit up my world.\n", | ||
"Do you mind holding my hand? I want to be sure I'm not dreaming.\n", | ||
"I've been trying to tie my shoes, but I can't stop tripping over my thoughts of you.\n", | ||
"Is there a rainbow today? Because I've just found my pot of gold in you.\n", | ||
"Do you have a map? I keep getting lost in your eyes.\n", | ||
"If you were a star, you'd outshine the entire galaxy.\n", | ||
"I'm not a wishful thinker, but with you, I believe in fairy tales.\n", | ||
"I thought happiness started with an H, but mine starts with U.\n", | ||
"Your smile must be a black hole because it's irresistibly attractive.\n", | ||
"Are you Wi-fi? Because I'm feeling a connection.\n", | ||
"If kisses were snowflakes, I'd send you a blizzard.\n", | ||
"Do you have a Band-Aid? I just scraped my knee falling for you.\n", | ||
"Your presence makes my heart race, but it's a marathon I never want to finish.\n", | ||
"If beauty were a crime, you'd be serving a life sentence.\n", | ||
"Did it hurt? When you fell from the stars and landed in my world?\n", | ||
" I'm not a genie, but I can make your dreams come true.\n", | ||
"Every song I hear reminds me of you, even the ones I haven't heard yet.\n", | ||
"I never believed in magic until I saw you.\n", | ||
"If you were words on a page, you'd be the fine print.\n", | ||
" Are you made of copper and tellurium? Because you're Cu-Te.\n", | ||
"Can I follow you? Because my mom told me to follow my dreams.\n", | ||
"Your beauty could inspire poets and artists for generations.\n", | ||
"Do you believe in destiny? Because I think ours just intertwined.\n", | ||
"Are you a calculator? Because every time I look at you, things start adding up.\n", | ||
"Is your name Google? Because you have everything I've been searching for.\n", | ||
"Do you have a name, or can I call you mine?\n", | ||
"Are you a magician? Every time I look at you, everyone else disappears.\n", | ||
"Do you like basketball? Because when I saw you, my heart did a slam dunk.\n", | ||
"Are you a library book? Because I can't help but check you out.\n", | ||
"If you were a vegetable, you'd be a cutecumber.\n", | ||
"Do you have a sunburn or are you always this hot?\n", | ||
"Is your dad a boxer? Because you're a knockout.\n", | ||
"Are you a loan from a bank? Because you have my interest.\n", | ||
"Are you a campfire? Because you're hot and I want s'more.\n", | ||
"Do you have a pencil? Because I want to erase your past and write our future.\n", | ||
"Are you a parking ticket? Because you've got 'FINE' written all over you.\n", | ||
"If I could rearrange the alphabet, I would put U and I together.\n", | ||
"Are you a snowstorm? Because you make my heart race.\n", | ||
"Do you have a Band-Aid? Because I just scraped my knee falling for you.\n", | ||
"Is your dad a baker? Because you're a cutie pie.\n", | ||
"Are you a time traveler? Because I can see you in my future.\n", | ||
"Are you a candle? Because you light up my world.\n", | ||
"Are you a string? Because I can't stop finding myself attached to you.\n", | ||
"If you were a function, I'd call you every day.\n", | ||
"Are you a loop? Because I can't stop thinking about you again and again.\n", | ||
"You're the 'key' to my 'value'.\n", | ||
"If beauty were data, you'd be an overflow error.\n", | ||
"Are you a variable? Because I feel the need to declare my intentions.\n", | ||
"I think you've just incremented my heart's counter.\n", | ||
"You're the API to my application.\n", | ||
"If relationships were algorithms, ours would be a perfect match.\n", | ||
"Your presence makes my system run at optimal efficiency.\n", | ||
"If you were an exception, I'd catch you.\n", | ||
"You must be a compiler because every time I see you, my code becomes runnable.\n", | ||
"I'm not a photographer, but I can picture us in an endless loop together.\n", | ||
"In the world of binary, you are the one for me.\n", | ||
"I've got a lot of lines of code, but none as intriguing as the story of us.\n", | ||
"Forget the cloud, you've taken up all the storage in my heart.\n", | ||
"I don't need version control to know you're my final commit.\n", | ||
"Let's merge our branches and build a beautiful codebase together.\n", | ||
"Do you believe in parallel universes? Because in every one I've imagined, it's always been you and me.\n", | ||
"You must be a packet because I can't help but sniff you out in a crowd.\n", | ||
"Are you an algorithm? Because every part of me wants to solve you.\n", | ||
"Do you know JavaScript? Because you make my heart race asynchronously.\n", | ||
"If I were to traverse the nodes of my heart, every path would lead to you.\n", | ||
"In the Git of life, I'd never want to revert our commit.\n", | ||
"Are you a CSS file? Because without you, my life would be unstyled.\n", | ||
"You must be a bug, because I just can't shake you off my mind.\n", | ||
"If hearts had firewalls, you'd have bypassed mine ages ago.\n", | ||
"Are you a Boolean? Because true or false, my heart points to you.\n", | ||
"In the world of objects, you are my favorite instance.\n", | ||
"If attraction were a programming language, ours would be high-level.\n", | ||
"Are you a kernel? Because my heart feels an urge to dive deeper into you.\n", | ||
"Do you like Java? Because you've Objectified my affections.\n", | ||
"I'd never put our relationship in a try-catch block, because I never want to handle an exception with us. \n", | ||
"You're not just a semicolon; you're the statement that completes me.\n", | ||
"In the IDE of life, you've just become my favorite extension.\n", | ||
"If I were a coder, I'd refactor my life to include more of you.\n", | ||
"You're like the most elegant code I've ever seen; concise, beautiful, and effective.\n", | ||
"You've stolen the ASCII to my heart.\n", | ||
"You must be an exception, because I can't handle you properly.\n", | ||
"You must be an algorithm, because you have my heart running in O(1) time.\n", | ||
"Are you a piece of code? Because you're turning my software into hardware!\n", | ||
"Are you a compressed file? Because when I see you, my heart wants to unzip.\n", | ||
"I'm the RizzLord." | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
Is it okay if I walk you home? My heart seems to follow wherever you go. | ||
If beauty were a moment, you'd be an eternity. | ||
Did we just share an elevator? Because I believe we have some serious uplifted chemistry. | ||
I must be a snowflake because I've fallen for you. | ||
Every time I see you, it feels like I've discovered a new shade of color. | ||
If stars would shine every time I thought of you, the night sky would never be dark. | ||
Do you believe in love at first sight, or should I walk by again? | ||
Your voice is my favorite sound, and your name is my favorite noun. | ||
If I were to rewrite the alphabet, I'd put U and I together. | ||
Have you been to the doctor recently? Because I think you've got a case of being mesmerizing. | ||
I wouldn't need a camera to savor this moment; I just need you. | ||
Is it hot in here, or is it just the aura of warmth you radiate? | ||
I tried finding the perfect line to make you smile, but then I realized you are the line. | ||
If you were a vegetable, you'd be a 'cute-cumber.' | ||
If life was a song, your smile would be the melody that gets stuck in my head. | ||
I'm not a photographer, but I can surely picture us together. | ||
If you were a fruit, you'd be a fine-apple. | ||
I'm not sure if it was the sparkle in your eyes or your radiant smile, but something just lit up my world. | ||
Do you mind holding my hand? I want to be sure I'm not dreaming. | ||
I've been trying to tie my shoes, but I can't stop tripping over my thoughts of you. | ||
Is there a rainbow today? Because I've just found my pot of gold in you. | ||
Do you have a map? I keep getting lost in your eyes. | ||
If you were a star, you'd outshine the entire galaxy. | ||
I'm not a wishful thinker, but with you, I believe in fairy tales. | ||
I thought happiness started with an H, but mine starts with U. | ||
Your smile must be a black hole because it's irresistibly attractive. | ||
Are you Wi-fi? Because I'm feeling a connection. | ||
If kisses were snowflakes, I'd send you a blizzard. | ||
Do you have a Band-Aid? I just scraped my knee falling for you. | ||
Your presence makes my heart race, but it's a marathon I never want to finish. | ||
If beauty were a crime, you'd be serving a life sentence. | ||
Did it hurt? When you fell from the stars and landed in my world? | ||
I'm not a genie, but I can make your dreams come true. | ||
Every song I hear reminds me of you, even the ones I haven't heard yet. | ||
I never believed in magic until I saw you. | ||
If you were words on a page, you'd be the fine print. | ||
Are you made of copper and tellurium? Because you're Cu-Te. | ||
Can I follow you? Because my mom told me to follow my dreams. | ||
Your beauty could inspire poets and artists for generations. | ||
Do you believe in destiny? Because I think ours just intertwined. | ||
Are you a calculator? Because every time I look at you, things start adding up. | ||
Is your name Google? Because you have everything I've been searching for. | ||
Do you have a name, or can I call you mine? | ||
Are you a magician? Every time I look at you, everyone else disappears. | ||
Do you like basketball? Because when I saw you, my heart did a slam dunk. | ||
Are you a library book? Because I can't help but check you out. | ||
If you were a vegetable, you'd be a cutecumber. | ||
Do you have a sunburn or are you always this hot? | ||
Is your dad a boxer? Because you're a knockout. | ||
Are you a loan from a bank? Because you have my interest. | ||
Are you a campfire? Because you're hot and I want s'more. | ||
Do you have a pencil? Because I want to erase your past and write our future. | ||
Are you a parking ticket? Because you've got 'FINE' written all over you. | ||
If I could rearrange the alphabet, I would put U and I together. | ||
Are you a snowstorm? Because you make my heart race. | ||
Do you have a Band-Aid? Because I just scraped my knee falling for you. | ||
Is your dad a baker? Because you're a cutie pie. | ||
Are you a time traveler? Because I can see you in my future. | ||
Are you a candle? Because you light up my world. | ||
Are you a string? Because I can't stop finding myself attached to you. | ||
If you were a function, I'd call you every day. | ||
Are you a loop? Because I can't stop thinking about you again and again. | ||
You're the 'key' to my 'value'. | ||
If beauty were data, you'd be an overflow error. | ||
Are you a variable? Because I feel the need to declare my intentions. | ||
I think you've just incremented my heart's counter. | ||
You're the API to my application. | ||
If relationships were algorithms, ours would be a perfect match. | ||
Your presence makes my system run at optimal efficiency. | ||
If you were an exception, I'd catch you. | ||
You must be a compiler because every time I see you, my code becomes runnable. | ||
I'm not a photographer, but I can picture us in an endless loop together. | ||
In the world of binary, you are the one for me. | ||
I've got a lot of lines of code, but none as intriguing as the story of us. | ||
Forget the cloud, you've taken up all the storage in my heart. | ||
I don't need version control to know you're my final commit. | ||
Let's merge our branches and build a beautiful codebase together. | ||
Do you believe in parallel universes? Because in every one I've imagined, it's always been you and me. | ||
You must be a packet because I can't help but sniff you out in a crowd. | ||
Are you an algorithm? Because every part of me wants to solve you. | ||
Do you know JavaScript? Because you make my heart race asynchronously. | ||
If I were to traverse the nodes of my heart, every path would lead to you. | ||
In the Git of life, I'd never want to revert our commit. | ||
Are you a CSS file? Because without you, my life would be unstyled. | ||
You must be a bug, because I just can't shake you off my mind. | ||
If hearts had firewalls, you'd have bypassed mine ages ago. | ||
Are you a Boolean? Because true or false, my heart points to you. | ||
In the world of objects, you are my favorite instance. | ||
If attraction were a programming language, ours would be high-level. | ||
Are you a kernel? Because my heart feels an urge to dive deeper into you. | ||
Do you like Java? Because you've Objectified my affections. | ||
I'd never put our relationship in a try-catch block, because I never want to handle an exception with us. | ||
You're not just a semicolon; you're the statement that completes me. | ||
In the IDE of life, you've just become my favorite extension. | ||
If I were a coder, I'd refactor my life to include more of you. | ||
You're like the most elegant code I've ever seen; concise, beautiful, and effective. | ||
You’ve stolen the ASCII to my heart. | ||
You must be an exception, because I can’t handle you properly. | ||
You must be an algorithm, because you have my heart running in O(1) time. | ||
Are you a piece of code? Because you’re turning my software into hardware! | ||
Are you a compressed file? Because when I see you, my heart wants to unzip. | ||
I'm the RizzLord. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from pymongo import MongoClient | ||
import os | ||
from dotenv import load_dotenv | ||
from random import randint | ||
|
||
load_dotenv() | ||
|
||
client = MongoClient(os.getenv('MONGO_URI')) | ||
|
||
# Checks if the connection has been made, else make an error printout | ||
try: | ||
client.admin.command('ping') | ||
database = client[os.getenv('MONGO_DBNAME')] | ||
print('* Connected to MongoDB!') | ||
|
||
except Exception as err: | ||
print('* "Failed to connect to MongoDB at', os.getenv('MONGO_URI')) | ||
print('Database connection error:', err) | ||
|
||
collection = database['lines'] | ||
|
||
size = len(collection.find_one({})["lines"]) | ||
random_number = randint(0, size - 1) | ||
|
||
line = collection.find_one({})["lines"][random_number] | ||
|
||
print(line) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
import pathlib | ||
|
||
PROJECT_ROOT = f"{pathlib.Path(__file__).parent.resolve()}/../.." | ||
|
||
file_lines = [] | ||
|
||
with open(f'{PROJECT_ROOT}/src/data/lines.txt', 'r') as file: | ||
file_lines = file.readlines() | ||
|
||
d = { | ||
'lines': [] | ||
} | ||
|
||
for line in file_lines: | ||
d['lines'].append(line) | ||
|
||
with open(f'{PROJECT_ROOT}/src/data/lines.json', 'w') as file: | ||
json.dump(d, file) | ||
|
||
# with open('data/lines.json', 'r') as file: | ||
# data = json.load(file) | ||
|
||
# for line in data['lines']: | ||
# print(line) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from pymongo import MongoClient | ||
import os | ||
from dotenv import load_dotenv | ||
import json | ||
import pathlib | ||
|
||
load_dotenv() | ||
|
||
PROJECT_ROOT = f"{pathlib.Path(__file__).parent.resolve()}/../.." | ||
|
||
# Establish a database connection with the MONGO_URI (MongoDB Atlas connection) | ||
client = MongoClient(os.getenv('MONGO_URI')) | ||
|
||
# Checks if the connection has been made, else make an error printout | ||
try: | ||
client.admin.command('ping') | ||
database = client[os.getenv('MONGO_DBNAME')] | ||
print('* Connected to MongoDB!') | ||
|
||
except Exception as err: | ||
print('* "Failed to connect to MongoDB at', os.getenv('MONGO_URI')) | ||
print('Database connection error:', err) | ||
|
||
lines = [] | ||
|
||
with open(f'{PROJECT_ROOT}/src/data/lines.json', 'r') as file: | ||
data = json.load(file) | ||
lines = data['lines'] | ||
|
||
collection = database['lines'] | ||
|
||
collection.insert_one({ | ||
'lines': lines | ||
}) | ||
|
||
client.close() |