Last active
February 4, 2022 22:52
-
-
Save plq/84dd044b6d04816bb0ceac4334a8f294 to your computer and use it in GitHub Desktop.
cekilis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isimler | ||
---|---|---|
isim1 | ||
isim2 | ||
isim3 | ||
isim4 | ||
isim5 | ||
isim6 | ||
isim7 | ||
isim8 | ||
isim9 | ||
isim10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import json | |
import random | |
import csv | |
import sys | |
try: | |
kazanacak_kisi_sayisi = int(sys.argv[1]) | |
except: | |
print("Usage:", sys.argv[0], "<kazanacak kisi sayisi>") | |
sys.exit(1) | |
# herkesi oku | |
isimler = [] | |
with open('data.csv', 'r') as csvfile: | |
linenum = 0 | |
spamreader = csv.reader(csvfile, delimiter=',', quotechar='"') | |
for isim, _ in spamreader: | |
if linenum > 0: | |
isimler.append(isim) | |
linenum += 1 | |
# onceden kazanmis olanlari oku | |
kazanmislar = [] | |
if os.path.exists("kazanmislar.json"): | |
try: | |
kazanmislar = json.load(open("kazanmislar.json", 'r')) | |
except json.decoder.JSONDecodeError: | |
pass | |
kazanmislar = set(kazanmislar) | |
print("daha once", len(kazanmislar), "kisi kazanmis") | |
# cekilisi yap | |
adaylar = set(isimler) - set(kazanmislar) | |
if len(adaylar) < kazanacak_kisi_sayisi: | |
print(len(adaylar), "aday kalmis ama sen", kazanacak_kisi_sayisi, "adet kisi kazansin istedin") | |
sys.exit(1) | |
kazananlar = set(random.sample(list(adaylar), kazanacak_kisi_sayisi)) | |
loserlar = adaylar - set(kazananlar) | |
kazanmislar = kazananlar.union(kazanmislar) | |
print("kazananlar:", sorted(list(kazananlar))) | |
print("kalan adet:", len(loserlar)) | |
print("toplan kazanan adet:", len(kazanmislar)) | |
# onceki kazananlari yedekle | |
if os.path.exists("kazanmislar.json"): | |
cekilis_sayisi = 1 | |
backup = 'kazanmislar.%d.json' % (cekilis_sayisi,) | |
while os.path.exists(backup): | |
cekilis_sayisi += 1 | |
backup = 'kazanmislar.%d.json' % (cekilis_sayisi,) | |
print("rename", "kazanmislar.json", "=>", backup) | |
os.rename("kazanmislar.json", backup) | |
# son kazananlari da ekle | |
json.dump(sorted(list(kazanmislar)), open('kazanmislar.json', 'w', encoding='utf8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment