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

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

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

    抽奖规则和去年一样取上证指数和最后指定日期最高楼。上一年的帖子/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://ex.noerr.eu.org/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://ex.noerr.eu.org/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  
    cs5791393
        301
    cs5791393  
       2024-11-22 13:05:08 +08:00
    重在参与!
    zhaojiejoe
        302
    zhaojiejoe  
       2024-11-22 13:06:21 +08:00
    分子
    xujunjie
        303
    xujunjie  
       2024-11-22 13:10:31 +08:00
    支持
    570956418
        304
    570956418  
       2024-11-22 13:12:56 +08:00
    参与一下
    cjlsky
        305
    cjlsky  
       2024-11-22 13:15:08 +08:00
    回购的第二年
    robot2134
        306
    robot2134  
       2024-11-22 13:15:58 +08:00 via Android
    +1
    defunct9
        307
    defunct9  
       2024-11-22 13:19:57 +08:00
    分子
    Pbe2RsrnVcPrF
        308
    Pbe2RsrnVcPrF  
       2024-11-22 13:22:07 +08:00
    1
    s609926202
        309
    s609926202  
       2024-11-22 13:29:33 +08:00
    +1
    JerryV2
        310
    JerryV2  
       2024-11-22 13:30:09 +08:00
    +1
    xier9213
        311
    xier9213  
       2024-11-22 13:33:28 +08:00
    分母+1
    ecee
        312
    ecee  
       2024-11-22 13:33:39 +08:00
    +1
    bomjack
        313
    bomjack  
       2024-11-22 13:34:20 +08:00
    重在参与
    kzmdididi
        314
    kzmdididi  
       2024-11-22 13:34:36 +08:00
    大麦
    vimfaith
        315
    vimfaith  
       2024-11-22 13:38:29 +08:00
    重在参与!
    PeterPig
        316
    PeterPig  
       2024-11-22 13:38:37 +08:00 via iPhone
    +1
    vimfaith
        317
    vimfaith  
       2024-11-22 13:38:43 +08:00
    重在参与
    nellace
        318
    nellace  
       2024-11-22 13:39:19 +08:00
    重在参与!
    cqq626432432
        319
    cqq626432432  
       2024-11-22 13:40:10 +08:00
    重在参与!
    adimn
        320
    adimn  
       2024-11-22 13:41:35 +08:00
    做个分子
    jaylengao
        321
    jaylengao  
       2024-11-22 13:42:33 +08:00
    重在参与
    wxd21020
        322
    wxd21020  
       2024-11-22 13:43:26 +08:00
    支持
    hnbcinfo
        323
    hnbcinfo  
       2024-11-22 13:44:20 +08:00
    大家好,我是分母。重在掺和,拉低各位中奖率就是我的目标
    myxvhgiile
        324
    myxvhgiile  
       2024-11-22 13:45:01 +08:00
    参与一下
    wangofjian
        325
    wangofjian  
       2024-11-22 13:45:04 +08:00
    凑个分子
    ip7x12v5
        326
    ip7x12v5  
       2024-11-22 13:48:52 +08:00
    试试
    seeyourface
        327
    seeyourface  
       2024-11-22 13:49:38 +08:00
    参与一下
    qwas
        328
    qwas  
       2024-11-22 13:50:33 +08:00
    橙不橙子不重要,看到队伍占个位
    meteor957
        329
    meteor957  
       2024-11-22 13:50:49 +08:00
    分母+1
    markchen88
        330
    markchen88  
       2024-11-22 13:50:57 +08:00
    参与
    raydied
        331
    raydied  
       2024-11-22 13:51:17 +08:00
    分子分母都+1
    paullige
        332
    paullige  
       2024-11-22 13:52:17 +08:00
    感谢
    keaidian
        333
    keaidian  
       2024-11-22 13:53:05 +08:00
    幸运之子!
    lilicheng
        334
    lilicheng  
       2024-11-22 13:53:49 +08:00
    那就让我尝尝吧
    jykid
        335
    jykid  
       2024-11-22 13:54:18 +08:00
    那让我来试试
    SkYouth
        336
    SkYouth  
       2024-11-22 13:55:34 +08:00
    重在参与。
    sdsd995
        337
    sdsd995  
       2024-11-22 13:56:21 +08:00
    支持一下,参与试试
    rawburuser
        338
    rawburuser  
       2024-11-22 13:57:35 +08:00
    重在参与
    aswqazx
        339
    aswqazx  
       2024-11-22 13:59:31 +08:00
    +1
    alanoy
        340
    alanoy  
       2024-11-22 14:00:38 +08:00
    重在参与!
    wanwan
        341
    wanwan  
       2024-11-22 14:02:13 +08:00 via Android
    看看运气
    Mianmiss
        342
    Mianmiss  
       2024-11-22 14:02:31 +08:00
    +1 重在参与
    Mianmiss
        343
    Mianmiss  
       2024-11-22 14:02:39 +08:00
    参与下
    luo123qiu
        344
    luo123qiu  
       2024-11-22 14:03:29 +08:00
    分母+1
    iamperiod331www
        345
    iamperiod331www  
       2024-11-22 14:05:33 +08:00
    参与一下
    lin98
        346
    lin98  
       2024-11-22 14:05:51 +08:00
    试试
    fantasy55
        347
    fantasy55  
       2024-11-22 14:06:41 +08:00
    分子++
    kissing
        348
    kissing  
       2024-11-22 14:07:14 +08:00
    支持一下!
    a33291
        349
    a33291  
       2024-11-22 14:07:35 +08:00
    祝 op 大卖
    gongxuanzhang
        350
    gongxuanzhang  
       2024-11-22 14:09:24 +08:00
    今年运气还可以
    walkeronway
        351
    walkeronway  
       2024-11-22 14:10:42 +08:00
    支持支持
    boom520
        352
    boom520  
       2024-11-22 14:10:43 +08:00
    上次买过,味道 ok 的
    xing666
        353
    xing666  
       2024-11-22 14:14:19 +08:00
    重在参与
    Incarna
        354
    Incarna  
       2024-11-22 14:14:36 +08:00
    支持,要是中了的话觉得好吃给家人买点
    wlliam19
        355
    wlliam19  
       2024-11-22 14:17:30 +08:00
    想吃
    clieujv
        356
    clieujv  
       2024-11-22 14:18:22 +08:00
    我相信我能中
    wujinglun
        357
    wujinglun  
       2024-11-22 14:20:16 +08:00
    参与一下
    sumarker
        358
    sumarker  
    PRO
       2024-11-22 14:21:08 +08:00
    分子
    jark006
        359
    jark006  
       2024-11-22 14:22:17 +08:00
    分母来了
    pegasusz
        360
    pegasusz  
       2024-11-22 14:26:02 +08:00
    反正中不了,拉低下中奖率吧
    bluelotus0739
        361
    bluelotus0739  
       2024-11-22 14:27:45 +08:00
    赣南脐橙真的很好吃!!!
    JieyueXing
        362
    JieyueXing  
    PRO
       2024-11-22 14:27:50 +08:00
    分子
    lianginx
        363
    lianginx  
       2024-11-22 14:29:11 +08:00
    好家伙,第一次抽奖,我来试试
    qwereee
        364
    qwereee  
       2024-11-22 14:29:23 +08:00
    +1
    qingshengwen
        365
    qingshengwen  
       2024-11-22 14:30:07 +08:00
    分子+1
    BelovedOne
        366
    BelovedOne  
       2024-11-22 14:31:19 +08:00
    重在参与!
    ae86
        367
    ae86  
       2024-11-22 14:31:27 +08:00
    分母+1
    mrzhoudjq
        368
    mrzhoudjq  
       2024-11-22 14:33:23 +08:00
    参与一下
    yxb9511
        369
    yxb9511  
       2024-11-22 14:35:45 +08:00
    冲冲冲,每年都吃赣南脐橙
    purewhite0
        370
    purewhite0  
       2024-11-22 14:37:48 +08:00
    参与一下
    mxT52CRuqR6o5
        371
    mxT52CRuqR6o5  
       2024-11-22 14:37:55 +08:00
    分母
    waising
        372
    waising  
       2024-11-22 14:40:12 +08:00
    分母
    zjzs
        373
    zjzs  
       2024-11-22 14:45:11 +08:00
    分母来啦
    AmosWu
        374
    AmosWu  
       2024-11-22 14:45:29 +08:00
    +1
    veyron888
        375
    veyron888  
       2024-11-22 14:45:29 +08:00
    预祝大麦
    eventlooped
        376
    eventlooped  
       2024-11-22 14:47:26 +08:00
    重在参与,爱吃脐橙
    lddtech
        377
    lddtech  
       2024-11-22 14:48:18 +08:00
    分子
    jy02919061
        378
    jy02919061  
       2024-11-22 14:49:31 +08:00 via Android
    来了啦啦啦啦啦了
    ZX16815
        379
    ZX16815  
       2024-11-22 14:49:32 +08:00
    分子
    cubicoo
        380
    cubicoo  
       2024-11-22 14:49:50 +08:00 via Android
    参与一下
    CaptainAmerica
        381
    CaptainAmerica  
       2024-11-22 14:51:25 +08:00
    支持一下
    hahasong
        382
    hahasong  
       2024-11-22 14:56:17 +08:00
    我来看看能不能吃上
    Rekkles
        383
    Rekkles  
       2024-11-22 14:57:08 +08:00
    分子分母
    wulv
        384
    wulv  
       2024-11-22 14:57:24 +08:00
    参与一下
    richamon
        385
    richamon  
       2024-11-22 14:58:53 +08:00
    参与一下
    vaynecv
        386
    vaynecv  
       2024-11-22 15:02:31 +08:00
    分子
    NilError
        387
    NilError  
       2024-11-22 15:03:09 +08:00
    分母加一
    ddonano
        388
    ddonano  
       2024-11-22 15:03:20 +08:00
    参与一下
    yuxi521
        389
    yuxi521  
       2024-11-22 15:04:28 +08:00
    1111
    liuxiaojiu
        390
    liuxiaojiu  
       2024-11-22 15:06:07 +08:00
    试一下
    zzerd
        391
    zzerd  
    OP
       2024-11-22 15:06:09 +08:00
    @Feedmo https://gist.github.com/zzerding/d80d25149a74c0dd96516d949e9e52b7 看这兄弟,这有注释。晚上我有空用 V2EX api 重写 getAllUser
    yveJohn
        392
    yveJohn  
       2024-11-22 15:06:32 +08:00
    重在参与
    lvxing888
        393
    lvxing888  
       2024-11-22 15:08:41 +08:00
    支持一下
    luistrong
        394
    luistrong  
       2024-11-22 15:10:02 +08:00
    分子
    voya
        395
    voya  
       2024-11-22 15:10:41 +08:00
    生意兴隆
    Yafun
        396
    Yafun  
       2024-11-22 15:11:35 +08:00
    重在参与!!
    zhijietalk
        397
    zhijietalk  
       2024-11-22 15:14:05 +08:00
    试试
    zgsi
        398
    zgsi  
       2024-11-22 15:14:38 +08:00
    代码一言难尽
    akxjhdfn
        399
    akxjhdfn  
       2024-11-22 15:15:42 +08:00
    分子!~
    allendavis
        400
    allendavis  
       2024-11-22 15:21:02 +08:00
    拉低概率?
    1  2  3  4  5  6  
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   4268 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 10:07 · PVG 18:07 · LAX 02:07 · JFK 05:07
    ♥ Do have faith in what you're doing.