Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
network-assets-reptile
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyang
network-assets-reptile
Commits
6c528f44
Commit
6c528f44
authored
Aug 09, 2023
by
liyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:facebook debug
parent
9126b716
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
312 deletions
+19
-312
output.json
output.json
+0
-238
test.py
test.py
+10
-68
index.py
utils/index.py
+9
-6
No files found.
output.json
deleted
100644 → 0
View file @
9126b716
This source diff could not be displayed because it is too large. You can
view the blob
instead.
test.py
View file @
6c528f44
import
mysql.connector
import
json
import
json
# 连接到数据库
# 读取JSON文件内容
db_config
=
{
with
open
(
'./staticLogicEdgeInfo.json'
,
'r'
)
as
file
:
"host"
:
"8.142.151.250"
,
json_data
=
file
.
read
()
"user"
:
"script"
,
"password"
:
"changfA123$"
,
"database"
:
"network_assets"
}
connection
=
mysql
.
connector
.
connect
(
**
db_config
)
# 解析JSON内容
cursor
=
connection
.
cursor
(
)
parsed_data
=
json
.
loads
(
json_data
)
#
设置 group_concat_max_len,设置返回字符串长度限制为 1,000,000 字符
#
将JSON内容转换为一行
c
ursor
.
execute
(
"SET SESSION group_concat_max_len = 1000000"
)
c
ompressed_json
=
json
.
dumps
(
parsed_data
,
separators
=
(
','
,
':'
)
)
# 执行SQL查询语句
# 将压缩后的内容写入文件
sql_query
=
"""
with
open
(
'staticLogicEdgeInfo.json'
,
'w'
)
as
file
:
SELECT
file
.
write
(
compressed_json
)
country_code AS countryCode,
\ No newline at end of file
CONCAT(
'{"countryCode": "', REPLACE(country_code, '"', '
\\
"'), '", ',
'"ASInfoList": [',
GROUP_CONCAT(
CONCAT(
'{"topology": false, "ASType": "', REPLACE(type, '"', '
\\
"'),
'", "linkedNumber": ', connect_degree,
', "ASNumber": ', as_number,
', "ASDegrees": ', transmit_degree,
', "countryCode": "', REPLACE(country_code, '"', '
\\
"'), '"}'
)
SEPARATOR ', '
),
'], ',
'"countryName": "', REPLACE(country, '"', '
\\
"'), '"}'
) AS result
FROM as_info
GROUP BY country_code, country
"""
cursor
.
execute
(
sql_query
)
query_result
=
cursor
.
fetchall
()
# 关闭数据库连接
cursor
.
close
()
connection
.
close
()
# 将查询结果转换为正确格式的数据
formatted_result
=
[]
for
row
in
query_result
:
country_code
=
row
[
0
]
result_data
=
row
[
1
]
# 转换非字符串类型为字符串
if
isinstance
(
result_data
,
(
list
,
tuple
)):
result_data
=
[
str
(
item
)
for
item
in
result_data
]
# # 构建 JSON 数据
# json_data = {
# "countryCode": country_code,
# "ASInfoList": result_data
# }
data
=
json
.
loads
(
result_data
)
formatted_result
.
append
(
data
)
# 将结果导出到 JSON 文件
output_file_path
=
"./output.json"
with
open
(
output_file_path
,
"w"
,
encoding
=
"utf-8"
)
as
json_file
:
json
.
dump
(
formatted_result
,
json_file
,
indent
=
4
,
ensure_ascii
=
False
)
print
(
f
"查询结果已导出到 {output_file_path}"
)
utils/index.py
View file @
6c528f44
...
@@ -102,13 +102,16 @@ def parse_time_string(time_str):
...
@@ -102,13 +102,16 @@ def parse_time_string(time_str):
new_time_str
=
time_str
.
replace
(
"年"
,
"/"
)
.
replace
(
"月"
,
"/"
)
.
replace
(
"日"
,
""
)
new_time_str
=
time_str
.
replace
(
"年"
,
"/"
)
.
replace
(
"月"
,
"/"
)
.
replace
(
"日"
,
""
)
dt_object
=
datetime
.
datetime
.
strptime
(
new_time_str
,
'
%
Y/
%
m/
%
d'
)
dt_object
=
datetime
.
datetime
.
strptime
(
new_time_str
,
'
%
Y/
%
m/
%
d'
)
else
:
else
:
# new_time_str = time_str.replace("月", "/").replace("日", "")
# dt_object = datetime.datetime.strptime(new_time_str, '%m/%d')
current_year
=
datetime
.
datetime
.
now
()
.
year
current_year
=
datetime
.
datetime
.
now
()
.
year
new_time_str
=
time_str
.
replace
(
"月"
,
"/"
)
.
replace
(
"日"
,
f
"/{current_year} "
)
if
":"
in
time_str
:
dt_object
=
datetime
.
datetime
.
strptime
(
new_time_str
,
'
%
m/
%
d/
%
Y
%
H:
%
M'
)
new_time_str
=
f
"{current_year}/"
+
time_str
.
replace
(
"月"
,
"/"
)
.
replace
(
"日"
,
" "
)
dt_object
=
datetime
.
datetime
.
strptime
(
new_time_str
,
'
%
Y/
%
m/
%
d
%
H:
%
M'
)
else
:
new_time_str
=
f
"{current_year}/"
+
time_str
.
replace
(
"月"
,
"/"
)
.
replace
(
"日"
,
""
)
dt_object
=
datetime
.
datetime
.
strptime
(
new_time_str
,
'
%
Y/
%
m/
%
d'
)
return
dt_object
.
timestamp
()
timestamp
=
dt_object
.
timestamp
()
return
timestamp
def
parse_ltn_time_string
(
time_str
):
def
parse_ltn_time_string
(
time_str
):
...
...
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