V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zzerd
V2EX  ›  推广

自已家的赣南脐橙开卖,给 v 友抽几箱

  •  
  •   zzerd · 2024-11-22 00:28:09 +08:00 · 17247 次点击
    这是一个创建于 381 天前的主题,其中的信息可能已经有所发展或是发生改变。

    抽奖规则和去年一样取上证指数和最后指定日期最高楼。上一年的帖子/996196

    今年取 2024-11-22 上证指数收盘价作为随机数种子,有效抽奖用户为 2024-11-22 帖子回复最高楼层前的所有所有人

    去年的抽奖代码没有去重所有回复多个的用户中的概率高一点点,今年我用 ai 糊了一下。代码如下

    const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36';
    
    async function handleRequest(tid, num, seedParam, maxFloor) {
        if (!tid || isNaN(num)) {
            console.error('请提供有效的帖子 ID 和抽奖人数');
            return;
        }
        console.log(`Fetching OP for TID: ${tid}`);
        const op = await getOp(tid);
        console.log(`OP: ${op}`);
        console.log(`Fetching all users for TID: ${tid}`);
        const uniqueUserList = await getAllUser(tid, maxFloor);
        console.log(`Unique Users: ${uniqueUserList.join(', ')}`);
        const filteredUserList = uniqueUserList.filter(user => user !== op);
        console.log(`Filtered Users: ${filteredUserList.join(', ')}`);
        const userCount = filteredUserList.length;
        console.log(`User Count: ${userCount}`);
        const seed = seedParam !== null ? seedParam : userCount.toString();
        console.log(`Seed: ${seed}`);
        console.log(`Max Floor: ${maxFloor}`);
        const combinedSeed = `${seed}-${maxFloor}`;
        console.log(`Combined Seed: ${combinedSeed}`);
        const shuffledList = shuffle(filteredUserList, combinedSeed);
        console.log(`Shuffled Users: ${shuffledList.join(', ')}`);
        const result = `符合条件的用户共有 ${filteredUserList.length} 人
    抽奖结果:
    ${shuffledList.slice(0, num).join('\n')}`;
        console.log(result);
    }
    
    async function getOp(tid) {
        const url = `https://www.v2ex.com/amp/t/${tid}`;
        console.log(`Fetching OP URL: ${url}`);
        const response = await fetch(url, { headers: { 'User-Agent': UA } });
        if (!response.ok) {
            console.log(`Failed to fetch OP: ${response.status} ${response.statusText}`);
            return null;
        }
        const text = await response.text();
        const match = /<div class="topic_author">[\s\S]*?<amp-img[^>]+alt="([^"]+)"[\s\S]*?<\/div>/.exec(text);
        console.log(`OP Match: ${match ? match[1] : null}`);
        return match ? match[1].trim() : null;
    }
    
    async function getUserList(url, startIndex, endIndex) {
        console.log(`Fetching User List URL: ${url}`);
        const response = await fetch(url, { headers: { 'User-Agent': UA } });
        if (!response.ok) {
            console.log(`Failed to fetch User List: ${response.status} ${response.statusText}`);
            return [];
        }
        const text = await response.text();
        const replyItemRegex = /<div class="reply_item">([\s\S]*?)<\/div>/g;
        let replyItemMatch;
        const users = [];
        let currentIndex = startIndex || 0;
        while ((replyItemMatch = replyItemRegex.exec(text)) !== null) {
            if (endIndex !== undefined && currentIndex >= endIndex) {
                break;
            }
            const replyItem = replyItemMatch[1];
            const altRegex = /<amp-img[^>]+alt="([^"]+)"[^>]*>/g;
            const altMatch = altRegex.exec(replyItem);
            if (altMatch) {
                users.push(altMatch[1]);
            }
            currentIndex++;
        }
        console.log(`Matches: ${users.join(', ')}`);
        return users;
    }
    
    async function getAllPages(tid) {
        const url = `https://www.v2ex.com/amp/t/${tid}`;
        console.log(`Fetching All Pages URL: ${url}`);
        const response = await fetch(url, { headers: { 'User-Agent': UA } });
        if (!response.ok) {
            console.log(`Failed to fetch All Pages: ${response.status} ${response.statusText}`);
            return [];
        }
        const text = await response.text();
        const pageCountMatch = /\u5171 (\d+) \u9875/.exec(text);
        const pageCount = pageCountMatch ? parseInt(pageCountMatch[1], 10) : 1;
        console.log(`Page Count: ${pageCount}`);
        const pages = [];
        for (let i = 1; i <= pageCount; i++) {
            pages.push(`${url}/${i}`);
        }
        return pages;
    }
    
    async function getAllUser(tid, maxFloor) {
        const pages = await getAllPages(tid);
        console.log(`Pages: ${pages.join(', ')}`);
        let allUsers = [];
        let currentFloor = 0;
        for (let page of pages) {
            const startIndex = currentFloor;
            const endIndex = maxFloor !== undefined ? maxFloor : undefined;
            const users = await getUserList(page, startIndex, endIndex);
            allUsers = allUsers.concat(users);
            currentFloor += users.length;
            if (endIndex !== undefined && currentFloor >= endIndex) {
                break;
            }
        }
        const uniqueUsers = [];
        const seen = new Set();
        for (const user of allUsers) {
            if (!seen.has(user)) {
                uniqueUsers.push(user);
                seen.add(user);
            }
        }
        console.log(`Unique Users: ${uniqueUsers.join(', ')}`);
        return uniqueUsers;
    }
    
    function shuffle(array, seed) {
        const rng = lcg(seed);
        console.log(`Shuffling with Seed: ${seed}`);
        for (let i = array.length - 1; i > 0; i--) {
            const j = Math.floor(rng() * (i + 1));
            console.log(`Shuffling: i=${i}, j=${j}`);
            if (array[i] !== undefined && array[j] !== undefined) {
                [array[i], array[j]] = [array[j], array[i]];
            } else {
                console.log(`Error: array[i] or array[j] is undefined. i=${i}, j=${j}, array[i]=${array[i]}, array[j]=${array[j]}`);
            }
        }
        return array;
    }
    
    function lcg(seed) {
        let state = hashCode(seed);
        console.log(`LCG State: ${state}`);
        const a = 1664525;
        const c = 1013904223;
        const m = Math.pow(2, 32);
        return function() {
            state = (a * state + c) % m;
            console.log(`LCG Next: ${state / m}`);
            return state / m;
        }
    }
    
    function hashCode(str) {
        l
    ![]( https://i.v2ex.co/VlpwI4y5.jpeg)
    et hash = 0;
        for (let i = 0; i < str.length; i++) {
            const char = str.charCodeAt(i);
            hash = ((hash << 5) - hash) + char;
            hash |= 0;
        }
        return Math.abs(hash);
    }
    
    // Example usage:
    handleRequest('123456', 3, seed123, 10);
    这里的 '123456' 是帖子 ID ,3 是抽奖人数,'seed123' 是种子(可选),10 是最大楼层(可选)。
    在 V2EX 网站里用浏览器 consele 运行就可以
    

    为了方便 v 友进行类似抽奖我糊了一个 cloudflare work 来使用直接请求 https://v2ex.240801.xyz/?tid=12345&num=10&seed=12345&maxFloor=11(大佬别打,刚装上访问不了可能 cf 路由没设置好)这里的参数说明为 tid 为帖子 id num 为中奖人数 seed 为随机数种子 maxFloor 为最高楼层

    下面是橙子链接请大家按需购买

    ps 甜度不用担心,今年我们县的都甜。现摘现发没有清洗打腊,只要老家不下雨一般下单第二天就发货。室温 20 度以内还是很耐放的两三个星期没啥问题。有个卖橙子的微信群想加的加我微信 console.log(atob('enF3MjAwOA=='))拉群

    第 1 条附言  ·  2024-11-22 09:23:17 +08:00

    今年的橙子我也还没吃上,这图都是前段时间家时机人拍的现在橙子应该黄一些了。

    为啥这次的代码块没有高亮。。。代码看起来多,是因为ai 写的取回复用户数没用v站的api,下面是去除相关爬虫代码后的代码:https://gist.github.com/zzerding/d80d25149a74c0dd96516d949e9e52b7

    cloudflare work我会改为api形式代码后续在上面的gist里更新

    晚上12点以后可根据规则自行开奖

    第 2 条附言  ·  2024-11-22 10:51:00 +08:00

    统一回复一下:

    橙子大约9分甜一分酸,每个人的口感不一样可以进群问问去年的v友

    可以发顺丰。晚上熬夜开的团图片先错了,里面有顺丰的商品链接大约江西周边9省53r/5kg

    好了不摸鱼了领导催进度了

    第 3 条附言  ·  2024-11-23 09:35:03 +08:00

    感谢大家的支持,因为是现摘发货一天也就发300斤,受天气影响22号下单的会在24或者25号发完,先下单的先发,介意的可以申请退款。

    抽奖

    使用node自行开奖

    看到515楼我知道这个正则表达式取用户非常不可靠(但是当前代码好像没有注入成功),所以改用v2ex api。 使用方式

    恭喜以下用户

    @AchieveHF @xwh @ruiy @kuzhan 可以回复联系方式或者带主页截图找我领奖

    545 条回复    2025-11-24 08:52:04 +08:00
    1  2  3  4  5  6  
    guzzhao
        401
    guzzhao  
       2024-11-22 15:21:51 +08:00
    分子
    Arrowing
        402
    Arrowing  
       2024-11-22 15:22:48 +08:00
    重在参与!
    HelloCCC
        403
    HelloCCC  
       2024-11-22 15:23:15 +08:00
    重在参与
    xwh
        404
    xwh  
       2024-11-22 15:23:43 +08:00
    支持
    phh
        405
    phh  
       2024-11-22 15:24:02 +08:00
    分母加一 今天大 A 就是你弄崩的吧
    MilkyWayZZ
        406
    MilkyWayZZ  
       2024-11-22 15:24:23 +08:00
    分母
    yamaidai
        407
    yamaidai  
       2024-11-22 15:25:00 +08:00
    重在参与!
    yahon
        408
    yahon  
       2024-11-22 15:26:31 +08:00
    试试
    terito11122
        409
    terito11122  
       2024-11-22 15:27:21 +08:00
    分子~
    justinjsn
        410
    justinjsn  
       2024-11-22 15:28:25 +08:00
    分母 +1
    ashtwo
        411
    ashtwo  
       2024-11-22 15:28:51 +08:00
    分母
    coderljx
        412
    coderljx  
       2024-11-22 15:29:55 +08:00
    重在参与
    byaiu
        413
    byaiu  
       2024-11-22 15:31:04 +08:00
    分子!
    somin
        414
    somin  
       2024-11-22 15:33:47 +08:00
    参与一下
    linzhai
        415
    linzhai  
       2024-11-22 15:33:49 +08:00
    分母+1
    ImDESIGNER
        416
    ImDESIGNER  
       2024-11-22 15:34:38 +08:00
    祝福
    chengiri
        417
    chengiri  
       2024-11-22 15:34:59 +08:00
    +1
    alphafeng
        418
    alphafeng  
       2024-11-22 15:36:05 +08:00
    分母+1
    5460
        419
    5460  
       2024-11-22 15:36:23 +08:00
    来试试运气
    null113
        420
    null113  
       2024-11-22 15:40:20 +08:00
    试试
    czhxn123456
        421
    czhxn123456  
       2024-11-22 15:42:22 +08:00
    分子
    sleepyfevniv
        422
    sleepyfevniv  
       2024-11-22 15:44:25 +08:00
    分母分母分母分母分母
    wowawesome
        423
    wowawesome  
       2024-11-22 15:45:10 +08:00
    分子+1
    noahlias
        424
    noahlias  
       2024-11-22 15:45:23 +08:00
    分一下
    xmt328
        425
    xmt328  
       2024-11-22 15:45:44 +08:00
    看到了还是要参与下
    jojon
        426
    jojon  
       2024-11-22 15:47:32 +08:00
    重在参与
    CodeSorcerer
        427
    CodeSorcerer  
       2024-11-22 15:48:14 +08:00
    重在参与
    smilev587
        428
    smilev587  
       2024-11-22 15:53:31 +08:00
    分母
    AgileLC
        429
    AgileLC  
       2024-11-22 15:53:39 +08:00
    买了试试
    dezou
        430
    dezou  
       2024-11-22 15:59:41 +08:00
    争做分子
    miss1123
        431
    miss1123  
       2024-11-22 16:01:48 +08:00
    分母
    xlzhu
        432
    xlzhu  
       2024-11-22 16:05:25 +08:00
    重在参与,顺祝商祺
    zeuss
        433
    zeuss  
       2024-11-22 16:07:00 +08:00
    try try
    svanrj
        434
    svanrj  
       2024-11-22 16:08:42 +08:00
    重在参与!
    karlxu
        435
    karlxu  
       2024-11-22 16:17:59 +08:00
    做个分母
    qianghaha
        436
    qianghaha  
       2024-11-22 16:21:51 +08:00
    分子试试~
    MMDeJeVS3GtMVLeu
        437
    MMDeJeVS3GtMVLeu  
       2024-11-22 16:22:03 +08:00
    分子
    zc832097
        438
    zc832097  
       2024-11-22 16:22:16 +08:00
    分子+1
    beihanggmj
        439
    beihanggmj  
       2024-11-22 16:22:53 +08:00
    做个分母和分子
    Javen96
        440
    Javen96  
       2024-11-22 16:24:57 +08:00
    分子试试~
    zidy111
        441
    zidy111  
       2024-11-22 16:25:10 +08:00
    重在参与。
    zephyr94
        442
    zephyr94  
       2024-11-22 16:28:03 +08:00
    +1
    JustinJie
        443
    JustinJie  
       2024-11-22 16:29:58 +08:00 via iPhone
    来来来 分子分子
    antonlee
        444
    antonlee  
       2024-11-22 16:30:10 +08:00
    参,祺
    ninggc
        445
    ninggc  
       2024-11-22 16:31:24 +08:00
    参与下
    chen11
        446
    chen11  
       2024-11-22 16:31:55 +08:00
    当个分母
    aogg
        447
    aogg  
       2024-11-22 16:32:19 +08:00
    分母,分子多少个啊
    AokiNet
        448
    AokiNet  
       2024-11-22 16:32:26 +08:00
    XHalso
        449
    XHalso  
       2024-11-22 16:33:00 +08:00
    重在参与!
    Tune
        450
    Tune  
       2024-11-22 16:33:17 +08:00 via iPhone
    来参与一下😁
    Kenyore
        451
    Kenyore  
       2024-11-22 16:34:56 +08:00
    当个分母
    tooZero
        452
    tooZero  
       2024-11-22 16:37:42 +08:00
    你是分母 我是分子 我们不一样
    youyang
        453
    youyang  
       2024-11-22 16:38:10 +08:00
    大麦~
    LiGG
        454
    LiGG  
       2024-11-22 16:38:58 +08:00
    支持
    aredhat200
        455
    aredhat200  
       2024-11-22 16:40:50 +08:00 via iPhone
    分子!
    goleben
        456
    goleben  
       2024-11-22 16:42:21 +08:00
    看着不错哦
    easyii
        457
    easyii  
       2024-11-22 16:42:40 +08:00
    参与
    myleszzZ
        458
    myleszzZ  
       2024-11-22 16:43:05 +08:00
    分子试试~
    shimmying
        459
    shimmying  
       2024-11-22 16:44:13 +08:00
    重在参与!
    taygetus
        460
    taygetus  
       2024-11-22 16:44:27 +08:00
    分母
    mkbnb2333
        461
    mkbnb2333  
       2024-11-22 16:46:02 +08:00
    重在参与!
    gn3tR2RR584l2aP2
        462
    gn3tR2RR584l2aP2  
       2024-11-22 16:48:11 +08:00
    想吃橙子。
    SolLo
        463
    SolLo  
    PRO
       2024-11-22 16:50:03 +08:00
    重在参与,支持一下!
    Vendettar
        464
    Vendettar  
       2024-11-22 16:50:43 +08:00
    支持
    littlebrother
        465
    littlebrother  
       2024-11-22 16:51:39 +08:00
    分子试试~
    Cyclince
        466
    Cyclince  
       2024-11-22 16:52:21 +08:00 via Android
    试试
    864766428
        467
    864766428  
       2024-11-22 16:52:36 +08:00 via iPhone
    万一呢
    ohuo
        468
    ohuo  
       2024-11-22 16:53:40 +08:00
    分子
    zjsxwc
        469
    zjsxwc  
       2024-11-22 16:54:53 +08:00
    做个分母
    miz123456
        470
    miz123456  
       2024-11-22 16:56:01 +08:00
    重在参与!
    cheese
        471
    cheese  
       2024-11-22 16:57:39 +08:00
    尝试中奖
    osdnfpn
        472
    osdnfpn  
       2024-11-22 16:57:47 +08:00
    做个分母
    bigblackpig
        473
    bigblackpig  
       2024-11-22 17:07:01 +08:00
    减少概率组
    zhjh0521
        474
    zhjh0521  
       2024-11-22 17:07:50 +08:00
    做个分母
    zhangsx
        475
    zhangsx  
       2024-11-22 17:09:15 +08:00
    试试,不过脐橙确实好吃
    lokya
        476
    lokya  
       2024-11-22 17:10:49 +08:00
    参与一下
    Od37v61n5s89gXx8
        477
    Od37v61n5s89gXx8  
       2024-11-22 17:15:03 +08:00
    争做分子
    lzs5240
        478
    lzs5240  
       2024-11-22 17:17:38 +08:00
    重在参与 说不定呢
    bucketcheng
        479
    bucketcheng  
       2024-11-22 17:17:53 +08:00
    dddd
    manus
        480
    manus  
       2024-11-22 17:19:55 +08:00
    没中过奖
    brilliantsparrow
        481
    brilliantsparrow  
       2024-11-22 17:20:34 +08:00
    中!!!
    cont
        482
    cont  
       2024-11-22 17:23:02 +08:00
    +1
    m1ch3ng
        483
    m1ch3ng  
       2024-11-22 17:23:19 +08:00
    我来当分母了
    titixlq
        484
    titixlq  
       2024-11-22 17:23:57 +08:00
    分子+
    syncnano
        485
    syncnano  
       2024-11-22 17:28:25 +08:00
    重在参与
    yushenglin
        486
    yushenglin  
       2024-11-22 17:29:02 +08:00
    重在参与!
    Tiking
        487
    Tiking  
       2024-11-22 17:29:26 +08:00
    做个分母
    fengci
        488
    fengci  
       2024-11-22 17:31:49 +08:00
    尝试中奖 体会 v 友的开心
    coolrc
        489
    coolrc  
       2024-11-22 17:34:49 +08:00 via Android
    1
    isaced
        490
    isaced  
       2024-11-22 17:35:06 +08:00
    来吃橙子了~
    HappyAndSmile
        491
    HappyAndSmile  
       2024-11-22 17:43:31 +08:00
    我也小小参与下吧
    hellojukay
        492
    hellojukay  
       2024-11-22 17:44:51 +08:00
    中奖专用评论
    flyfire
        493
    flyfire  
       2024-11-22 17:49:01 +08:00
    重在参与
    v3413
        494
    v3413  
       2024-11-22 17:51:52 +08:00
    重在参与
    Mystery0
        495
    Mystery0  
       2024-11-22 17:55:24 +08:00
    参与一下
    CodeGroup
        496
    CodeGroup  
       2024-11-22 17:56:05 +08:00
    已下单
    notgoda
        497
    notgoda  
       2024-11-22 17:56:45 +08:00 via iPhone
    jmliang
        498
    jmliang  
       2024-11-22 18:04:02 +08:00
    试试
    JssDream
        499
    JssDream  
       2024-11-22 18:05:00 +08:00
    分母+1
    Spute
        500
    Spute  
       2024-11-22 18:11:04 +08:00
    👍江西老表
    1  2  3  4  5  6  
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2841 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 14:34 · PVG 22:34 · LAX 06:34 · JFK 09:34
    ♥ Do have faith in what you're doing.