Last active
August 29, 2015 14:11
-
-
Save wasabi0522/77cb6a44d4275cd818e6 to your computer and use it in GitHub Desktop.
Darsana Anker lottery
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 python | |
# -*- coding:utf-8 -*- | |
from __future__ import print_function | |
import sys | |
import random | |
import time | |
import csv | |
import datetime | |
seed = time.time() | |
def uniq_choice(members, num): | |
results = [] | |
for i in range(num): | |
try: | |
t = random.Random(seed).choice(members) | |
except IndexError: | |
sys.exit(1) | |
results.append(t) | |
members.remove(t) | |
return results | |
if __name__ == '__main__': | |
if len(sys.argv) < 3: | |
print("darsana_lottery.py [Path to userlist csv] [Path to prizelist csv]") | |
sys.exit(1) | |
members_file = sys.argv[1] | |
prizes_file = sys.argv[2] | |
# Timestamp(seed) check | |
print("Time based seed(%s) means datatime(%s)" % ( | |
seed, | |
datetime.datetime.fromtimestamp(seed).strftime('%Y/%m/%d %H:%M:%S'))) | |
with open(members_file) as mb, open(prizes_file) as pz: | |
members = [i for i in csv.DictReader(mb)] | |
members_index = list(range(len(members))) | |
# each line include Anker item name, num and num | |
prizes = [line[:-1].split(",") for line in pz] | |
type_ = (("*当選者*", 1), ("*当選予備*", 2)) | |
for i in prizes: | |
print("*%s*" % i[0]) # item name | |
for n, j in type_: | |
print(n) | |
results = uniq_choice(members_index, int(i[j])) | |
for k in results: | |
print("%s,%s,%s" % (members[k]["name"], # Agent name | |
members[k]["gname"], # Google+ name | |
members[k]["url"])) # Google+ url |
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
name | gname | url | |
---|---|---|---|
wasabi0522 | Masahiro kiura | https://plus.google.com/u/0/+MasahiroKiura |
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
2nd Gen Astro E4 | 3 | 3 | |
---|---|---|---|
2nd Gen Astro E3 | 3 | 3 | |
2nd Gen Astro | 2 | 2 | |
40W 5-Port Charger | 2 | 2 | |
24W 2-Port Car Charger | 2 | 2 | |
6 Foot Cables | 20 | 20 | |
10 Foot Cables | 20 | 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment