Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MBD_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s1871242
MBD_project
Commits
3fef17dc
Commit
3fef17dc
authored
4 years ago
by
s2017873
Browse files
Options
Downloads
Patches
Plain Diff
Uploaded get_indeces.py
parent
63d66e5a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
get_indeces.py
+64
-0
64 additions, 0 deletions
get_indeces.py
with
64 additions
and
0 deletions
get_indeces.py
0 → 100644
+
64
−
0
View file @
3fef17dc
import
pickle
import
requests
import
json
import
csv
import
time
import
multiprocessing
as
mp
url_list
=
[]
cc
=
"
http://index.commoncrawl.org/CC-MAIN-2020-50-index
"
with
open
(
"
/home/s2017873/top-1m.csv
"
)
as
csv_file
:
csv_reader
=
csv
.
reader
(
csv_file
,
delimiter
=
'
,
'
)
i
=
0
for
row
in
csv_reader
:
i
+=
1
url_list
.
append
(
row
[
1
])
def
get_indeces_from_url
(
tup
):
url
,
queue
=
tup
get_string
=
cc
+
"
/?url=
"
+
url
+
"
/&output=json
"
code
=
0
while
code
!=
200
:
r
=
requests
.
get
(
get_string
)
code
=
r
.
status_code
if
r
.
status_code
==
200
:
json_obj_list
=
r
.
text
.
split
(
"
\n
"
)
json_obj_list
.
pop
()
l
=
set
()
for
json_obj
in
json_obj_list
:
j
=
json
.
loads
(
json_obj
)
if
'
/warc/
'
in
j
[
'
filename
'
]:
l
.
add
(
j
[
'
filename
'
])
queue
.
put
(
l
)
break
elif
r
.
status_code
==
404
:
queue
.
put
(
set
())
break
elif
r
.
status_code
==
503
:
time
.
sleep
(
0.5
)
else
:
print
(
r
.
status_code
)
time
.
sleep
(
0.5
)
# Partition urls to 1000 workers that each do 1000 urls
def
write_to_urls
(
queue
):
url_set
=
set
()
for
i
in
range
(
top_k
):
new_urls
=
queue
.
get
()
print
(
"
{0} / {1}
"
.
format
(
i
,
top_k
))
to_write
=
new_urls
.
difference
(
url_set
)
url_set
=
url_set
.
union
(
new_urls
)
with
open
(
"
url_file.txt
"
,
"
a
"
)
as
f
:
for
url
in
to_write
:
f
.
write
(
url
+
"
\n
"
)
print
(
"
Done
"
)
p
=
mp
.
Pool
(
4
)
m
=
mp
.
Manager
()
q
=
m
.
Queue
()
top_k
=
100
url_list
=
url_list
[:
top_k
]
url_list
=
map
(
lambda
url
:
(
url
,
q
),
url_list
)
writer
=
mp
.
Process
(
target
=
write_to_urls
,
args
=
(
q
,
))
writer
.
start
()
p
.
map
(
get_indeces_from_url
,
url_list
)
p
.
join
()
writer
.
join
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment