summaryrefslogtreecommitdiffstats
path: root/import
diff options
context:
space:
mode:
authorLukas Metzger2020-07-24 17:20:01 +0200
committerLukas Metzger2020-07-24 17:20:01 +0200
commit64e7452fffe15248633b8b719b91a7fea9231c64 (patch)
tree7580fcd6b9444d488896a258d4b6d110b03b7736 /import
parentUse range from chart for total aggregation (diff)
downloadbwlp-statistics-64e7452fffe15248633b8b719b91a7fea9231c64.tar.gz
bwlp-statistics-64e7452fffe15248633b8b719b91a7fea9231c64.tar.xz
bwlp-statistics-64e7452fffe15248633b8b719b91a7fea9231c64.zip
Ignore testservers on import
Diffstat (limited to 'import')
-rw-r--r--import/import.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/import/import.py b/import/import.py
index 68324c5..24a871c 100644
--- a/import/import.py
+++ b/import/import.py
@@ -12,22 +12,34 @@ import datetime
def default(x, default):
return default if x is None else x
-with open(sys.argv[1], 'r') as f:
- data = json.load(f)
-
c = configparser.ConfigParser()
c.read('config.ini')
filename = os.path.basename(sys.argv[1])
-date = re.search('^[0-9]{4}-[0-9]{2}-[0-9]{2}', filename).group(0)
-date = datetime.datetime.fromtimestamp(int(data['days7']['tsTo'])).date()
-
ip = re.search('_([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})[_\.]', filename).group(1)
db = pymysql.connect(c.get('db', 'host'), c.get('db', 'username'), c.get('db', 'password'), c.get('db', 'name'), cursorclass=pymysql.cursors.DictCursor)
cursor = db.cursor()
+# Check if ip is already in names table
+cursor.execute('SELECT testserver FROM names WHERE ip = %s', (ip))
+entry = cursor.fetchall()
+if len(entry) > 0: # Already in table
+ if entry[0]['testserver'] == 1:
+ print('This is a Testserver. Ignoring!')
+ db.close()
+ exit(0)
+else: # Add to database
+ cursor.execute('INSERT INTO names(ip, name, testserver) VALUES (%s, %s, 0)', (ip, ip))
+
+# Load data and timestamps
+with open(sys.argv[1], 'r') as f:
+ data = json.load(f)
+
+date = re.search('^[0-9]{4}-[0-9]{2}-[0-9]{2}', filename).group(0)
+date = datetime.datetime.fromtimestamp(int(data['days7']['tsTo'])).date()
+
# Add report to database
try:
cursor.execute('INSERT INTO reports(date,ip,version) VALUES(%s, %s, %s)',(
@@ -37,7 +49,8 @@ try:
))
except pymysql.err.IntegrityError:
print('Report is already in database!')
- exit(1)
+ db.close()
+ exit(0)
cursor.execute('SELECT LAST_INSERT_ID() as id')
reportId = cursor.fetchone()['id']