forked from TiernanJesrani/swe-application-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo.py
132 lines (101 loc) · 3.39 KB
/
mongo.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
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
129
130
131
132
from datetime import datetime, timedelta # This will be needed later
import os
import pandas as pd
from dotenv import load_dotenv
from pymongo import MongoClient
from jobs import scrape_url, convert_data_entry, master_df, not_in_db
MONGODB_URI = os.environ['MONGODB_URI']
def apply(link):
listings_collection = open_collection("app_listings")
applied_collection = open_collection("app_applied")
listings_collection.find_one_and_update(
{ "link" : link },
{ "$set": {"hidden" : True} }
)
listing = listings_collection.find_one(
{ "link" : link }
)
data = {
"company": listing["company"],
"role": listing["role"],
"location": listing["location"],
"link": listing["link"],
"date": datetime.now(),
"status": "Applied"
}
applied_collection.insert_one(data)
def open_collection(collection_name):
load_dotenv()
# Connect to your MongoDB cluster:
client = MongoClient(MONGODB_URI)
# Select the database you want to use:
db = client['dashboard']
collection = db[collection_name]
return collection
# pulls data from the database and converts it to a pandas DF
def fetch_data_to_dataframe(collection_name):
collection = open_collection(collection_name)
if collection_name == 'app_listings':
data = list(collection.find({
'hidden': False
}))
else:
data = list(collection.find())
df = pd.DataFrame(data)
return df
def update_status_in_database(new_status, link):
collection = open_collection('app_applied')
# Update the status
collection.find_one_and_update(
{ "link" : link },
{ "$set": {"status" : new_status} }
)
def enter_leetcode_data(title):
lc_collection = open_collection("lc_cache")
if lc_collection.count_documents({"title": title}) == 0:
lc_collection.insert_one(
{"title":title}
)
def get_sankey_vals():
applied_collection = open_collection("app_applied")
all_applications = applied_collection.find()
["Applied", "No Answer", "Rejected", "Interviews", "Offers", "Accepted"]
applied = 0
no_answer = 0
rejected = 0
interviews = 0
offers = 0
accepted = 0
for application in all_applications:
if application['status'] == 'Applied':
applied += 1
elif application['status'] == 'No Answer':
applied += 1
no_answer += 1
elif application['status'] == 'Rejected':
applied += 1
rejected += 1
elif application['status'] == 'Interview':
applied += 1
interviews += 1
elif application['status'] == 'Offer':
applied += 1
interviews += 1
offers += 1
elif application['status'] == 'Accepted':
applied += 1
interviews += 1
offers += 1
accepted += 1
return [no_answer, rejected, interviews, offers, accepted]
# apps = open_collection("app_listings")
# print ("\n\n\n\nmongo.py: master_df")
# print(master_df)
# for index, row in master_df.iterrows():
# if not_in_db(row['Link'], apps):
# apps.insert_one(convert_data_entry(row))
# apply("http://redirect.cvrve.me/e36fd103a077bcbda08a?utm_source=ouckah")
def main():
print(fetch_data_to_dataframe('app_listings'))
if __name__=="__main__":
main()