|
@@ -0,0 +1,35 @@
|
|
|
|
+# -*- encoding: utf-8 -*-
|
|
|
|
+import pymysql
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def main():
|
|
|
|
+ con = pymysql.connect(host='172.29.110.52',
|
|
|
|
+ user='wanzb',
|
|
|
|
+ password='wanzb890*()',
|
|
|
|
+ database='wanzb')
|
|
|
|
+ with con:
|
|
|
|
+ # remove duplicate stocks
|
|
|
|
+ with con.cursor() as cur:
|
|
|
|
+ n_rows = cur.execute('delete from stock where name in (select name from (select name,count(name) as c from stock group by name having c>1) as t0) and code is NULL order by name')
|
|
|
|
+ print('{} stocks removed'.format(n_rows))
|
|
|
|
+ con.commit()
|
|
|
|
+
|
|
|
|
+ # remove duplicate player's records
|
|
|
|
+ with con.cursor() as cur:
|
|
|
|
+ # find target table
|
|
|
|
+ n_rows = cur.execute('show tables like "player_record_%"')
|
|
|
|
+ tables = [i[0] for i in cur.fetchall()]
|
|
|
|
+ tables.sort(key=lambda x: int(x[14:]))
|
|
|
|
+ target_table = tables[-1]
|
|
|
|
+
|
|
|
|
+ # remove duplicate entries in `player_record` util not fund
|
|
|
|
+ n_rows = -1
|
|
|
|
+ while n_rows != 0:
|
|
|
|
+ n_rows = cur.execute('delete from {} where id in (select mid from (select max(id) mid,user_id,stock_date,count(user_id) c from {} group by user_id,stock_date having c > 1) t0)'.format(target_table, target_table))
|
|
|
|
+ print('{} player_records removed'.format(n_rows))
|
|
|
|
+ con.commit()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
+ main()
|
|
|
|
+
|