-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.py
executable file
·56 lines (51 loc) · 2.05 KB
/
cli.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
#!/usr/bin/env python
import logging
from optparse import OptionParser
from util import MyOption
from farmvillebot import FarmVilleBot
def parse_options():
parser = OptionParser(option_class=MyOption)
parser.set_defaults(zoom=4, delay=0.5, step=1,
action=FarmVilleBot.click,
log_level=logging.WARN)
parser.add_option('-z', '--zoom',
type='int', dest='zoom',
help="zoom level: 1 - 4")
parser.add_option('--delay',
type='float', dest='delay',
help="delay between mouse actions")
parser.add_option('--step',
type='fraction', dest='step',
help="size of the step; can be integer or a fraction, e.g. 1/4")
parser.add_option('--click',
action='store_const', const=FarmVilleBot.click, dest='action',
help="click")
parser.add_option('--collect',
action='store_const', const=FarmVilleBot.collect, dest='action',
help="collect or harvest (3rd menu action)")
parser.add_option('-v', '--verbose',
action='store_const', const=logging.INFO, dest='log_level',
help="set logging level to INFO")
parser.add_option('--debug',
action='store_const', const=logging.DEBUG, dest='log_level',
help="set logging level to DEBUG")
return parser.parse_args()
def sweep_area(bot, nrows, ncols, action):
for i in range(nrows):
for j in range(ncols - 1):
action(bot)
if i % 2:
bot.down()
else:
bot.up()
action(bot)
bot.right()
bot.left()
def main():
options, args = parse_options()
nrows, ncols = (int(x) for x in args)
logging.basicConfig(level=options.log_level)
bot = FarmVilleBot(options.zoom, options.delay, options.step)
sweep_area(bot, nrows, ncols, options.action)
if __name__ == '__main__':
main()