-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-one.py
134 lines (110 loc) · 4.1 KB
/
check-one.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import ScriptingBridge
import gdata.spreadsheet.service
import time
import shutil
date = 'June 14, 2013'
feed_str = 'tVc9gCzhh-seVwvaojke4Iw'
EShiftDown = 1265854068
ECommandDown = 1264807268
EOptionDown = 1265594484
EControlDown = 1264809068
ELeftArrowKey = 1802730240
ERightArrowKey = 1802730496
pages = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_("com.apple.iwork.pages")
pages.activate()
document = pages.open_('/Users/isaac/Documents/check-one.pages')
time.sleep(1)
event = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_("com.apple.systemevents")
def align_right():
event.keystroke_using_('}', ECommandDown)
def align_left():
event.keystroke_using_('{', ECommandDown)
def type_out( arg ):
event.keystroke_using_( arg, 0 )
newline( 1 )
def select_line():
event.keystroke_using_( ELeftArrowKey, ECommandDown | EShiftDown )
def newline( arg ):
for i in range(arg):
event.keystroke_using_( "\r", 0 )
def main():
client = gdata.spreadsheet.service.SpreadsheetsService()
client.email = '[email protected]'
client.password = '3355dartoO'
client.source = '22K'
client.ProgrammaticLogin()
feed = client.GetWorksheetsFeed( feed_str )
for entry in feed.entry:
worksheet_id = entry.id.text.rsplit('/',1)[1]
print worksheet_id + ': ' + entry.title.text
if entry.title.text == 'Payout':
break
rows = client.GetListFeed( feed_str, worksheet_id ).entry
for row in rows:
if not row.custom['check'].text: continue
players = int(row.custom['players'].text)
division_string = row.custom['division'].text or ''
print division_string
divisions = division_string.split()
if len(divisions) == 0:
divisions = ['']
for division in divisions:
for rank in ['1st', '2nd', '3rd', '4th', '5th-6th', '5th-6th', '7th-8th', '7th-8th']:
payout = row.custom[ 'rank' + rank ].text
payout_int = int(payout) / int( row.custom['players'].text )
payout_str = numToWords( payout_int )
memo = row.custom['event'].text + ' ' + division + ' on ' + row.custom['day'].text + ' - ' + rank
for p in range(players):
pages.activate()
newline( 3 )
align_right()
type_out( date )
newline( 1 )
type_out( '***** ' + str(payout_int) + '.00' )
newline( 1 )
align_left()
type_out( '***** ' + payout_str.title() + ' *****' )
newline( 4 )
type_out( memo )
newline( 5 )
time.sleep(0.5)
units = ["", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine "]
teens = ["", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
tens = ["", "ten", "twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety"]
thousands = ["","thousand"]
def numToWords(num):
words = []
if num == 0:
words.append("zero")
else:
numStr = "%d" % num
numStrLen = len(numStr)
groups = (numStrLen + 2) / 3
numStr = numStr.zfill(groups * 3)
for i in range(0, groups*3, 3):
h = int(numStr[i])
t = int(numStr[i+1])
u = int(numStr[i+2])
g = groups - (i / 3 + 1)
if h >= 1:
words.append(units[h])
words.append("hundred")
if t > 1:
words.append(tens[t])
if u >= 1:
words.append(units[u])
elif t == 1:
if u >= 1:
words.append(teens[u])
else:
words.append(tens[t])
else:
if u >= 1:
words.append(units[u])
if g >= 1 and (h + t + u) > 0:
words.append(thousands[g])
return ' '.join( words )
main()