Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
Project3
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
20200203063
Project3
Commits
4d476bb4
Commit
4d476bb4
authored
Sep 01, 2020
by
20200203063
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
17255091
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
gen_id2business.py
+34
-0
No files found.
gen_id2business.py
0 → 100644
View file @
4d476bb4
# encoding: utf-8
import
json
import
pickle
import
os
business_path
=
"data/business.json"
save_id2business_path
=
"model/id2business.pkl"
def
load_id2business
():
id2business
=
None
if
not
os
.
path
.
exists
(
save_id2business_path
):
id2business
=
dict
()
with
open
(
business_path
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
for
line
in
f
.
readlines
():
if
len
(
line
.
strip
())
==
0
:
continue
ele
=
json
.
loads
(
line
.
strip
())
business_id
=
ele
[
"business_id"
]
if
ele
[
"business_id"
]
in
id2business
:
print
(
"{} duplicated"
.
format
(
str
(
business_id
)))
continue
id2business
[
business_id
]
=
ele
with
open
(
save_id2business_path
,
'wb'
)
as
f
:
pickle
.
dump
(
id2business
,
f
)
else
:
with
open
(
save_id2business_path
,
'rb'
)
as
f
:
id2business
=
pickle
.
load
(
f
)
return
id2business
id2business
=
load_id2business
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment