mirror of https://github.com/dirtbags/tanks.git
Change tput url, read password from env
This commit is contained in:
parent
50752d3c8f
commit
97f29f389a
14
contrib/tput
14
contrib/tput
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
""" Here's an example tank, in RFC822ish format:
|
""" Here's an example tank, in RFC822ish format:
|
||||||
|
|
||||||
From: Joe Cool <joe@cool.cc>
|
From: Joe Cool <joe@cool.cc>
|
||||||
Password: swordfish
|
|
||||||
Tank-Name: Red Baron
|
Tank-Name: Red Baron
|
||||||
Color: #c7e148
|
Color: #c7e148
|
||||||
Sensor-0: 50 0 7 1
|
Sensor-0: 50 0 7 1
|
||||||
|
@ -18,6 +18,7 @@ import argparse
|
||||||
import sys
|
import sys
|
||||||
import email
|
import email
|
||||||
import requests
|
import requests
|
||||||
|
import os
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description="Upload forf tanks.",
|
parser = argparse.ArgumentParser(description="Upload forf tanks.",
|
||||||
|
@ -27,7 +28,7 @@ def parse_args():
|
||||||
type=argparse.FileType('r'), default=sys.stdin)
|
type=argparse.FileType('r'), default=sys.stdin)
|
||||||
parser.add_argument('--url', '-u', nargs='?', metavar='URL',
|
parser.add_argument('--url', '-u', nargs='?', metavar='URL',
|
||||||
help="URL to submit your tank to",
|
help="URL to submit your tank to",
|
||||||
default='http://woozle.org/tanks/designer.cgi')
|
default='http://woozle.org/tanks/upload.cgi')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
def read_tank(infile):
|
def read_tank(infile):
|
||||||
|
@ -35,13 +36,16 @@ def read_tank(infile):
|
||||||
headers = dict(msg.items())
|
headers = dict(msg.items())
|
||||||
return headers, msg.get_payload()
|
return headers, msg.get_payload()
|
||||||
|
|
||||||
def post_tank(headers, code, url='http://woozle.org/tanks/designer.cgi'):
|
def post_tank(headers, code, url):
|
||||||
|
token = os.environ.get('token')
|
||||||
|
if not token:
|
||||||
|
raise RuntimeError("Must provide token in 'token' environment variable")
|
||||||
request = {}
|
request = {}
|
||||||
request['token'] = headers.get('Password', '')
|
request['token'] = token
|
||||||
request['name'] = headers.get('Tank-Name', '')
|
request['name'] = headers.get('Tank-Name', '')
|
||||||
request['author'] = headers.get('From', '')
|
request['author'] = headers.get('From', '')
|
||||||
request['color'] = headers.get('Color', '#c0c0c0')
|
request['color'] = headers.get('Color', '#c0c0c0')
|
||||||
for sn in xrange(0, 10):
|
for sn in range(0, 10):
|
||||||
sensor = 'Sensor-{}'.format(sn)
|
sensor = 'Sensor-{}'.format(sn)
|
||||||
if sensor in headers:
|
if sensor in headers:
|
||||||
sr, sa, sw, st = headers[sensor].split()
|
sr, sa, sw, st = headers[sensor].split()
|
||||||
|
|
Loading…
Reference in New Issue