forked from peviitor-ro/Scrapers-UI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrapy.py
More file actions
293 lines (261 loc) · 10.5 KB
/
scrapy.py
File metadata and controls
293 lines (261 loc) · 10.5 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import requests
import os
import json
import re
# curent path
path = os.getcwd()
# this folders will be excluded
exclude = [
'',
'a',
'l',
'website',
'update',
'setup',
'script',
'__pycache__',
'main',
'osfdigital',
'000',
'test',
'smarttech'
]
# scrapers urls
urls = [
'https://dev.laurentiumarian.ro/scraper/Scrapy_peviitor_jobs/'
]
# make a request to get the scrapers
def get_scrapers(url):
"""Returns a list of scrapers."""
response = requests.get(url)
return response.json()
# make a request to get the logos
def get_logos():
"""Returns a list of logos."""
url = 'https://api.peviitor.ro/v1/logo/'
response = requests.get(url)
obj = response.json().get('companies')
data = {}
for company in obj:
name = company.get('name').lower()
data[name] = company.get('logo')
return data
# list of new companies for scrapers.js
json_file = []
# get the logos
logos = get_logos()
# loop through the urls
for url in urls:
# get the data
data = get_scrapers(url)[1].items()
# identify the extensions
extensions = {
"py": "Python",
"js": "JavaScript",
}
# loop through the data
for key, value in data:
company = key.lower().split('_')[0]
# html template
html = f'''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../../css/scraper.css" />
<title></title>
</head>
<body>
<div class="header">
<a href="/">
<div class="logo">
<h3><i>Scraper-UI.</i></h3>
<img alt="logo" height="30" src="https://peviitor.ro/static/media/peviitor_logo.df4cd2d4b04f25a93757bb59b397e656.svg" width="100"/>
</div>
</a>
<div class="nav-links">
<a href="https://firme.peviitor.ro/" target="_blank">Firme PeViitor</a>
<a href="../../doc.html">Documentation</a>
</div>
</div>
<!-- Start Section Alert -->
<div class="alertPopUp active">
<div class="alertPopUp-content">
<img alt="Check" class="alert-img" id="image-alert" src="" />
<div class="message">
<span class="alert-text-1"> </span>
<span class="alert-text-2"> </span>
</div>
</div>
<p class="close">X</p>
<div class="progress active"></div>
</div>
<!-- End Section Alert -->
<section class="company">
<div class="company-container">
<div class="flip-card-container">
<div class="flip-card">
<div class="box">
<img alt="{company.lower()}" src="{logos.get(company.lower())}" />
</div>
<div class="box2">
<a href="#" target="_blank">
Careers
</a>
<a href="#" target="_blank">
Targetare.ro
</a>
</div>
</div>
</div>
<div class="chart-container">
<canvas id="Chart"> </canvas>
</div>
</div>
</section>
<div class="container-details">
<div class="scraper-details">
<div class="details">
<h5>Company</h5>
<p id="company"></p>
</div>
<div class="hr"></div>
<div class="details">
<h5>Status</h5>
<p id="status">Uknown</p>
</div>
<div class="hr"></div>
<div class="details">
<h5>Jobs</h5>
<p id="jobs">Uknown</p>
</div>
<div class="hr"></div>
<div class="details">
<h5>Last Update</h5>
<p id="last-update">Uknown</p>
</div>
<div class="hr"></div>
<div class="details">
<h5>
Scraper
</h5>
<p id="scraper-lg">
{extensions.get(value.split(".")[-1])}
</p>
</div>
<div class="hr"></div>
<div class="details">
<h5>Contributors</h5>
<div id="contributors"></div>
</div>
<div class="hr"></div>
<div class="details">
<h5>Testers</h5>
<div id="testers"></div>
</div>
</div>
<div class="functionality">
<button>
<div>Run Scraper</div>
<svg
xmlns="http://www.w3.org/2000/svg"
width="16px"
height="16px"
viewbox="0 0 16 16"
fill="white"
class="bi bi-gear"
>
<path
d="M8 4.754a3.246 3.246 0 1 0 0 6.492 3.246 3.246 0 0 0 0-6.492zM5.754 8a2.246 2.246 0 1 1 4.492 0 2.246 2.246 0 0 1-4.492 0z"
/>
<path
d="M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0l-.094.319a.873.873 0 0 1-1.255.52l-.292-.16c-1.64-.892-3.433.902-2.54 2.541l.159.292a.873.873 0 0 1-.52 1.255l-.319.094c-1.79.527-1.79 3.065 0 3.592l.319.094a.873.873 0 0 1 .52 1.255l-.16.292c-.892 1.64.901 3.434 2.541 2.54l.292-.159a.873.873 0 0 1 1.255.52l.094.319c.527 1.79 3.065 1.79 3.592 0l.094-.319a.873.873 0 0 1 1.255-.52l.292.16c1.64.893 3.434-.902 2.54-2.541l-.159-.292a.873.873 0 0 1 .52-1.255l.319-.094c1.79-.527 1.79-3.065 0-3.592l-.319-.094a.873.873 0 0 1-.52-1.255l.16-.292c.893-1.64-.902-3.433-2.541-2.54l-.292.159a.873.873 0 0 1-1.255-.52l-.094-.319zm-2.633.283c.246-.835 1.428-.835 1.674 0l.094.319a1.873 1.873 0 0 0 2.693 1.115l.291-.16c.764-.415 1.6.42 1.184 1.185l-.159.292a1.873 1.873 0 0 0 1.116 2.692l.318.094c.835.246.835 1.428 0 1.674l-.319.094a1.873 1.873 0 0 0-1.115 2.693l.16.291c.415.764-.42 1.6-1.185 1.184l-.291-.159a1.873 1.873 0 0 0-2.693 1.116l-.094.318c-.246.835-1.428.835-1.674 0l-.094-.319a1.873 1.873 0 0 0-2.692-1.115l-.292.16c-.764.415-1.6-.42-1.184-1.185l.159-.291A1.873 1.873 0 0 0 1.945 8.93l-.319-.094c-.835-.246-.835-1.428 0-1.674l.319-.094A1.873 1.873 0 0 0 3.06 4.377l-.16-.292c-.415-.764.42-1.6 1.185-1.184l.292.159a1.873 1.873 0 0 0 2.692-1.115l.094-.319z"
/>
</svg>
</button>
<a
href="https://peviitor.ro/rezultate?q={company}&country=Rom%C3%A2nia&page=1"
target="_blank"
class="functionality-buttons"
>See Jobs</a
>
<p class="delete-storage">Delete Local Storage</p>
<a href="https://github.com/peviitor-ro/{url.split("/")[-2]}/blob/main/JobsCrawlerProject/JobsCrawlerProject/spiders/{value}" target="_blank" class="functionality-buttons">
GitHubRepo
</a>
<a href="https://github.com/peviitor-ro/{url.split("/")[-2]}/issues" target="_blank">
Report 🐞
</a>
<a
href="https://www.google.com/url?q=https%3A%2F%2Fdiscord.gg%2Ft2aEdmR52a&sa=D&sntz=1&usg=AOvVaw2T-L7jAgzen0J-qResoTGU"
target="_blank"
class="functionality-buttons"
>
Join Discord
</a>
</div>
</div>
<div class="jobs"></div>
<div class="skeleton-jobs">
<template id="card-template">
<div class="skeleton-job">
<div>
<p class="skeleton-job-title"></p>
<p class="skeleton-job-company"></p>
<p class="skeleton-job-location"></p>
</div>
<div class="skeleton-job-post">
<p></p>
</div>
</div>
</template>
</div>
<div class="console hidden">
<button class="close-console" onclick="closeConsole()">x</button>
<div class="console-content"></div>
</div>
<div onclick="toTop()" class="button-to-top-parent">
<div class="button-to-top">⇧</div>
</div>
<script>
// De Modificat
const apiObj = {{
file: "{key}",
url: "{url}",
dataSetUrl: "{url.replace('scraper', 'dataset')}{value}/",
}};
// ##########################################
</script>
<script src="../../js/countries.js"></script>
<script src="../../js/counties.js"></script>
<script src="../../js/scraper.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
<script src="../../js/chart.js"></script>
</body>
</html>
'''
# Create folder
try:
# if the folder exists, continue
folder = company.lower()
if folder not in exclude:
os.mkdir(f'{path}/src/{company.lower()}')
with open(f'{path}/src/{company.lower()}/index.html', 'w',encoding='utf-8') as f:
f.write(html)
json_file.append({"name": company})
print(f'Folder {folder} created.')
except FileExistsError:
continue
# set the pattern
pattern = re.compile(r'let scrapers = \[(.*?)\];', re.DOTALL)
# get the content of the file
with open('js/scrapers.js', 'r') as f:
content = f.read()
# find the pattern
result = '[' + pattern.search(content).group(1).replace('name:', '"name":').replace(' ', '').replace('\n', '') + ']'
# convert to dict
result = json.loads(result.replace('",}', '"}').replace('},]', '}]')) + json_file
# add new results in file
with open('js/scrapers.js', 'w') as f:
f.write(f'let scrapers = {json.dumps(result, indent=4)};')