本文共508字,预计阅读需要2分钟
今日阅读:
- 区块链黑暗森林自救手册 小记:本来是想找关于比特币冷钱包的本地构建方案,结果发现一个非常详尽的区块链安全知识手册,没看完。
- obsidian和Git连用实现版本控制 小记:简单易懂的教程,不过我还没去实践。因为考虑到安全性,我打算使用本地电脑去搭建一个Git服务,这又挖下一个大坑。
今日软件:
号称“最懂程序员的新一代 AI 搜索引擎”,数据参考来源于高质量的社区和官方文档,实际测试下来也确实不错。
虽然有了YOU和谷歌搜索总结这种形式,但是这种特定领域的专用Ai搜索感觉还是非常有必要的。
只是不知道他这个搜索算力可以支撑免费多久。
今日代码:
主要是逆向抓取了一下BILIBILI游戏中心,统计了一下在库游戏的下载量,存活率等维度。
统计结果比我想象中活的还要多,实际看了下有很多其实还没开服就死掉了,所以没有被标记为停服 。
import requests
import csv
import threading
# 创建一个线程锁
lock = threading.Lock()
def fetch_data(thread_id, start, end, csv_filename):
for i in range(start, end + 1):
url = f"https://line1-h5-pc-api.biligame.com/game/detail/gameinfo?game_base_id={i}"
try:
response = requests.get(url)
if response.status_code == 200:
if response.json()['data']['title']:
data = response.json().get('data', {})
title = data.get('title', '无标题')
operator_name = data.get('operator_name', '无信息')
developer_name = data.get('developer_name', '无信息')
download_count = data.get('download_count', '无信息')
is_ios_online = data.get('is_ios_online', False)
is_ios_online_text = "有" if is_ios_online else "无"
is_pc_online = data.get('is_pc_online', False)
is_pc_online_text = "有" if is_pc_online else "无"
is_android_online = data.get('is_android_online', False)
is_android_online_text = "有" if is_android_online else "无"
download_status = data.get('download_status', False)
download_status_text = "是" if download_status else "否"
# 使用线程锁来同步写入操作
with lock:
with open(csv_filename, 'a', newline='', encoding='utf-8-sig') as file:
writer = csv.writer(file)
writer.writerow([i, title, operator_name, developer_name, download_count, is_android_online_text, is_ios_online_text, is_pc_online_text, download_status_text])
print(f"ID {i}: " + title)
else:
print(f"ID {i}: response.status_code")
except Exception as e:
print(f"ID {i}: Error occurred - {e}")
def start_threads(num_threads, start_id, end_id, csv_filename):
# 在所有线程开始之前,创建文件并写入标题行
with open(csv_filename, 'w', newline='', encoding='utf-8-sig') as file:
writer = csv.writer(file)
writer.writerow(['ID', '标题', '发行商', '开发商', '下载量', '安卓端', 'IOS端', 'PC端', '仍在运营'])
total_ids = end_id - start_id + 1
ids_per_thread = total_ids // num_threads
threads = []
for t in range(num_threads):
thread_start_id = start_id + t * ids_per_thread
thread_end_id = thread_start_id + ids_per_thread - 1
if t == num_threads - 1:
thread_end_id = end_id
thread = threading.Thread(target=fetch_data, args=(t, thread_start_id, thread_end_id, csv_filename))
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
# 启动线程
num_threads = 20 # 线程数
start_id = 101149 # 起始ID
end_id = 111212 # 结束ID
csv_filename = 'BILIBILI游戏数据统计231218_101149_111212.csv'
start_threads(num_threads, start_id, end_id, csv_filename)
今日见闻:
没什么。
今日废话:
黑镜第二集《一千五百万的价值》,极致的压抑。没什么是真实的,除了活着。
其中最有意思的是哪个饮料,都让人以为是喝了饮料人心才变,结果赤裸的向我们展示了什么是本性和欲。