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
63d66e5a
Commit
63d66e5a
authored
4 years ago
by
s2017873
Browse files
Options
Downloads
Patches
Plain Diff
Delete get_url_ip_from_way.py
parent
f2906915
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_url_ip_from_way.py
+0
-47
0 additions, 47 deletions
get_url_ip_from_way.py
with
0 additions
and
47 deletions
get_url_ip_from_way.py
deleted
100644 → 0
+
0
−
47
View file @
f2906915
import
pyspark
from
warcio.archiveiterator
import
ArchiveIterator
import
warc
import
esutil
import
json
from
pyspark.sql
import
SparkSession
from
pyspark
import
SparkFiles
,
SparkConf
conf
=
SparkConf
()
conf
.
appName
=
'
master-yarn
'
spark
=
SparkSession
.
builder
.
config
(
conf
=
conf
).
getOrCreate
()
sc
=
spark
.
sparkContext
# m1_df = spark.read.csv('/user/s2017873/top-1m.csv.gz')
wat_files
=
esutil
.
hdfs
.
ls
(
'
/user/s2017873/wat_files/
'
,
False
,
False
)
def
get_records_for_path
(
path
):
result
=
[]
with
esutil
.
hdfs
.
opent
(
'
hdfs:
'
+
path
)
as
stream
:
for
record
in
ArchiveIterator
(
stream
):
if
record
.
rec_type
==
'
metadata
'
:
# wat_json = spark.read.json(record.content_stream().read()).asDict()
wat_json
=
json
.
loads
(
record
.
content_stream
().
read
())
if
"
WARC-IP-Address
"
in
wat_json
[
"
Envelope
"
][
"
WARC-Header-Metadata
"
]:
ip
=
wat_json
[
"
Envelope
"
][
"
WARC-Header-Metadata
"
][
"
WARC-IP-Address
"
]
url
=
wat_json
[
"
Envelope
"
][
"
WARC-Header-Metadata
"
][
"
WARC-Target-URI
"
]
no_https
=
url
.
split
(
"
//
"
)[
1
]
if
not
(
'
/
'
in
no_https
):
result
.
append
((
no_https
,
ip
))
return
result
rdd
=
sc
.
parallelize
(
wat_files
)
new_rdd
=
rdd
.
flatMap
(
lambda
path
:
get_records_for_path
(
path
))
# m1_rdd = m1_df.rdd.map(lambda (rank, url) : (url, rank))
#with open("/home/s2017873/log4.txt", "w+") as f:
# f.write(str(new_rdd.take(1)))
# final_rdd = m1_rdd.leftOuterJoin(new_rdd)
# joined_rdd = m1_rdd.join(new_rdd).take(1)
#with open("/home/s2017873/log4.txt", 'w+') as f:
# first = final_rdd.take(1)
# f.write(str(first))
new_rdd
.
saveAsTextFile
(
"
hdfs:///user/s2017873/FINAL
"
)
# joined_rdd.saveAsTextFile("output_folder")
# final_rdd.saveAsTextFile("url_rank_ip.csv")
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