-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgithubScraper.py
174 lines (139 loc) · 6.51 KB
/
githubScraper.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import requests
import os
from bs4 import BeautifulSoup
from supabase import create_client, Client
from dotenv import load_dotenv
load_dotenv()
url: str = os.getenv("NEXT_PUBLIC_SUPABASE_URL")
key: str = os.getenv("NEXT_PUBLIC_SERVICE_ROLE_KEY")
supabase: Client = create_client(url, key)
print("Starting Github scrape...")
current_database = supabase.table('posts').select('*').execute().data
job_post_data = []
def githubScraper(repoLink, repoName):
githubInternships = requests.get(repoLink)
soup = BeautifulSoup(githubInternships.text, features="html.parser")
for internship in soup.select("article table tbody tr"):
internship_details = internship.find_all("td")
date = internship_details[4].string
links = internship_details[3].find_all("a")
if(len(links) > 0):
job_link_exists = any(links[0].get("href") == item.get('job_link') for item in current_database)
if(not job_link_exists):
job_post = {}
try:
job_post["job_link"] = links[0].get("href")
except:
job_post["job_link"] = ""
try:
job_post["job_role"] = internship_details[1].string
except:
job_post["job_role"] = ""
try:
job_post["company_name"] = internship_details[0].string
if(job_post["company_name"] == "↳" and len(job_post_data) > 0):
job_post["company_name"] = job_post_data[-1]["company_name"]
except:
job_post["company_name"] = ""
try:
job_post["job_type"] = ""
except:
job_post["job_type"] = ""
try:
job_post["source"] = repoName
except:
job_post["source"] = ""
details_element = internship_details[2].find("details")
if details_element:
summary_element = details_element.find("summary")
if summary_element:
text_after_summary = "\n".join([str(sibling) for sibling in summary_element.next_siblings if sibling.name is None])
try:
job_post["location"] = text_after_summary
except:
job_post["location"] = ""
else:
try:
text = internship_details[2].get_text(separator="\n")
job_post["location"] = text
except:
job_post["location"] = ""
try:
job_post["term"] = ""
except:
job_post["term"] = ""
try:
job_post["date"] = date
except:
job_post["date"] = ""
job_post_data.append(job_post)
def githubOffSeasonScraper(repoLink, repoName):
githubInternships = requests.get(repoLink)
soup = BeautifulSoup(githubInternships.text, features="html.parser")
for internship in soup.select("article table tbody tr"):
internship_details = internship.find_all("td")
date = internship_details[5].string
links = internship_details[4].find_all("a")
if(len(links) > 0):
job_link_exists = any(links[0].get("href") == item.get('job_link') for item in current_database)
if(not job_link_exists):
job_post = {}
try:
job_post["job_link"] = links[0].get("href")
except:
job_post["job_link"] = ""
try:
job_post["job_role"] = internship_details[1].string
except:
job_post["job_role"] = ""
try:
job_post["company_name"] = internship_details[0].string
if(job_post["company_name"] == "↳" and len(job_post_data) > 0):
job_post["company_name"] = job_post_data[-1]["company_name"]
except:
job_post["company_name"] = ""
try:
job_post["job_type"] = ""
except:
job_post["job_type"] = ""
try:
job_post["source"] = repoName
except:
job_post["source"] = ""
details_element = internship_details[2].find("details")
if details_element:
summary_element = details_element.find("summary")
if summary_element:
text_after_summary = "\n".join([str(sibling) for sibling in summary_element.next_siblings if sibling.name is None])
try:
job_post["location"] = text_after_summary
except:
job_post["location"] = ""
else:
try:
text = internship_details[2].get_text(separator="\n")
job_post["location"] = text
except:
job_post["location"] = ""
try:
text = internship_details[3].get_text(separator="\n")
job_post["term"] = text
except:
job_post["term"] = ""
if(repoName == "PittCSC Off-Season" and "2025" not in job_post["term"]):
continue
try:
job_post["date"] = date
except:
job_post["date"] = ""
job_post_data.append(job_post)
githubScraper("https://github.com/SimplifyJobs/Summer2025-Internships", "PittCSC")
githubOffSeasonScraper("https://github.com/SimplifyJobs/Summer2024-Internships/blob/dev/README-Off-Season.md", "PittCSC Off-Season")
githubScraper("https://github.com/Ouckah/Summer2025-Internships#the-list-", "Ouckah")
githubScraper("https://github.com/SimplifyJobs/New-Grad-Positions", "PittCSC New Grad")
print(job_post_data)
for job_post in job_post_data:
try:
data, count = supabase.table('posts').insert(job_post).execute()
except Exception as e:
print(f"Error inserting job post: {e}")