SHARE
    TWEET
    Krenair

    Convert ZT DB to SP

    Sep 24th, 2013
    240
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    Python 1.73 KB | None | 0 0
    1. import getpass, MySQLdb, re
    2. conn = MySQLdb.connect(host = raw_input("Hostname: "), port = int(raw_input("Port number: ")), user = raw_input("Username: "), passwd = getpass.getpass(), db = raw_input("DB name: "))
    3. db = conn.cursor()
    4. db.execute("SELECT * FROM zerotolerance")
    5. rowsToInsert = []
    6. steamIdRegex = re.compile("^STEAM_[0-7]:[01]:\\d+$")
    7. for row in db.fetchall():
    8. id, type, punished_id, punished_name, punisher_id, punisher_name, remover_id, remover_name, start_time, end_time, removal_time, reason, removal_reason = row
    9. if type == 'Unknown':
    10. continue
    11. if end_time == 0 or end_time == start_time:
    12. length = 0
    13. else:
    14. length = end_time - start_time
    15. if punisher_id == 'Server':
    16. punisher_id = 'Console'
    17. rowsToInsert.append((type.lower(), punished_name, punished_id, "", punisher_name, punisher_id, remover_id, remover_name, start_time, length, removal_time, reason, removal_reason, -1))
    18. insertQuery = "INSERT INTO sourcepunish_punishments (Punish_Type, Punish_Player_Name, Punish_Player_ID, Punish_Player_IP, Punish_Admin_Name, Punish_Admin_ID, UnPunish_Admin_ID, UnPunish_Admin_Name, Punish_Time, Punish_Length, UnPunish_Time, Punish_Reason, UnPunish_Reason, Punish_Server_ID) VALUES "
    19. for row in rowsToInsert:
    20. insertQuery += '('
    21. for i in range(0, len(row)):
    22. element = row[i]
    23. if isinstance(element, str):
    24. insertQuery += '\'' + conn.escape_string(element) + '\''
    25. elif isinstance(element, int) or isinstance(element, long):
    26. insertQuery += str(element)
    27. if i + 1 != len(row):
    28. insertQuery += ', '
    29. insertQuery += '),\n'
    30. insertQuery = insertQuery[:-2] + ';'
    31. print insertQuery
    32. if raw_input("Are you sure? [y/N] ") == 'y':
    33. db.execute(insertQuery)
    34. print 'Done!'
    35. else:
    36. print 'Okay, exiting.'
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /