Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
A
aidso-data
Project
Project
Details
Activity
Releases
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
Yaowentong
aidso-data
Commits
15f53e7f
Commit
15f53e7f
authored
Jun 26, 2026
by
Yaowentong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
小红书时间修复
parent
f4a87988
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
114 deletions
+93
-114
spider_save_tos.py
aidso_geo/models/spider_save_tos.py
+57
-2
xiaohongshu_android_data_process.py
aidso_geo/models/xiaohongshu_android_data_process.py
+33
-3
robot_utils.py
aidso_geo/utils/robot_utils.py
+3
-109
No files found.
aidso_geo/models/spider_save_tos.py
View file @
15f53e7f
import
json
import
os
import
re
from
datetime
import
datetime
,
timedelta
from
aidso_geo.utils.tos_utils
import
put_string_to_tos
from
aidso_geo.utils
import
bh_utils
from
aidso_geo.utils
import
url_utils
...
...
@@ -285,10 +286,62 @@ def yuanbao_android_process_quote(url_list):
quto_list
.
append
(
raw_data
)
return
quto_list
def
parse_date_to_ymd
(
value
,
now
=
None
):
if
now
is
None
:
now
=
datetime
.
now
()
if
value
is
None
:
return
""
value
=
str
(
value
)
.
strip
()
if
not
value
or
value
in
(
"空"
,
"null"
,
"None"
,
"-"
):
return
""
# 2026-05-30
if
re
.
fullmatch
(
r"\d{4}-\d{1,2}-\d{1,2}"
,
value
):
dt
=
datetime
.
strptime
(
value
,
"
%
Y-
%
m-
%
d"
)
return
dt
.
strftime
(
"
%
Y-
%
m-
%
d"
)
# 05-30,默认补当前年份
if
re
.
fullmatch
(
r"\d{1,2}-\d{1,2}"
,
value
):
year
=
now
.
year
dt
=
datetime
.
strptime
(
f
"{year}-{value}"
,
"
%
Y-
%
m-
%
d"
)
return
dt
.
strftime
(
"
%
Y-
%
m-
%
d"
)
# 1天前 / 10天前
match
=
re
.
fullmatch
(
r"(\d+)天前"
,
value
)
if
match
:
days
=
int
(
match
.
group
(
1
))
dt
=
now
-
timedelta
(
days
=
days
)
return
dt
.
strftime
(
"
%
Y-
%
m-
%
d"
)
# 10小时前 / 1小时前
match
=
re
.
fullmatch
(
r"(\d+)小时前"
,
value
)
if
match
:
hours
=
int
(
match
.
group
(
1
))
dt
=
now
-
timedelta
(
hours
=
hours
)
return
dt
.
strftime
(
"
%
Y-
%
m-
%
d"
)
# 今天
if
value
==
"今天"
:
return
now
.
strftime
(
"
%
Y-
%
m-
%
d"
)
# 昨天
if
value
==
"昨天"
:
return
(
now
-
timedelta
(
days
=
1
))
.
strftime
(
"
%
Y-
%
m-
%
d"
)
return
""
def
xiaohongshu_android_process_quote
(
url_list
):
quto_list
=
[]
for
index
,
item
in
enumerate
(
url_list
):
published_at
=
item
.
get
(
'time'
,
''
)
published_at
=
parse_date_to_ymd
(
published_at
)
url
=
""
id
=
item
.
get
(
'id'
)
if
id
:
...
...
@@ -298,7 +351,7 @@ def xiaohongshu_android_process_quote(url_list):
"title"
:
item
.
get
(
'title'
,
''
),
"snippet"
:
item
.
get
(
'content'
,
''
),
"index"
:
index
,
"published_at"
:
item
.
get
(
'time'
,
''
)
,
"published_at"
:
published_at
,
"site_name"
:
'小红书'
,
"site_icon"
:
'www.xiaohongshu.com'
,
}
...
...
@@ -521,3 +574,5 @@ def process_and_save_files_ai(file_path, search_keyword, url_list, think_content
]
for
content
,
file_name
in
data_config
:
save_data_to_tos_ai
(
target_dir
,
content
,
file_name
)
# if __name__ == '__main__':
aidso_geo/models/xiaohongshu_android_data_process.py
View file @
15f53e7f
...
...
@@ -2,7 +2,7 @@ import json
import
traceback
from
aidso_geo.models
import
spider_save_tos
from
aidso_geo.utils
import
robot_utils
from
aidso_geo.utils
import
robot_utils
,
bh_utils
from
aidso_geo.utils.ai_interface
import
get_parse_sse_result
from
aidso_geo.utils.tos_utils
import
get_string_from_tos
...
...
@@ -28,6 +28,8 @@ def xiaohongshu_android_process_original_data(data):
items
=
json_content
.
get
(
'items'
)
response_content
=
base_info
.
get
(
'text'
)
url_list
=
items
if
"</complex_list>"
in
response_content
:
response_content
=
response_content
.
replace
(
'</complex_list>'
,
''
)
...
...
@@ -59,5 +61,33 @@ def xiaohongshu_android_process_original_data(data):
return
(
file_path
,
search_keyword
,
url_list
,
think_content
,
response_content
,
suggestions
)
if
__name__
==
'__main__'
:
file_path2
=
'geo/XHSA-XHSA-01-2XH12SA-X1H22SA1/XHSA/original.text'
xiaohongshu_android_process_original_data
(
file_path2
)
# file_path2 = 'geo/7ac6f0c7-988d-4c3e-a45b-f317e144b68e/XHSA/original.text'
# xiaohongshu_android_process_original_data(file_path2)
data_list
=
bh_utils
.
query_data
(
f
"select * from geo_commit_task where platform = 'XHSA' and taskId = 'aeb60818-5221-4062-820d-e4523f184d56'"
)
# # #
# # #
# # # # #
def
handle_item
(
i
):
if
i
.
get
(
'comWordsMap'
):
i
[
'comWordsMap'
]
=
json
.
loads
(
i
.
get
(
'comWordsMap'
))
if
i
.
get
(
'brandWords'
):
i
[
'brandWords'
]
=
json
.
loads
(
i
.
get
(
'brandWords'
))
if
i
.
get
(
'comWords'
):
i
[
'comWords'
]
=
json
.
loads
(
i
.
get
(
'comWords'
))
if
i
.
get
(
'keywords'
):
i
[
'keywords'
]
=
json
.
loads
(
i
.
get
(
'keywords'
))
if
i
.
get
(
'productWordsMap'
):
i
[
'productWordsMap'
]
=
json
.
loads
(
i
.
get
(
'productWordsMap'
))
print
(
i
.
get
(
'taskId'
))
return
xiaohongshu_android_process_original_data
(
i
)
# 喜欢非遗手作的看这里!周末到河北之涿州!
if
data_list
:
for
i
in
data_list
:
try
:
handle_item
(
i
)
except
Exception
as
e
:
...
aidso_geo/utils/robot_utils.py
View file @
15f53e7f
...
...
@@ -5,102 +5,8 @@ import json
from
loguru
import
logger
from
apscheduler.schedulers.blocking
import
BlockingScheduler
from
aidso_geo.config.base_config
import
init_redis
,
init_redis8
from
aidso_geo.config.base_config
import
init_redis
from
aidso_geo.utils
import
bh_utils
from
datetime
import
datetime
redis_client
=
init_redis8
()
def
safe_int
(
value
,
default
=
0
):
try
:
if
value
is
None
:
return
default
return
int
(
value
)
except
Exception
:
return
default
def
get_active_channels
():
"""
查询所有启用中的第三方 channel
"""
sql
=
"""
select channel, daily_limit, total_limit
from geo_third_token
where status = 1
"""
return
bh_utils
.
query_data
(
sql
)
or
[]
def
sync_third_usage_once
():
"""
每小时同步第三方 token 用量快照。
读取:
1. Redis hash third_geo_daily:field = channel + YYYYMMDD
2. Redis hash third_geo_total:field = channel
写入:
geo_third_usage_snapshot
"""
now
=
datetime
.
now
()
today_pt
=
now
.
strftime
(
"
%
Y
%
m
%
d"
)
sync_time
=
now
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
insertime
=
int
(
time
.
time
())
try
:
channels
=
get_active_channels
()
if
not
channels
:
logger
.
info
(
f
"[{sync_time}] sync_third_usage_once 无启用中的 channel"
)
return
# 一次性拉 Redis hash,避免用户多时频繁 hget
daily_map
=
redis_client
.
hgetall
(
"third_geo_daily"
)
or
{}
total_map
=
redis_client
.
hgetall
(
"third_geo_total"
)
or
{}
insert_rows
=
[]
for
item
in
channels
:
channel
=
str
(
item
.
get
(
"channel"
,
""
))
.
strip
()
if
not
channel
:
continue
daily_limit
=
safe_int
(
item
.
get
(
"daily_limit"
),
0
)
total_limit
=
safe_int
(
item
.
get
(
"total_limit"
),
0
)
daily_key
=
f
"{channel}{today_pt}"
today_used
=
safe_int
(
daily_map
.
get
(
daily_key
),
0
)
total_used
=
safe_int
(
total_map
.
get
(
channel
),
0
)
insert_rows
.
append
({
"channel"
:
channel
,
"pt"
:
today_pt
,
"daily_limit"
:
daily_limit
,
"total_limit"
:
total_limit
,
"today_used"
:
today_used
,
"total_used"
:
total_used
,
"today_remain"
:
max
(
daily_limit
-
today_used
,
0
),
"total_remain"
:
max
(
total_limit
-
total_used
,
0
),
"sync_time"
:
sync_time
,
"insertime"
:
insertime
})
if
not
insert_rows
:
logger
.
info
(
f
"[{sync_time}] sync_third_usage_once 无可写入数据"
)
return
ok
=
bh_utils
.
insert_data
(
"geo_third_usage_snapshot"
,
insert_rows
)
if
ok
:
logger
.
info
(
f
"[{sync_time}] sync_third_usage_once 同步成功 rows={len(insert_rows)}"
)
else
:
logger
.
error
(
f
"[{sync_time}] sync_third_usage_once 同步失败 rows={len(insert_rows)}"
)
except
Exception
as
e
:
logger
.
exception
(
f
"[{sync_time}] sync_third_usage_once 执行异常: {e}"
)
owner_map
=
{
"XHSA"
:
"崔士豪"
,
...
...
@@ -120,7 +26,7 @@ owner_map = {
platform_list
=
[
"BDAI"
,
"DB"
,
"DOUBA"
,
"DP"
,
"DPA"
,
"DYAI"
,
"KIMI"
,
"TXYB"
,
"TXYBA"
,
"TYQW"
,
"TYQWA"
,
"WXYY"
"KIMI"
,
"TXYB"
,
"TXYBA"
,
"TYQW"
,
"TYQWA"
,
"WXYY"
,
"XHSA"
]
...
...
@@ -366,21 +272,9 @@ if __name__ == '__main__':
replace_existing
=
True
)
scheduler
.
add_job
(
sync_third_usage_once
,
trigger
=
'cron'
,
minute
=
5
,
id
=
'sync_third_usage_once'
,
max_instances
=
1
,
coalesce
=
True
,
replace_existing
=
True
)
logger
.
info
(
"定时任务注册完成:"
"fail_task_send_feishu(每6小时), "
"task_queue_backlog(每小时), "
"sync_third_usage_once(每小时)"
"task_queue_backlog(每小时)"
)
scheduler
.
start
()
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