-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_filler.py
76 lines (63 loc) · 1.91 KB
/
form_filler.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
from mechanize import Browser
import pickler
def string_or_bool( string, control):
pos = ['true', 'True', 'y', 'yes', 'on']
neg = ['false', 'False', 'n', 'no']
string=str(string[0])
if (control.type == 'checkbox'):
result = ['on'] if string in pos else []
return result
elif control.type == 'text':
return string
elif control.type == 'radio':
return [string]
elif control.type == 'select':
return [string]
elif (string in pos) or (string in neg):
return string in pos
else:
return string
def fill_form( br, argv ):
#Remove first irrelevant arg
argv.pop(0)
argc = len( argv )
#Load flag map
flags = pickler.load( 'flags')
#Selects the form we want
br.form = list(br.forms())[0]
# Set dynimg so we just get an image instd of a map
control = br.form.find_control("dynimg")
control.items[0].selected=True
for index, arg in enumerate( argv ):
if arg in flags:
name = flags[ arg ][0]
control = br.form.find_control( name )
else:
#print("setting",control.name,"type",control.type)
control.value = string_or_bool([argv[index]], control)
# for control in br.form.controls:
# print("name=%s, type=%s, value=%s" % (control.name, control.type, control.value))
# Set color scheme
# control = br.form.find_control("scheme")
# control.value=["3"]
# Disable star names
# br.form.find_control("starn").items[0].selected=False
# Disable boundaries
# br.form.find_control("constb").items[0].selected=False
# Disable names
# br.form.find_control("constn").items[0].selected=False
# Disable coords
# br.form.find_control("coords").items[0].selected=False
#
# Set lat and lon values
# lat = '0'
# lon = '0'
# if argc > 1:
# lon = argv[1]
# if argc > 2:
# lat = argv[2]
# control = br.form.find_control("lat")
# control.value = lat
#
# control = br.form.find_control("lon")
# control.value = lon