-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
92 lines (82 loc) · 2.17 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- coding: utf-8 -*-
#
from config import *
import tweepy
import random
from unicodedata import normalize
def login():
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
return tweepy.API(auth)
def tweet(api, string):
api.update_status(status=string)
# returns a list of 16 boggle letters
def generate_board():
dice = [
"RIFOBX",
"IFEHEY",
"DENOWS",
"UTOKND",
"HMSRAO",
"LUPETS",
"ACITOA",
"YLGKUE",
"QBMJOA",
"EHISPN",
"VETIGN",
"BALIYT",
"EZAVND",
"RALESC",
"UWILRG",
"PACEMD",
]
letters = [ random.choice(die) for die in dice ]
random.shuffle(letters)
return letters
WIDE_MAP = dict((i, i + 0xFEE0) for i in xrange(0x21, 0x7F))
WIDE_MAP[0x20] = 0x3000
def widen(s):
"""
Convert all ASCII characters to the full-width counterpart.
>>> print widen('test, Foo!')
test, Foo!
>>>
"""
return unicode(s).translate(WIDE_MAP).encode('utf8')
def board_string(letters):
#horiz = widen("+---------+")
horiz = widen("+") + " "
for i in range(7):
horiz += widen("-") + " "
horiz += widen("+")
# construct row divider
divider = widen("|") + " "
for i in range(7):
divider += widen("-") + " "
divider += widen("|")
board = ""
board += horiz
board += "\n"
for i in range(4):
board += widen("|") + " "
for j in range(4):
letter = letters.pop()
if letter == "Q":
board += "Qu" + widen("|") + " "
else:
#board += widen(letter)+" | "
board += widen(letter) + " " + widen("|") + " "
board += "\n"
if not i == 3:
#board += widen("| - - - - |")
board += divider
board += "\n"
board += horiz
return normalize('NFC',unicode(board, 'utf-8'))
def main():
letters = generate_board()
boggle_board = board_string(letters)
print "Tweeting this board"
api = login()
tweet(api, boggle_board)
print letters