You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mlab_mysql_import.py
+31-16Lines changed: 31 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@
9
9
# 20120628 AX removed testing for every line, added timing code,
10
10
# 20120629 AX added loop over all arguments, exception handling, restructured code, moved processed files to archive or error folder
11
11
# 20120708 AX skip empty ip lines instead or error message
12
+
# 20120708 RB cleaning some names and spelling, also we don't want processed_files.log to clobber the downloaders processed_files.log. So we should use overly descriptive names
12
13
#
13
14
# test:
14
15
# cd /DATA
@@ -20,6 +21,15 @@
20
21
# v move error files naar error directory
21
22
# v log process and errors
22
23
# v skip empty ip lines instead or error message
24
+
#
25
+
# Get the date from the filename, and look up the correct maxmind database
26
+
# then, insert the locId directly with the line in the mlab/{glasnost,ndt} database, preventing slow future updates
27
+
# on the other hand, all these updates might be extremely slow: TEST
28
+
#
29
+
# todo : refactor all the utility functions in a separate file
30
+
# todo : refactor all the passwords in a separate file (which is NOT in the repo, AND is in the .gitignore list
31
+
32
+
23
33
24
34
importsys
25
35
importre
@@ -39,7 +49,7 @@
39
49
# PLEASE UPDATE THESE SETTINGS
40
50
db_host="localhost"# your host, usually localhost
41
51
db_user="root"# your username
42
-
db_passwd="rootpassword"# your password
52
+
db_passwd=""# your password
43
53
db_name="mlab"# name of the database
44
54
db_tables= {"glasnost": "glasnost", "ndt": "ndt"} # a mapping from testname to tablename
''' Test if the entry already exists in the database '''
114
125
# Check if the entry exists already
115
126
sql="SELECT COUNT(*) FROM "+db_table+" WHERE date = '"+test_datetime.isoformat() +"' AND destination = '"+destination+"' AND source = '"+source_ip+"' AND file_id = "+str(file_id)
''' Insert a test connection to the database, if it not already exists '''
132
143
# Check if the entry exists already
133
144
sql="SELECT COUNT(*) FROM "+db_table+" WHERE date = '"+test_datetime.isoformat() +"' AND destination = '"+destination+"' AND source = '"+source_ip+"' AND file_id = "+str(file_id)
134
145
cur.execute(sql)
135
146
136
-
# If not, then isert it
147
+
# If not, then insert it
137
148
ifcur.fetchone()[0] <1:
138
149
print'Found new test performed on the', test_datetime, 'from '+destination+' -> '+source_ip+'.'
0 commit comments