What is Nostr?
/ 阿白
npub1ccj…mr09
2023-05-14 15:24:07

阿白 on Nostr: ...

从2987个中文用户找出活跃的用户(以1个月内还有发帖子为判断)

需要一个Python脚本来处理数据, 作为参数输入的nostr_id_public_keys_china_users.txt 文件的每一行为一个公钥id,需要读取每一行公钥id作为参数,比如 db11b32009d914dd76bd904b8a636627d1d9043f2a4f9ecaf6aaf85d05c5f7af ,拼接命令为 echo '["REQ", "cn", {"authors": ["db11b32009d914dd76bd904b8a636627d1d9043f2a4f9ecaf6aaf85d05c5f7af"] , "kinds": [1], "limit": 1}]'|nostcat wss://offchain.pub|jq '.[2].created_at' , 执行命令将获得的时间戳结果跟当前时间比较 ,如果小于30天则将公钥id 添加输出到 nostr_crawler_live_zh_users_list.txt 文件里,并依次循环执行。

import subprocess
import time

input_file = "nostr_id_public_keys_china_users.txt"
output_file = "nostr_crawler_live_zh_users_list.txt"

def get_timestamp(public_key):
cmd = f'echo \'["REQ", "cn", {{"authors": ["{public_key}"] , "kinds": [1], "limit": 1}}]\'|nostcat wss://offchain.pub|jq \'.[2].created_at\''
result = subprocess.run(cmd, stdout=subprocess.PIPE, shell=True, text=True)
try:
return int(result.stdout.strip())
except ValueError:
return None

def is_within_30_days(timestamp):
current_time = int(time.time())
return (current_time - timestamp) < (30 * 24 * 60 * 60)

with open(input_file, 'r') as f_in, open(output_file, 'w') as f_out:
for line in f_in:
public_key = line.strip()
timestamp = get_timestamp(public_key)

if timestamp is not None and is_within_30_days(timestamp):
f_out.write(public_key + '\n')
Author Public Key
npub1ccjq3jwtlhwv358r0g6xglxhc5zg9f9sex63xxl62ut6fl5efu4sysmr09