Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

搞个抽奖?抽Card主题? #19

Open
ITJoker233 opened this issue Mar 20, 2020 · 9 comments
Open

搞个抽奖?抽Card主题? #19

ITJoker233 opened this issue Mar 20, 2020 · 9 comments

Comments

@ITJoker233
Copy link
Owner

ITJoker233 commented Mar 20, 2020

QQ群:499093465

抽奖规则

  1. 给Chic点赞的,不取消star即可参加
  2. 若抽中就取消star的,我会很伤心的(会拉黑名单,确信(

为了有效的通知抽中的人,请在这里留下邮箱 base64 加密就行,不要添加除了base64字符串以外的英文,最好中文也不要...

star数达到100人的时候抽1个人。

star数达到200人的时候抽2个人。以此类推。

建议只有base64,方便我用脚本获取issue
届时,脚本发布到这里👇,最后

抽中的结果以图片+文字的形式发送到这里。
已经购买的用户或者再一次抽中的用户可以有以下选择

  1. 接受
  2. 转赠于指定的用户
  3. 升级Card到最新版本的一次机会
  4. 放弃(则重新开始抽奖)

当然也要遵守以下要求

不得倒卖,或者免费赠予他人,毕竟开发不易❤

注:抽奖获得的用户没有后续的维护
(只需支付6元💰即可得到后续更新维护,当然你可以选择不要这个更新维护服务)

抽奖的代码

import requests
import random
import time
import re
import json
import hashlib
import base64
from github import Github
from PIL import Image
import os
import win32gui, win32ui, win32con, win32api
import config
'''
结果自动发布到issue
为了保证公平性,随机抽取的算法公式如以下
打乱次数 = int(int(当前时间戳) / 抽奖时候项目的星数的星数 / 10000)
然后用ramdom自带的shuffle算法(洗牌算法)打乱要抽奖的idList
用这个随机数获取
'''
token = config.token
headers={}
g = Github(token)
repo = g.get_repo('ITJoker233/Gridea-theme-Chic')
'''19 为抽奖的issue id'''
issue = repo.get_issue(number=19)
'''670943373 为发布消息的 comment id'''
infoComment = issue.get_comment(670943373) 
'''获得已经给Star的用户,并且在issue评论的用户'''
comments = issue.get_comments() 
'''获得已经给Star的用户'''
stargazers = repo.get_stargazers_with_dates()



'''初始化用户数组'''
def initDict():
    commentUsers = {}
    for comment in comments:
        if comment.user.login != 'ITJoker233':
            pattern = r'[^\u4e00-\u9fa5]+'
            matchData = re.search(pattern,comment.body)
            if matchData:
                commentUsers[str(comment.id)] = {
                    'email':base64.b64decode(matchData.group()).decode()
                }
            else:
                print('这条comment无法匹配到:{comment.body}')
    Users = {}
    userCount  = 0
    for stargazer in stargazers:
        Users[str(userCount)] = {
            'id':stargazer.user.id,
            'name':stargazer.user.login,
            'email':''
        }
        if stargazer.user.id in commentUsers:
            Users[str(userCount)]['email'] = commentUsers[str(stargazer.user.id)]['email']
        else:
            Users[str(userCount)]['email'] = g.get_user(stargazer.user.login).email
        userCount += 1
    return Users


'''图片压缩'''
def compressImage(srcFile,dstFile):
    sImg=Image.open(srcFile)
    w,h=sImg.size
    dImg=sImg.resize((int(w),int(h)),Image.ANTIALIAS)
    dImg.save(dstFile)

'''截图函数'''
def printScreen(filename):
    hwnd = 0
    hwndDC = win32gui.GetWindowDC(hwnd)
    mfcDC = win32ui.CreateDCFromHandle(hwndDC)
    saveDC = mfcDC.CreateCompatibleDC()
    saveBitMap = win32ui.CreateBitmap()
    MoniterDev = win32api.EnumDisplayMonitors(None, None)
    w = MoniterDev[0][2][2]
    h = MoniterDev[0][2][3]
    saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
    saveDC.SelectObject(saveBitMap)
    saveDC.BitBlt((0, 0), (w, h), mfcDC, (0, 0), win32con.SRCCOPY)
    saveBitMap.SaveBitmapFile(saveDC, filename)
    win32gui.DeleteObject(saveBitMap.GetHandle())
    saveDC.DeleteDC()
    mfcDC.DeleteDC()
    win32gui.ReleaseDC(hwnd, hwndDC)
    compressImage(filename,filename)
    with open(filename,'rb') as file:
        picBase64 = base64.b64encode(file.read())
    return picBase64
    
'''上传到PicGo'''
def uploadPic(files):
    url = 'http://127.0.0.1:36679/upload'
    data  = {
        'list':files
    }
    response = requests.post(url,json.dumps(data)).json()
    if response['success']:
        return response['result'][0]
    return response['success']


'''获得随机用户id'''
def getRandomUserID(StarCount):
    '''由于从0开始,所以-1'''
    idList = [x for x in range(0,StarCount-1)] 
    '''要给一定打乱的次数至少100次'''
    messNum = random.randint(StarCount,int(int(time.time()) / StarCount / 10000))
    for i in range(0,messNum):
        random.shuffle(idList)
    print('已打乱次数:'+str(messNum))
    return idList[0]

'''开始抽奖'''
def StartLottery(Stargazers,winNumber):
    '''star星数'''
    StarCount = len(Stargazers)
    '''中奖用户列表'''
    winUsers = []
    for i in range(winNumber):
        print(f'**开始第{str(i)}个随机用户**')
        winUser = Stargazers[str(getRandomUserID(StarCount))]
        winUsers.append(winUser)
        print(f'''{'*'*10}\nName: {winUser['name']}\nUserID:{winUser['id']}\nEmail:{winUser['email']}''')
    print(f'''恭喜中奖的这{winNumber}个逼:{",".join([winUser['name'] for winUser in winUsers ])},''')
    return winUsers


if __name__ == "__main__":
    print('****初始化用户字典列表****')
    '''初始化用户字典列表'''
    oldTime = time.time()
    Stargazers = initDict() 
    '''抽奖批次'''
    lotteryTime = int(len(Stargazers)/100)
    '''中奖人数'''
    winNumber = lotteryTime
    print('****开始抽奖****')
    winUsers = StartLottery(Stargazers,winNumber)
    print(f'****抽奖结束****\n> 用时:{int(time.time()-oldTime)}秒')
    nowDate = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
    Body = infoComment.body + f'\r\n### 本次抽奖时间:{nowDate} \r\n#### 抽奖批次:第{lotteryTime}批 🔥'
    i = 1
    for winUser in winUsers:
        Body += f'''\r\n{i}. {winUser['name']} {winUser['id']} '''
        i += 1
    fileName = f'''抽奖第{lotteryTime}批结果_{time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))}.jpg'''
    print('****正在截图...****')
    print(f'> 文件名为:{fileName}')
    time.sleep(1)
    md5 = hashlib.md5()
    picData = printScreen(fileName)
    md5.update(picData)
    print('****正在上传到图床****')
    picUrl = uploadPic([(os.path.abspath('.')+'\\'+fileName).replace('\\','/')])
    Body += f'\r\n\n### 运行结果图\r\n\n 图片md5:{md5.hexdigest()}'
    Body += f'\r\n\n![(图床)运行结果图]({picUrl})'
    print('****正在提交数据****')
    infoComment.edit(Body)
    print(f'提交成功')
@FWangZil
Copy link

FWangZil commented May 9, 2020

Nzc5MTU4MDc4QHFxLmNvbQ==

@ITJoker233 ITJoker233 pinned this issue May 10, 2020
@Chaaoo
Copy link

Chaaoo commented Jul 14, 2020

ODk0NzMyOTk5QHFxLmNvbQ==

@wangzy14
Copy link

wangzy14 commented Jul 15, 2020

NzU2ODk3MjRAcXEuY29t

@SoraKasvgano
Copy link
Contributor

bm9yZXBseTFAYmZiYW4uY29t

@WhatZ2333
Copy link

d2hhdHoyMzMzQDg4LmNvbQ==

@Lingtin
Copy link

Lingtin commented Aug 7, 2020

enhzeHp0QGZveG1haWwuY29t

@ITJoker233
Copy link
Owner Author

ITJoker233 commented Aug 8, 2020

中奖名单

本次抽奖时间:2020-08-09 04:11:32

抽奖批次:第1批 🔥

  1. Crmye 63234216

运行结果图

图片md5:252098decd92814ec025840993595e85

(图床)运行结果图

@ITJoker233
Copy link
Owner Author

明天我再抽🐷

Repository owner deleted a comment Aug 17, 2020
@Lemonawa
Copy link

SmFtZXNtZW5nXzY2NkBvdXRsb29rLmNvbQ==

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants