-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#! /usr/bin/env python | ||
|
||
import sys | ||
import re | ||
|
||
|
||
argStr = ' '.join(sys.argv[1:]) | ||
m = re.match(r'^(.*)/(.*)(?:\:([\d]+))', argStr) | ||
sys, stn, dist = m.group(1, 2, 3) | ||
sys = sys.title() | ||
stn = stn.title() | ||
dist = int(dist) | ||
|
||
import sqlite3 | ||
conn = sqlite3.connect("data/TradeDangerous.db") | ||
cur = conn.cursor() | ||
|
||
system_id = cur.execute(""" | ||
SELECT system_id | ||
FROM System | ||
WHERE name like ? | ||
""", [sys]).fetchone()[0] | ||
|
||
matches = cur.execute(""" | ||
SELECT COUNT(*) | ||
FROM Station | ||
WHERE system_id = ? | ||
AND name like ? | ||
""", [system_id, stn]).fetchone()[0] | ||
if matches > 0: | ||
raise Exception("Station already exists.") | ||
|
||
cur.execute(""" | ||
INSERT INTO Station | ||
(system_id, name, ls_from_star) | ||
VALUES (?, ?, ?) | ||
""", [system_id, stn, dist]) | ||
conn.commit() | ||
|
||
print("ADDED: {}/{}:{}ls".format(sys, stn, dist)) | ||
print("You'll need to regenerate your Station.csv or lose your data.") | ||
print(" trade.py export --table Station") | ||
|