Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit aa0924c

Browse files
committed
Add scriptupload. Apparently all my code got rewrote?
1 parent 52a5c61 commit aa0924c

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pynetworktables==2018.0.0
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#nt setup
2+
from networktables import NetworkTables
3+
import __future__
4+
NetworkTables.initialize(server='10.1.99.2')
5+
prefs = NetworkTables.getTable("Preferences")
6+
7+
go = False #true when file has been successfully read
8+
lines = [] #an array of strings which represent each line of the file
9+
filename = raw_input("File name: ") #the name of the file to read (user input)
10+
oneline = "" #the file as a single string
11+
retry = False #whether or not to retry.
12+
13+
if not NetworkTables.isConnected():
14+
print("You aren't connected to the bot.")
15+
quit()
16+
#loops until a file is read into the file array
17+
while not go:
18+
if retry:
19+
filename = raw_input("Not found. Try another name (enter to quit): ")#retry, or quit (in case the file doesn't exist)
20+
if filename == "":
21+
quit()
22+
try:
23+
with open(filename) as script:
24+
lines = script.readlines()
25+
oneline = "".join(lines) #this is python's weird syntax for joining an array into one line, as we can't seem to pull string arrays from the WPILib Preferences class.
26+
break
27+
except:
28+
retry = True
29+
#puts the string
30+
prefs.putString("autoscripts", oneline)
31+
print("Uploading %s as a String[] to key \"autoscripts\"" % filename)
32+
33+
#checks if the key has been filled
34+
tester = "" #a variable to check if autoscripts is None
35+
36+
tester = prefs.getValue("autoscripts", None)
37+
if tester != oneline:
38+
print("It doesn't look like key \"autoscripts\" is filled, maybe you aren't connected to networktables?")
39+
else:
40+
print("Success!")

0 commit comments

Comments
 (0)