Why Nostr? What is Njump?
2023-05-11 18:35:59
in reply to

阿白 on Nostr: from selenium import webdriver from selenium.webdriver.common.by import By import ...

from selenium import webdriver
from selenium.webdriver.common.by import By
import requests
import json
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import re

def npub_to_live(driver, input_str):
# 添加显式等待,直到所需元素变得可见
wait = WebDriverWait(driver, 10)

# 等待直到 connectionState 元素的文本内容包含 "Connected"
connection_state = wait.until(
EC.visibility_of_element_located((By.ID, "connectionState"))
)
wait.until(
lambda _: "Connected" in connection_state.text
)

# 寻找hex输入框,并获取hex_key值
query_input = driver.find_element(By.ID, 'input')
query_input.clear()
query_input.send_keys(input_str)


# 点击 id 为 "send" 的按钮
send_button = driver.find_element(By.ID, 'send')
send_button.click()
time.sleep(1)

query_output = driver.find_element(By.ID, 'output')
query_output = query_output.get_attribute('value')
return query_output
def main():
with open(“nostr_id_public_keys_china_users.txt”, “r”) as f:
npub_keys = [line.strip() for line in f]

unique_followers = set()

# 创建WebDriver实例
driver = webdriver.Safari()

url = 'https://nostr.info/relayr/';
driver.get(url)

# 添加显式等待,直到所需元素变得可见
wait = WebDriverWait(driver, 10)
relay_input = wait.until(EC.visibility_of_element_located((By.ID, 'relay')))

# 寻找relay输入框,并设置relay_key值
relay_input.clear()
relay_input.send_keys("wss://offchain.pub", Keys.RETURN)

for npub_key in npub_keys:
input_str = f'["REQ","cn",{{"authors":["{npub_key}"],"kinds":[1],"limit":1}} ]'
query_output = npub_to_live(driver, input_str)

print(f"{npub_key} Processed: {query_output} ")

# 提取 created_at 时间戳
created_at_match = re.search('"created_at":(\d+)', query_output)
if created_at_match:
created_at = int(created_at_match.group(1))

# 计算当前时间戳和 created_at 的差值
current_timestamp = int(time.time())
time_difference = current_timestamp - created_at

# 判断是否在过去30天内
if time_difference < 30 * 24 * 60 * 60:
with open("nostr_crawler_live_zh_users_list.txt", "a") as f:
f.write(f"{npub_key}\n")

# 关闭WebDriver实例
driver.quit()
if name == “main”:
main()
Author Public Key
npub1ccjq3jwtlhwv358r0g6xglxhc5zg9f9sex63xxl62ut6fl5efu4sysmr09